   q nA  : B     cmd q s	A   yZ<	     cmd/acct  q q	   Z   cmd/acct/acct.mk  #	@(#)acct.mk	1.9 of 9/23/83 #
ROOT =
PFX=
TESTDIR = .
FRC =
INS = /etc/install
ARGS =
INSDIR = $(ROOT)/usr/lib/acct
CC = $(PFX)cc
CFLAGS = -O
LFLAGS = -s
LIB = lib/a.a

all:	library acctcms acctcom acctcon1\
	acctcon2 acctdisk acctdusg acctmerg accton\
	acctprc1 acctprc2 acctwtmp\
	diskusg fwtmp wtmpfix\
	chargefee ckpacct dodisk lastlogin\
	monacct nulladm prctmp prdaily\
	prtacct remove runacct\
	shutacct startup turnacct holtable \
	awkecms awkelus

library:
		cd lib; $(MAKE) "INS=$(INS)" "CC=$(CC)" "CFLAGS=$(CFLAGS)" \
			"PFX=$(PFX)" "ROOT=$(ROOT)"

acctcms:	library acctcms.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctcms.c $(LIB) -o $(TESTDIR)/acctcms
		$(INS) -f $(INSDIR) $(TESTDIR)/acctcms

acctcom:	library acctcom.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctcom.c $(LIB) -o $(TESTDIR)/acctcom
		$(INS) $(TESTDIR)/acctcom $(ROOT)/bin

acctcon1:	library acctcon1.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctcon1.c $(LIB) -o $(TESTDIR)/acctcon1
		$(INS) -f $(INSDIR) $(TESTDIR)/acctcon1

acctcon2:	acctcon2.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctcon2.c -o $(TESTDIR)/acctcon2
		$(INS) -f $(INSDIR) $(TESTDIR)/acctcon2

acctdisk:	acctdisk.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctdisk.c -o $(TESTDIR)/acctdisk
		$(INS) -f $(INSDIR) $(TESTDIR)/acctdisk

acctdusg:	acctdusg.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctdusg.c -o $(TESTDIR)/acctdusg
		$(INS) -f $(INSDIR) $(TESTDIR)/acctdusg

acctmerg:	library acctmerg.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctmerg.c $(LIB) -o $(TESTDIR)/acctmerg
		$(INS) -f $(INSDIR) $(TESTDIR)/acctmerg

accton:		accton.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			accton.c -o $(TESTDIR)/accton
		$(INS) -f $(INSDIR) -u root -g adm -m 4755 $(TESTDIR)/accton

acctprc1:	library acctprc1.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctprc1.c $(LIB) -o $(TESTDIR)/acctprc1
		$(INS) -f $(INSDIR) $(TESTDIR)/acctprc1

acctprc2:	acctprc2.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctprc2.c -o $(TESTDIR)/acctprc2
		$(INS) -f $(INSDIR) $(TESTDIR)/acctprc2

acctwtmp:	acctwtmp.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			acctwtmp.c -o $(TESTDIR)/acctwtmp
		$(INS) -f $(INSDIR) $(TESTDIR)/acctwtmp

diskusg:	diskusg.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			diskusg.c -o $(TESTDIR)/diskusg
		$(INS) -f $(INSDIR) $(TESTDIR)/diskusg

fwtmp:		fwtmp.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			fwtmp.c -o $(TESTDIR)/fwtmp
		$(INS) -f $(INSDIR) $(TESTDIR)/fwtmp

wtmpfix:	wtmpfix.c $(FRC)
		$(CC) $(CFLAGS) $(LFLAGS) $(FFLAG) \
			wtmpfix.c -o $(TESTDIR)/wtmpfix
		$(INS) -f $(INSDIR) $(TESTDIR)/wtmpfix

chargefee:	chargefee.sh $(FRC)
		cp chargefee.sh $(TESTDIR)/chargefee
		$(INS) -f $(INSDIR) $(TESTDIR)/chargefee

ckpacct:	ckpacct.sh $(FRC)
		cp ckpacct.sh $(TESTDIR)/ckpacct
		$(INS) -f $(INSDIR) $(TESTDIR)/ckpacct

dodisk:		dodisk.sh $(FRC)
		cp dodisk.sh $(TESTDIR)/dodisk
		$(INS) -f $(INSDIR) $(TESTDIR)/dodisk

monacct:	monacct.sh $(FRC)
		cp monacct.sh $(TESTDIR)/monacct
		$(INS) -f $(INSDIR) $(TESTDIR)/monacct

lastlogin:	lastlogin.sh $(FRC)
		cp lastlogin.sh $(TESTDIR)/lastlogin
		$(INS) -f $(INSDIR) $(TESTDIR)/lastlogin

nulladm:	nulladm.sh $(FRC)
		cp nulladm.sh $(TESTDIR)/nulladm
		$(INS) -f $(INSDIR) $(TESTDIR)/nulladm

prctmp:		prctmp.sh $(FRC)
		cp prctmp.sh $(TESTDIR)/prctmp
		$(INS) -f $(INSDIR) $(TESTDIR)/prctmp

prdaily:	prdaily.sh $(FRC)
		cp prdaily.sh $(TESTDIR)/prdaily
		$(INS) -f $(INSDIR) $(TESTDIR)/prdaily

prtacct:	prtacct.sh $(FRC)
		cp prtacct.sh $(TESTDIR)/prtacct
		$(INS) -f $(INSDIR) $(TESTDIR)/prtacct

remove:		remove.sh $(FRC)
		cp remove.sh $(TESTDIR)/remove
		$(INS) -f $(INSDIR) $(TESTDIR)/remove

runacct:	runacct.sh $(FRC)
		cp runacct.sh $(TESTDIR)/runacct
		$(INS) -f $(INSDIR) $(TESTDIR)/runacct

shutacct:	shutacct.sh $(FRC)
		cp shutacct.sh $(TESTDIR)/shutacct
		$(INS) -f $(INSDIR) $(TESTDIR)/shutacct

startup:	startup.sh $(FRC)
		cp startup.sh $(TESTDIR)/startup
		$(INS) -f $(INSDIR) $(TESTDIR)/startup

turnacct:	turnacct.sh $(FRC)
		cp turnacct.sh $(TESTDIR)/turnacct
		$(INS) -f $(INSDIR) $(TESTDIR)/turnacct

holtable:	holidays $(FRC)
		$(INS) -f $(INSDIR) $(TESTDIR)/holidays

awkecms:	ptecms.awk $(FRC)
		$(INS) -f $(INSDIR) $(TESTDIR)/ptecms.awk

awkelus:	ptelus.awk $(FRC)
		$(INS) -f $(INSDIR) $(TESTDIR)/ptelus.awk

install:
		$(MAKE) -f acct.mk $(ARGS) FFLAG=$(FFLAG) \
			"PFX=$(PFX)" "ROOT=$(ROOT)" "INS=$(INS)"

clean:
		-rm -f *.o
		cd lib; $(MAKE) clean

clobber:	clean
		-rm -f acctcms acctcom acctcon1 acctcon2 acctdisk diskusg\
			acctdusg acctmerg accton acctprc1 acctprc2 acctwtmp\
			fwtmp wtmpfix
		-rm -f chargefee ckpacct dodisk lastlogin nulladm\
			monacct prctmp prdaily prtacct remove runacct\
			shutacct startup turnacct
		cd lib; $(MAKE) clobber

FRC:
cq "   ZG   ?cmd/acct/acctcms.c  /*	@(#)acctcms.c	1.6 of 7/22/83	*/
/*
 *	acctcms [-a] [-c] [-j] [-n] [-s] [-p] [-o] [-t] [file...]
 *	summarize per-process accounting
 *	-a	out      put in ascii, rather than [pt]cms.h format
 *	-c	sort by total cpu, rather than total kcore-minutes
 *	-j	anything used only once -> ***other
 *	-n	sort by number of processes
 *	-s	any following files already in pcms.h format
 *      -p      output prime time command summary (only with -a)
 *      -o      output non-prime time (offshift) command summary (only
 *		with -a option)
 *	-t	process records in total (old) style (tcms.h) format
 *	file	file in [pt]cms.h (if -s seen already) or acct.h (if not)
 *	expected use:
 *	acctcms /usr/adm/pacct? > today; acctcms -s old today >new
 *	cp new old; rm new
 *	acctcms -a today; acctcms -a old
 */
#include <sys/types.h>
#include "acctdef.h"
#include <stdio.h>
#include <ctype.h>
#include <sys/acct.h>
#define MYKIND(flag)	((flag & ACCTF) == 0)
#define TOTAL(a)	(a[PRIME] + a[NONPRIME])

#if pdp11
#define CSIZE 500
#else
#define CSIZE 1000
#endif
int	csize;

/*
 *  Total cms records format
 */
struct tcms {
	char	tcm_comm[8];	/* command name */
	long	tcm_pc;		/* number of processes */
	float	tcm_cpu;	/* cpu time(min) */
	float	tcm_real;	/* real time(min) */
	float	tcm_kcore;	/* kcore-minutes */
	long	tcm_io;		/* chars transfered */
	long	tcm_rw;		/* blocks read */
} ;
struct tcms	*tcm;
/*
 * prime/nonprime CMS record format
 */
struct pcms {
	char	pcm_comm[8];	/* command name */
	long	pcm_pc[2];	/* number of processes */
	float	pcm_cpu[2];	/* cpu time(min) */
	float	pcm_real[2];	/* real time(min) */
	float	pcm_kcore[2];	/* kcore-minutes */
	float	pcm_io[2];	/* chars transfered */
	float	pcm_rw[2];	/* blocks read */
} ;
struct pcms	*pcm;
#define PRIME		0
#define NONPRIME	1
struct	acct	ab;
struct	tcms	tcmtmp	= {"***other"};
struct	pcms	pcmtmp	= {"***other"};
int	aflg;
int	cflg;
int	jflg;
int	nflg;
int	sflg;
int	pflg;
int	oflg;
int	tflg;
int	errflg;

int	ccmp(), kcmp(), ncmp();
int	tccmp(), tkcmp(), tncmp();
time_t	expand();

/*  Format specification for ASCII printing */

char	*fmtcmd =	"%-8.8s",
	*fmtcnt =	"%8ld",
	*fmtkcore =	"%12.2f",
	*fmtcpu =	"%10.2f",
	*fmtreal =	"%13.2f",
	*fmtmsz =	"%8.2f",
	*fmtmcpu =	"%8.2f",
	*fmthog =	"%8.2f",
	*fmtcharx =	"%13.0f",
	*fmtblkx =	"%11.0f" ;

main(argc, argv)
char **argv;
{
	int	c;
	extern	int	optind;
	extern	char	*optarg;

	while((c = getopt(argc, argv, "acjnspot")) != EOF)
	switch(c) {
		case 'a':
			aflg++;
			continue;
		case 'c':
			cflg++;
			continue;
		case 'j':
			jflg++;
			continue;
		case 'n':
			nflg++;
			continue;
		case 's':
			sflg++;
			continue;
		case 'p':
			pflg++;
			continue;
		case 'o':
			oflg++;
			continue;
		case 't':
			tflg++;
			continue;
		default:
			errflg++;
			continue;
	}
	if(errflg){
		fprintf(stderr, "Usage: %s [-acjnspot] [file ...]\n", argv[0]);
		exit(1);
	}
	if(tflg) {
		if( (tcm = (struct tcms *)calloc(CSIZE, sizeof(struct tcms))) == NULL) {
			fprintf(stderr, "%s: Cannot allocate memory\n", argv[0]);
			exit(5);
		}
		for(; optind < argc; optind++)
			tdofile(argv[optind]);
		if (jflg)
			tfixjunk();
		tsqueeze();
		qsort(tcm, csize, sizeof(tcm[0]), nflg? tncmp: (cflg? tccmp: tkcmp));
		if (aflg)
			toutpta();
		else
			toutptc();
	} else {
		if( (pcm = (struct pcms *)calloc(CSIZE, sizeof(struct pcms))) == NULL) {
			fprintf(stderr, "%s: Cannot allocate memory\n", argv[0]);
			exit(6);
		}
		for(; optind < argc; optind++)
			dofile(argv[optind]);
		if (jflg)
			fixjunk();
		squeeze();
		qsort(pcm, csize, sizeof(pcm[0]), nflg? ncmp: (cflg? ccmp: kcmp));
		if (aflg)
			outputa();
		else
			outputc();
	}
}

tdofile(fname)
char *fname;
{
	struct tcms cmt;
	struct acct ab;

	if (freopen(fname, "r", stdin) == NULL) {
		fprintf(stderr,  "acctcms: cannot open %s\n", fname);
		return;
	}
	if (sflg)
		while (fread(&cmt, sizeof(cmt), 1, stdin) == 1)
			tenter(&cmt);
	else
		while (fread(&ab, sizeof(ab), 1, stdin) == 1) {
			CPYN(cmt.tcm_comm, ab.ac_comm);
			cmt.tcm_pc = 1;
			cmt.tcm_cpu = MINT(expand(ab.ac_stime)+expand(ab.ac_utime));
			cmt.tcm_real = MINT(expand(ab.ac_etime));
			cmt.tcm_kcore = MINT(KCORE(expand(ab.ac_mem)));
			cmt.tcm_io = expand(ab.ac_io);
			cmt.tcm_rw = expand(ab.ac_rw);
			tenter(&cmt);
		}
}

dofile(fname)
char *fname;
{
	struct acct ab;
	struct pcms pcmt;
	double	ratio;
	long	elaps[2];
	long	etime;
	double	dtmp;
	time_t	ltmp;

	if (freopen(fname, "r", stdin) == NULL) {
		fprintf(stderr,  "acctcms: cannot open %s\n", fname);
		return;
	}
	if (sflg)
		while (fread(&pcmt, sizeof(pcmt), 1, stdin) == 1)
			enter(&pcmt);
	else
		while (fread(&ab, sizeof(ab), 1, stdin) == 1) {
			CPYN(pcmt.pcm_comm, ab.ac_comm);
	/*
	 * Approximate P/NP split as same as elapsed time
 	 */
			if((etime = SECS(expand(ab.ac_etime))) == 0)
				etime = 1;
			pnpsplit(ab.ac_btime, etime, elaps);
			ratio = (double)elaps[PRIME]/(double)etime;
			if(elaps[PRIME] > elaps[NONPRIME]) {
				pcmt.pcm_pc[PRIME] = 1;
				pcmt.pcm_pc[NONPRIME] = 0;
			} else {
				pcmt.pcm_pc[PRIME] = 0;
				pcmt.pcm_pc[NONPRIME] = 1;
			}
			dtmp = MINT(expand(ab.ac_stime)+expand(ab.ac_utime));
			pcmt.pcm_cpu[PRIME] = dtmp * ratio;
			pcmt.pcm_cpu[NONPRIME] = (ratio == 1.0) ? 0.0 : (dtmp - pcmt.pcm_cpu[PRIME]);
			dtmp = MINT(expand(a      b.ac_etime));
			pcmt.pcm_real[PRIME] = dtmp * ratio;
			pcmt.pcm_real[NONPRIME] = (ratio == 1.0) ? 0.0 : (dtmp - pcmt.pcm_real[PRIME]);
			dtmp = MINT(KCORE(expand(ab.ac_mem)));
			pcmt.pcm_kcore[PRIME] = dtmp * ratio;
			pcmt.pcm_kcore[NONPRIME] = (ratio == 1.0) ? 0.0 : (dtmp - pcmt.pcm_kcore[PRIME]);
			ltmp = expand(ab.ac_io);
			pcmt.pcm_io[PRIME] = (double)ltmp * ratio;
			pcmt.pcm_io[NONPRIME] = (ratio == 1.0) ? 0.0 : ((double)ltmp - pcmt.pcm_io[PRIME]);
			ltmp = expand(ab.ac_rw);
			pcmt.pcm_rw[PRIME] = (double)ltmp * ratio;
			pcmt.pcm_rw[NONPRIME] = (ratio == 1.0) ? 0.0 : ((double)ltmp - pcmt.pcm_rw[PRIME]);
			enter(&pcmt);
		}
}

tenter(p)
register struct tcms *p;
{
	register i;
	register j;
	for (i = j = 0; j < sizeof(p->tcm_comm); j++) {
		if (p->tcm_comm[j] && p->tcm_comm[j] <= 037)
			p->tcm_comm[j] = '?';
		i = i*7 + p->tcm_comm[j];	/* hash function */
	}
	if (i < 0)
		i = -i;
	for (i %= CSIZE, j = 0; tcm[i].tcm_comm[0] && j != CSIZE; i = (i+1)%CSIZE, j++)
		if (EQN(p->tcm_comm, tcm[i].tcm_comm))
			break;
	if(j == CSIZE) {
		fprintf(stderr, "acctcms: Hash table overflow. Increase CSIZE\n");
		return(-1);
	}
	if (tcm[i].tcm_comm[0] == 0)
		CPYN(tcm[i].tcm_comm, p->tcm_comm);
	tcmadd(&tcm[i], p);
	return(i);
}
enter(p)
register struct pcms *p;
{
	register i;
	register j;
	for (i = j = 0; j < sizeof(p->pcm_comm); j++) {
		if (p->pcm_comm[j] && p->pcm_comm[j] <= 037)
			p->pcm_comm[j] = '?';
		i = i*7 + p->pcm_comm[j];	/* hash function */
	}
	if (i < 0)
		i = -i;
	for (i %= CSIZE, j = 0; pcm[i].pcm_comm[0] && j != CSIZE; i = (i+1)%CSIZE, j++)
		if (EQN(p->pcm_comm, pcm[i].pcm_comm))
			break;
	if(j == CSIZE) {
		fprintf(stderr, "acctcms: Hash table overflow. Increase CSIZE\n");
		return(-1);
	}
	if (pcm[i].pcm_comm[0] == 0)
		CPYN(pcm[i].pcm_comm, p->pcm_comm);
	pcmadd(&pcm[i], p);
	return(i);
}
tfixjunk()	/* combine commands used only once */
{
	register i, j;
	j = enter(&tcmtmp);
	for (i = 0; i < CSIZE; i++)
		if (i != j && tcm[i].tcm_comm[0] && tcm[i].tcm_pc <= 1) {
			tcmadd(&tcm[j], &tcm[i]);
			tcm[i].tcm_comm[0] = 0;
		}
}
fixjunk()	/* combine commands used only once */
{
	register i, j;
	j = enter(&pcmtmp);
	for (i = 0; i < CSIZE; i++)
		if (i != j && pcm[i].pcm_comm[0] && (pcm[i].pcm_pc[PRIME] + pcm[i].pcm_pc[NONPRIME]) <= 1) {
			pcmadd(&pcm[j], &pcm[i]);
			pcm[i].pcm_comm[0] = 0;
		}
}

tcmadd(p1, p2)
register struct tcms *p1, *p2;
{
	p1->tcm_pc += p2->tcm_pc;
	p1->tcm_cpu = p1->tcm_cpu + p2->tcm_cpu;
	p1->tcm_real = p1->tcm_real + p2->tcm_real;
	p1->tcm_kcore = p1->tcm_kcore + p2->tcm_kcore;
	p1->tcm_io += p2->tcm_io;
	p1->tcm_rw += p2->tcm_rw;
}
pcmadd(p1, p2)
register struct pcms *p1, *p2;
{
	p1->pcm_pc[PRIME] += p2->pcm_pc[PRIME];
	p1->pcm_pc[NONPRIME] += p2->pcm_pc[NONPRIME];
	p1->pcm_cpu[PRIME] += p2->pcm_cpu[PRIME];
	p1->pcm_cpu[NONPRIME] += p2->pcm_cpu[NONPRIME];
	p1->pcm_real[PRIME] += p2->pcm_real[PRIME];
	p1->pcm_real[NONPRIME] += p2->pcm_real[NONPRIME];
	p1->pcm_kcore[PRIME] += p2->pcm_kcore[PRIME];
	p1->pcm_kcore[NONPRIME] += p2->pcm_kcore[NONPRIME];
	p1->pcm_io[PRIME] += p2->pcm_io[PRIME];
	p1->pcm_io[NONPRIME] += p2->pcm_io[NONPRIME];
	p1->pcm_rw[PRIME] += p2->pcm_rw[PRIME];
	p1->pcm_rw[NONPRIME] += p2->pcm_rw[NONPRIME];
}

tsqueeze()	/* get rid of holes in hash table */
{
	register i, k;

	for (i = k = 0; i < CSIZE; i++)
		if (tcm[i].tcm_comm[0]) {
			CPYN(tcm[k].tcm_comm, tcm[i].tcm_comm);
			tcm[k].tcm_pc = tcm[i].tcm_pc;
			tcm[k].tcm_cpu = tcm[i].tcm_cpu;
			tcm[k].tcm_real = tcm[i].tcm_real;
			tcm[k].tcm_kcore = tcm[i].tcm_kcore;
			tcm[k].tcm_io = tcm[i].tcm_io;
			tcm[k].tcm_rw = tcm[i].tcm_rw;
			k++;
		}
	csize = k;
}
squeeze()	/* get rid of holes in hash table */
{
	register i, k;

	for (i = k = 0; i < CSIZE; i++)
		if (pcm[i].pcm_comm[0]) {
			CPYN(pcm[k].pcm_comm, pcm[i].pcm_comm);
			pcm[k].pcm_pc[PRIME] = pcm[i].pcm_pc[PRIME];
			pcm[k].pcm_pc[NONPRIME] = pcm[i].pcm_pc[NONPRIME];
			pcm[k].pcm_cpu[PRIME] = pcm[i].pcm_cpu[PRIME];
			pcm[k].pcm_cpu[NONPRIME] = pcm[i].pcm_cpu[NONPRIME];
			pcm[k].pcm_real[PRIME] = pcm[i].pcm_real[PRIME];
			pcm[k].pcm_real[NONPRIME] = pcm[i].pcm_real[NONPRIME];
			pcm[k].pcm_kcore[PRIME] = pcm[i].pcm_kcore[PRIME];
			pcm[k].pcm_kcore[NONPRIME] = pcm[i].pcm_kcore[NONPRIME];
			pcm[k].pcm_io[PRIME] = pcm[i].pcm_io[PRIME];
			pcm[k].pcm_io[NONPRIME] = pcm[i].pcm_io[NONPRIME];
			pcm[k].pcm_rw[PRIME] = pcm[i].pcm_rw[PRIME];
			pcm[k].pcm_rw[NONPRIME] = pcm[i].pcm_rw[NONPRIME];
			k++;
		}
	csize = k;
}

tccmp(p1, p2)
register struct tcms *p1, *p2;
{
	if (p1->tcm_cpu == p2->tcm_cpu)
		return(0);
	return ((p2->tcm_cpu > p1->tcm_cpu)? 1 : -1);
}

ccmp(p1, p2)
register struct pcms *p1, *p2;
{
	register int	index;

	if( (pflg && oflg) || (!pflg && !oflg) ) {
		if (p1->pcm_cpu[PRIME] + p1->pcm_cpu[NONPRIME] == p2->pcm_cpu[PRIME] + p2->pcm_cpu[NONPRIME])
			return(0);
		return ((p2->pcm_cpu[PRIME] + p2->pcm_cpu[NONPRIME] > p1->pcm_cpu[PRIME] + p1->pcm_cpu[NONPRIME])? 1 : -1);
	}
	index = pflg ? PRIME : NONPRIME;
	if (p1->pcm_cpu[index] == p2->pcm_cpu[index])
		return(0);
	return ((p2->pcm_cpu[index] > p1->pcm_cpu[index])? 1 : -1);
}

tkcmp(p1, p2)
      register struct tcms *p1, *p2;
{
	if (p1->tcm_kcore == p2->tcm_kcore)
		return(0);
	return ((p2->tcm_kcore > p1->tcm_kcore)? 1 : -1);
}

kcmp(p1, p2)
register struct pcms *p1, *p2;
{
	register int	index;

	if( (pflg && oflg) || (!pflg && !pflg) ){
		if (p1->pcm_kcore[PRIME] + p1->pcm_kcore[NONPRIME] == p2->pcm_kcore[PRIME] + p2->pcm_kcore[NONPRIME])
			return(0);
		return ((p2->pcm_kcore[PRIME] + p2->pcm_kcore[NONPRIME] > p1->pcm_kcore[PRIME] + p1->pcm_kcore[NONPRIME])? 1 : -1);
	}
	index = pflg ? PRIME : NONPRIME;
	if (p1->pcm_kcore[index] == p2->pcm_kcore[index])
		return(0);
	return ((p2->pcm_kcore[index] > p1->pcm_kcore[index])? 1 : -1);
}

tncmp(p1, p2)
register struct tcms *p1, *p2;
{
	if (p1->tcm_pc == p2->tcm_pc)
		return(0);
	return ((p2->tcm_pc > p1->tcm_pc)? 1 : -1);
}

ncmp(p1, p2)
register struct pcms *p1, *p2;
{
	register int	index;

	if( (pflg && oflg) || (!pflg && !oflg) ) {
		if (p1->pcm_pc[PRIME] + p1->pcm_pc[NONPRIME] == p2->pcm_pc[PRIME] + p2->pcm_pc[NONPRIME])
			return(0);
		return ((p2->pcm_pc[PRIME] + p2->pcm_pc[NONPRIME] > p1->pcm_pc[PRIME] + p1->pcm_pc[NONPRIME])? 1 : -1);
	}
	index =  pflg ? PRIME : NONPRIME;
	if (p1->pcm_pc[index] == p2->pcm_pc[index])
		return(0);
	return ((p2->pcm_pc[index] > p1->pcm_pc[index])? 1 : -1);
}

char	thd1[] =
"COMMAND   NUMBER      TOTAL       TOTAL       TOTAL   MEAN     MEAN     HOG      CHARS        BLOCKS\n";
char	thd2[] =
"NAME        CMDS    KCOREMIN     CPU-MIN     REAL-MIN SIZE-K  CPU-MIN  FACTOR   TRNSFD         READ\n";
toutpta()
{
	register i;

	printf(thd1);
	printf(thd2);
	printf("\n");
	for (i = 0; i < csize; i++)
		tcmadd(&tcmtmp, &tcm[i]);
	CPYN(tcmtmp.tcm_comm, "TOTALS");
	tprint(&tcmtmp);
	printf("\n");
	for (i = 0; i < csize; i++)
		tprint(&tcm[i]);
}

tprint(p)
register struct tcms *p;
{
	printf("%-8.8s", p->tcm_comm);
	printf("%8ld", p->tcm_pc);
	printf("%12.2f", p->tcm_kcore);
	printf("%11.2f", p->tcm_cpu);
	printf("%13.2f", p->tcm_real);
	if(p->tcm_cpu == 0)  p->tcm_cpu = 1;
	printf("%7.2f", p->tcm_kcore/p->tcm_cpu);
	if(p->tcm_pc == 0)  p->tcm_pc = 1;
	printf("%8.2f", p->tcm_cpu/p->tcm_pc);
	if (p->tcm_real == 0)
		p->tcm_real = 1;
	printf(" %8.2f", p->tcm_cpu/p->tcm_real);
	printf("%12ld",p->tcm_io);
	printf("%12ld\n",p->tcm_rw);
}

toutptc()
{
	register i;

	for (i = 0; i < csize; i++)
		fwrite(&tcm[i], sizeof(tcm[i]), 1, stdout);
}

char	hd1[] =
"COMMAND   NUMBER      TOTAL       TOTAL       TOTAL   MEAN    MEAN     HOG         CHARS     BLOCKS\n";
char	hd2[] =
"NAME        CMDS    KCOREMIN     CPU-MIN   REAL-MIN  SIZE-K  CPU-MIN  FACTOR      TRNSFD      READ\n";
char	hd3[] =
"COMMAND        NUMBER         TOTAL          CPU-MIN                 REAL-MIN        MEAN    MEAN      HOG       CHARS       BLOCKS\n";
char	hd4[] =
"NAME         (P)    (NP)   KCOREMIN       (P)      (NP)          (P)         (NP)  SIZE-K  CPU-MIN   FACTOR     TRNSFD        READ\n";
char	hdprime[] =
"                                   PRIME TIME COMMAND SUMMARY\n";
char	hdnonprime[] =
"                                  NON-PRIME TIME COMMAND SUMMARY\n";
char	hdtot[] =
"                                     TOTAL COMMAND SUMMARY\n";
char	hdp[] =
"                                PRIME/NON-PRIME TIME COMMAND SUMMARY\n";

outputa()
{
	register i;

	if( pflg && oflg ) printf(hdp);
	else if(pflg) printf(hdprime);
	else if(oflg) printf(hdnonprime);
	else printf(hdtot);
	if( (!pflg && !oflg) || (pflg ^ oflg)) {
		printf(hd1);
		printf(hd2);
	}
	else {
		printf(hd3);
		printf(hd4);
	}
	printf("\n");
	for (i = 0; i < csize; i++)
		pcmadd(&pcmtmp, &pcm[i]);
	CPYN(pcmtmp.pcm_comm, "TOTALS");
	print(&pcmtmp);
	printf("\n");
	for (i = 0; i < csize; i++)
		print(&pcm[i]);
}

print(p)
register struct pcms *p;
{
	if(pflg && oflg) pprint(p);
	else if(pflg || oflg) prnt(p, pflg ? PRIME : NONPRIME);
	else totprnt(p);
}

prnt(p, hr)
register struct pcms *p;
register int	hr;
{
	if(p->pcm_pc[hr] == 0) return;
	printf(fmtcmd, p->pcm_comm);
	printf(fmtcnt, p->pcm_pc[hr]);
	printf(fmtkcore, p->pcm_kcore[hr]);
	printf(fmtcpu, p->pcm_cpu[hr]);
	printf(fmtreal, p->pcm_real[hr]);
	if(p->pcm_cpu[hr] == 0)  p->pcm_cpu[hr] = 1;
	printf(fmtmsz, p->pcm_kcore[hr]/p->pcm_cpu[hr]);
	if(p->pcm_pc[hr] == 0)  p->pcm_pc[hr] = 1;
	printf(fmtmcpu, p->pcm_cpu[hr]/p->pcm_pc[hr]);
	if (p->pcm_real[hr] == 0)
		p->pcm_real[hr] = 1;
	printf(fmthog, p->pcm_cpu[hr]/p->pcm_real[hr]);
	printf(fmtcharx,p->pcm_io[hr]);
	printf(fmtblkx,p->pcm_rw[hr]);
	printf("\n");
}

pprint(p)
register struct pcms *p;
{
	printf(fmtcmd, p->pcm_comm);
	printf(fmtcnt, p->pcm_pc[PRIME]);
	printf(fmtcnt, p->pcm_pc[NONPRIME]);
	printf(fmtkcore, TOTAL(p->pcm_kcore));
	printf(fmtcpu, p->pcm_cpu[PRIME]);
	printf(fmtcpu, p->pcm_cpu[NONPRIME]);
	printf(fmtreal, p->pcm_real[PRIME]);
	printf(fmtreal, p->pcm_real[NONPRIME]);
	if(TOTAL(p->pcm_cpu) == 0)  p->pcm_cpu[PRIME] = 1;
	printf(fmtmsz, TOTAL(p->pcm_kcore)/TOTAL(p->pcm_cpu));
	if(TOTAL(p->pcm_pc) == 0)  p->pcm_pc[PRIME] = 1;
	printf(fmtmcpu, TOTAL(p->pcm_cpu)/TOTAL(p->pcm_pc));
	if ( TOTAL(p->pcm_real) == 0)
		p->pcm_real[PRIME] = 1;
	printf(fmthog, TOTAL(p->pcm_cpu)/TOTAL(p->pcm_real));
	printf(f      mtcharx,TOTAL(p->pcm_io));
	printf(fmtblkx, TOTAL(p->pcm_rw));
	printf("\n");
}

totprnt(p)
register struct pcms *p;
{
	printf(fmtcmd, p->pcm_comm);
	printf(fmtcnt, TOTAL(p->pcm_pc));
	printf(fmtkcore, TOTAL(p->pcm_kcore));
	printf(fmtcpu, TOTAL(p->pcm_cpu));
	printf(fmtreal, TOTAL(p->pcm_real));
	if(TOTAL(p->pcm_cpu) == 0)  p->pcm_cpu[PRIME] = 1;
	printf(fmtmsz, TOTAL(p->pcm_kcore)/TOTAL(p->pcm_cpu));
	if(TOTAL(p->pcm_pc) == 0)  p->pcm_pc[PRIME] = 1;
	printf(fmtmcpu, TOTAL(p->pcm_cpu)/TOTAL(p->pcm_pc));
	if (TOTAL(p->pcm_real) == 0)
		p->pcm_real[PRIME] = 1;
	printf(fmthog, TOTAL(p->pcm_cpu)/TOTAL(p->pcm_real));
	printf(fmtcharx,TOTAL(p->pcm_io));
	printf(fmtblkx,TOTAL(p->pcm_rw));
	printf("\n");
}
outputc()
{
	register i;

	for (i = 0; i < csize; i++)
		fwrite(&pcm[i], sizeof(pcm[i]), 1, stdout);
}
q 	   `A   0cmd/acct/acctcom.c  static char Sccsid[]="@(#)acctcom.c	1.21 of 10/20/83";

#include	<time.h>
#include	<string.h>
#include	<sys/types.h>
#include	"acctdef.h"
#include	<grp.h>
#include	<stdio.h>
#include	<sys/acct.h>
#include	<pwd.h>
#include	<sys/stat.h>

#define MYKIND(flag)	((flag & ACCTF) == 0)
#define SU(flag)	((flag & ASU) == ASU)
#define PACCT		"/usr/adm/pacct"
#define MEANSIZE	01
#define KCOREMIN	02
#define HOGFACTOR	04
#define	SEPTIME		010
#define	CPUFACTOR	020
#define IORW		040
#define	pf(dble)	fprintf(stdout, "%8.2lf", dble)
#define	ps(s)		fprintf(stdout, "%8.8s", s)
#define	diag(string)		fprintf(stderr, "\t%s\n", string)

struct	acct ab;
char	command_name[16];
char	timestring[16];
char	obuf[BUFSIZ];

double	cpucut,
	syscut,
	hogcut,
	iocut,
	realtot,
	cputot,
	usertot,
	systot,
	kcoretot,
	iotot,
	rwtot;
extern long	timezone;
extern int	daylight;	/* daylight savings time if set */
long	daydiff,
	offset = -2,
	elapsed,
	sys,
	user,
	cpu,
	mem,
	io,
	rw,
	cmdcount;
time_t	tstrt_b,
	tstrt_a,
	tend_b,
	tend_a,
	etime;
int	backward,
	flag_field,
	average,
	quiet,
	option,
	verbose = 1,
	uidflag,
	gidflag,
	unkid,	/*user doesn't have login on this machine*/
	errflg,
	su_user,
	fileout = 0,
	stdinflg,
	nfiles;
dev_t	linedev	= -1;
uid_t	uidval,
	gidval;
char	*cname = NULL; /* command name pattern to match*/

struct passwd *getpwnam(), *pw;
struct group *getgrnam(),*grp;
long	ftell(),
	convtime(),
	time(),
	tmsecs(),
	expand();
char	*ctime(),
	*ofile,
	*devtolin(),
	*uidtonam();
dev_t	lintodev();
FILE	*ostrm;

main(argc, argv)
char **argv;
{
	register int	c;
	extern int	optind;
	extern char	*optarg;

	setbuf(stdout,obuf);
	while((c = getopt(argc, argv,
		"C:E:H:I:O:S:abe:fg:hikl:mn:o:qrs:tu:v")) != EOF) {
		switch(c) {
		case 'C':
			sscanf(optarg,"%lf",&cpucut);
			continue;
		case 'O':
			sscanf(optarg,"%lf",&syscut);
			continue;
		case 'H':
			sscanf(optarg,"%lf",&hogcut);
			continue;
		case 'I':
			sscanf(optarg,"%lf",&iocut);
			continue;
		case 'a':
			average++;
			continue;
		case 'b':
			backward++;
			continue;
		case 'g':
			if(sscanf(optarg,"%hu",&gidval) == 1)
				gidflag++;
			else if((grp=getgrnam(optarg)) == NULL)
				fatal("Unknown group", optarg);
			else {
				gidval=grp->gr_gid;
				gidflag++;
			}
			continue;
		case 'h':
			option |= HOGFACTOR;
			continue;
		case 'i':
			option |= IORW;
			continue;
		case 'k':
			option |= KCOREMIN;
			continue;
		case 'm':
			option |= MEANSIZE;
			continue;
		case 'n':
			cname=(char *)cmset(optarg);
			continue;
		case 't':
			option |= SEPTIME;
			continue;
		case 'r':
			option |= CPUFACTOR;
			continue;
		case 'v':
			verbose=0;
			continue;
		case 'l':
			linedev = lintodev(optarg);
			continue;
		case 'u':
			if(*optarg == '?')
				unkid++;
			else if(*optarg == '#')
				su_user++;
			else if(sscanf(optarg, "%hu", &uidval) == 1)
				uidflag++;
			else if((pw = getpwnam(optarg)) == NULL)
				fprintf(stderr, "%s: Unknown user %s\n",
					argv[0], optarg);
			else {
				uidval = pw->pw_uid;
				uidflag++;
			}
			continue;
		case 'q':
			quiet++;
			verbose=0;
			average++;
			continue;
		case 's':
			tend_a = convtime(optarg);
			continue;
		case 'S':
			tstrt_a = convtime(optarg);
			continue;
		case 'f':
			flag_field++;
			continue;
		case 'e':
			tstrt_b = convtime(optarg);
			continue;
		case 'E':
			tend_b = convtime(optarg);
			continue;
		case 'o':
			ofile = optarg;
			fileout++;
			if((ostrm = fopen(ofile, "w")) == NULL) {
				perror("open error on output file");
				errflg++;
			}
			continue;
		case '?':
			errflg++;
			continue;
		}
	}

	if(errflg) {
		usage();
		exit(1);
	}

	argv = &argv[optind];
	while(optind++ < argc) {
		dofile(*argv);
		nfiles++;
	}

	if(nfiles==0) {
		if(isatty(0) || isdevnull())
			dofile(PACCT);
		else {
			stdinflg = 1;
			backward = offset = 0;
			dofile(NULL);
		}
	}
	doexit(0);
}

dofile(fname)
char *fname;
{
	register struct acct *a = &ab;
	long curtime;
	time_t	ts_a = 0,
		ts_b = 0,
		te_a = 0,
		te_b = 0;
	long	daystart;
	long	nsize;

	if(fname != NULL)
		if(freopen(fname, "r", stdin) == NULL) {
			fprintf(stderr, "acctcom: cannot open %s\n", fname);
			return;
		}

	if(backward) {
		backward = 0;
		if(aread() == 0)
			return;
		backward = 1;
		nsize = sizeof(struct acct);	/* make sure offse      t is signed */
		fseek(stdin, (long)(-nsize), 2);
	} else {
		if(aread() == 0)
			return;
		rewind(stdin);
	}
	tzset();
	daydiff = a->ac_btime - (a->ac_btime % SECSINDAY);
	daystart = (a->ac_btime-timezone) - ((a->ac_btime-timezone) % SECSINDAY);
	time(&curtime);
	if(daydiff < (curtime - (curtime % SECSINDAY))) {
		/*
		 * it is older than today
		 */
		fprintf(stdout,
			"\nACCOUNTING RECORDS FROM:  %s", ctime(&a->ac_btime));
	}

	if(tstrt_a) {
		ts_a = tstrt_a + daystart;
		if(daylight)
			ts_a -= 3600;
		fprintf(stdout, "START AFT: %s", ctime(&ts_a));
	}
	if(tstrt_b) {
		ts_b = tstrt_b + daystart;
		if(daylight)
			ts_b -= 3600;
		fprintf(stdout, "START BEF: %s", ctime(&ts_b));
	}
	if(tend_a) {
		te_a = tend_a + daystart;
		if(daylight)
			te_a -= 3600;
		fprintf(stdout, "END AFTER: %s", ctime(&te_a));
	}
	if(tend_b) {
		te_b = tend_b + daystart;
		if(daylight)
			te_b -= 3600;
		fprintf(stdout, "END BEFOR: %s", ctime(&te_b));
	}
	if(ts_a) {
		if (te_b && ts_a > te_b) te_b += SECSINDAY;
	}

	while(aread() != 0) {
		elapsed = expand(a->ac_etime);
		etime = a->ac_btime + (long)SECS(elapsed);
		if(ts_a || ts_b || te_a || te_b) {

			if(te_a && (etime < te_a)) {
				if(backward) return;
				else continue;
			}
			if(te_b && (etime > te_b)) {
				if(backward) continue;
				else return;
			}
			if(ts_a && (a->ac_btime < ts_a))
				continue;
			if(ts_b && (a->ac_btime > ts_b))
				continue;
		}
		if(!MYKIND(a->ac_flag))
			continue;
		if(su_user && !SU(a->ac_flag))
			continue;
		sys = expand(a->ac_stime);
		user = expand(a->ac_utime);
		cpu = sys + user;
		if(cpu == 0)
			cpu = 1;
		mem = expand(a->ac_mem);
		substr(a->ac_comm,command_name,0,8);
		io=expand(a->ac_io);
		rw=expand(a->ac_rw);
		if(cpucut && cpucut >= SECS(cpu))
			continue;
		if(syscut && syscut >= SECS(sys))
			continue;
		if(linedev != -1 && a->ac_tty != linedev)
			continue;
		if(uidflag && a->ac_uid != uidval)
			continue;
		if(gidflag && a->ac_gid != gidval)
			continue;
		if(cname && !cmatch(a->ac_comm,cname))
			continue;
		if(iocut && iocut > io)
			continue;
		if(unkid && uidtonam(a->ac_uid)[0] != '?')
			continue;
		if(verbose && (fileout == 0)) {
			printhd();
			verbose = 0;
		}
		if(elapsed == 0)
			elapsed++;
		if(hogcut && hogcut >= (double)cpu/(double)elapsed)
			continue;
		if(fileout)
			fwrite(&ab, sizeof(ab), 1, ostrm);
		else
			println();
		if(average) {
			cmdcount++;
			realtot += (double)elapsed;
			usertot += (double)user;
			systot += (double)sys;
			kcoretot += (double)mem;
			iotot += (double)io;
			rwtot += (double)rw;
		};
	}
}

aread()
{
	register flag;
	static	 ok = 1;

	if(fread((char *)&ab, sizeof(struct acct), 1, stdin) != 1)
		flag = 0;
	else
		flag = 1;

	if(backward) {
		if(ok) {
			if(fseek(stdin,
				(long)(offset*sizeof(struct acct)), 1) != 0) {
					rewind(stdin);	/* get 1st record */
					ok = 0;
			}
		} else
			flag = 0;
	}
	return(flag);
}

printhd()
{
	fprintf(stdout, "COMMAND                      START    END          REAL");
	ps("CPU");
	if(option & SEPTIME)
		ps("(SECS)");
	if(option & IORW){
		ps("CHARS");
		ps("BLOCKS");
	}
	if(option & CPUFACTOR)
		ps("CPU");
	if(option & HOGFACTOR)
		ps("HOG");
	if(!option || (option & MEANSIZE))
		ps("MEAN");
	if(option & KCOREMIN)
		ps("KCORE");
	fprintf(stdout, "\n");
	fprintf(stdout, "NAME       USER     TTYNAME  TIME     TIME       (SECS)");
	if(option & SEPTIME) {
		ps("SYS");
		ps("USER");
	} else
		ps("(SECS)");
	if(option & IORW) {
		ps("TRNSFD");
		ps("READ");
	}
	if(option & CPUFACTOR)
		ps("FACTOR");
	if(option & HOGFACTOR)
		ps("FACTOR");
	if(!option || (option & MEANSIZE))
		ps("SIZE(K)");
	if(option & KCOREMIN)
		ps("MIN");
	if(flag_field)
		fprintf(stdout, "  F STAT");
	fprintf(stdout, "\n");
	fflush(stdout);
}

println()
{

	char name[32];
	register struct acct *a = &ab;

	if(quiet)
		return;
	if(!SU(a->ac_flag))
		strcpy(name,command_name);
	else {
		strcpy(name,"#");
		strcat(name,command_name);
	}
	fprintf(stdout, "%-9.9s", name);
	strcpy(name,uidtonam(a->ac_uid));
	if(*name != '?')
		fprintf(stdout, "  %-8.8s", name);
	else
		fprintf(stdout, "  %-8d",a->ac_uid);
	fprintf(stdout, " %-8.8s",a->ac_tty != -1? devtolin(a->ac_tty):"?");
	fprintf(stdout, "%.9s", &ctime(&a->ac_btime)[10]);
	fprintf(stdout, "%.9s ", &ctime(&etime)[10]);
	pf((double)SECS(elapsed));
	if(option & SEPTIME) {
		pf((double)sys / HZ);
		pf((double)user / HZ);
	} else
		pf((double)cpu / HZ);
	if(option & IORW)
		fprintf(stdout, "%8ld%8ld",io,rw);
	if(option & CPUFACTOR)
		pf((double)user / cpu);
	if(option & HOGFACTOR)
		pf((double)cpu / elapsed);
	if(!option || (option & MEANSIZE))
		pf(KCORE(mem / cpu));
	if(option & KCOREMIN)
		pf(MINT(KCORE(mem)));
	if(flag_field)
		fprintf(stdout, "  %1o %3o", a->ac_flag, a->ac_stat);
	fprintf(stdout, "\n");
}

/*
 * convtime converts time arg to internal value
 * arg has form hr:min:sec, min or sec are assumed to be 0 if omitted
 */
long
convtime(str)
char *str;
{
	long	hr, min, sec;

	min = sec = 0;

	if(sscanf(str, "%ld:%ld:%ld", &hr, &min, &sec) < 1) {
		fatal("acctcom: bad time:", str);
	}
	tzset();
	sec += (min*60);
	sec += (hr*3600);
	return(s      ec + timezone);
}

cmatch(comm, cstr)
register char	*comm, *cstr;
{

	char	xcomm[9];
	register i;

	for(i=0;i<8;i++){
		if(comm[i]==' '||comm[i]=='\0')
			break;
		xcomm[i] = comm[i];
	}
	xcomm[i] = '\0';

	return(regex(cstr,xcomm));
}

cmset(pattern)
register char	*pattern;
{

	if((pattern=(char *)regcmp(pattern,0))==NULL){
		fatal("pattern syntax", NULL);
	}

	return((unsigned)pattern);
}

doexit(status)
{
	if(!average)
		exit(status);
	if(cmdcount) {
		fprintf(stdout, "\cmds=%ld ",cmdcount);
		fprintf(stdout, "Real=%-6.2f ",SECS(realtot)/cmdcount);
		cputot = systot + usertot;
		fprintf(stdout, "CPU=%-6.2f ",SECS(cputot)/cmdcount);
		fprintf(stdout, "USER=%-6.2f ",SECS(usertot)/cmdcount);
		fprintf(stdout, "SYS=%-6.2f ",SECS(systot)/cmdcount);
		fprintf(stdout, "CHAR=%-8.2f ",iotot/cmdcount);
		fprintf(stdout, "BLK=%-8.2f ",rwtot/cmdcount);
		fprintf(stdout, "USR/TOT=%-4.2f ",usertot/cputot);
		fprintf(stdout, "HOG=%-4.2f ",cputot/realtot);
		fprintf(stdout, "\n");
	}
	else
		fprintf(stdout, "\nNo commands matched\n");
	exit(status);
}
isdevnull()
{
	struct stat	filearg;
	struct stat	devnull;

	if(fstat(0,&filearg) == -1) {
		fprintf(stderr,"acctcom: cannot stat stdin\n");
		return(NULL);
	}
	if(stat("/dev/null",&devnull) == -1) {
		fprintf(stderr,"acctcom: cannot stat /dev/null\n");
		return(NULL);
	}

	if(filearg.st_rdev == devnull.st_rdev) return(1);
	else return(NULL);
}

fatal(s1, s2)
char *s1, *s2;
{
	fprintf(stderr,"acctcom: %s %s\n", s1, s2);
	exit(1);
}

usage()
{
	fprintf(stderr, "Usage: acctcom [options] [files]\n");
	fprintf(stderr, "\nWhere options can be:\n");
	diag("-b	read backwards through file");
	diag("-f	print the fork/exec flag and exit status");
	diag("-h	print hog factor (total-CPU-time/elapsed-time)");
	diag("-i	print I/O counts");
	diag("-k	show total Kcore minutes instead of memory size");
	diag("-m	show mean memory size");
	diag("-r	show CPU factor (user-time/(sys-time + user-time))");
	diag("-t	show separate system and user CPU times");
	diag("-v	don't print column headings");
	diag("-a	print average statistics of selected commands");
	diag("-q	print average statistics only");
	diag("-l line	\tshow processes belonging to terminal /dev/line");
	diag("-u user	\tshow processes belonging to user name or user ID");
	diag("-u #	\tshow processes executed by super-user");
	diag("-u ?	\tshow processes executed by unknown UID's");
	diag("-g group	show processes belonging to group name of group ID");
	diag("-s time	\tshow processes ending after time (hh[:mm[:ss]])");
	diag("-e time	\tshow processes starting before time");
	diag("-S time	\tshow processes starting after time");
	diag("-E time	\tshow processes ending before time");
	diag("-n regex	select commands matching the ed(1) regular expression");
	diag("-o file	\tdo not print, put selected pacct records into file");
	diag("-H factor	show processes that exceed hog factor");
	diag("-O sec	\tshow processes that exceed CPU system time sec");
	diag("-C sec	\tshow processes that exceed total CPU time sec");
	diag("-I chars	show processes that transfer more than char chars");
}
"q    RZŗ   }cmd/acct/acctcon1.c /*	@(#)acctcon1.c	1.8 of 9/23/83	*/
/*
 *	acctcon1 [-p] [-t] [-l file] [-o file] <wtmp-file >ctmp-file
 *	-p	print input only, no processing
 *	-t	test mode: use latest time found in input, rather than
 *		current time when computing times of lines still on
 *		(only way to get repeatable data from old files)
 *	-l file	causes output of line usage summary
 *	-o file	causes first/last/reboots report to be written to file
 *	reads input (normally /etc/wtmp), produces
 *	list of sessions, sorted by ending time in ctmp.h/ascii format
 *	A_TSIZE is max # distinct ttys
 */

#include <sys/types.h>
#include "acctdef.h"
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <utmp.h>
#include "ctmp.h"


int	tsize	= -1;	/* used slots in tbuf table */
struct  utmp	wb;	/* record structure read into */
struct	ctmp	cb;	/* record structure written out of */

struct tbuf {
	char	tline[LSZ];	/* /dev/* */
	char	tname[NSZ];	/* user name */
	time_t	ttime;		/* start time */
	dev_t	tdev;		/* device */
	int	tlsess;		/* # complete sessions */
	int	tlon;		/* # times on (ut_type of 7) */
	int	tloff;		/* # times off (ut_type != 7) */
	long	ttotal;		/* total time used on this line */
} tbuf[A_TSIZE];

#define NSYS	20
int	nsys;
struct sys {
	char	sname[LSZ];	/* reasons for ACCOUNTING records */
	char	snum;		/* number of times encountered */
} sy[NSYS];

time_t	datetime;	/* old time if date changed, otherwise 0 */
time_t	firstime;
time_t	lastime;
int	ndates;		/* number of times date changed */
int	exitcode;
char	*report	= NULL;
char	*replin = NULL;
int	printonly;
int	tflag;

char	*ctime();
long	ftell();
uid_t	namtouid();
dev_t	lintodev();

main(argc, argv) 
char **argv;
{

	while (--argc > 0 && **++argv == '-')
		switch(*++*argv) {
		case 'l':
			if (--argc > 0)
				replin = *++argv;
			continue;
		case 'o':
			if (--argc > 0)
				report = *++argv;
			continue;
		case 'p':
			printonly++;
			continue;
		case 't':
			tflag++;
			continue;
		}

	if (printonly)       {
		while (wread()) {
			if (valid()) {
				printf("%.12s\t%.8s\t%lu",
					wb.ut_line,
					wb.ut_name,
					wb.ut_time);
				printf("\t%s", ctime(&wb.ut_time));
			} else
				fixup(stdout);
			
		}
		exit(exitcode);
	}

	while (wread()) {
		if (firstime == 0)
			firstime = wb.ut_time;
		if (valid())
			loop();
		else
			fixup(stderr);
	}
	wb.ut_name[0] = '\0';
	strcpy(wb.ut_line, "acctcon1");
	wb.ut_type = ACCOUNTING;
	if (tflag)
		wb.ut_time = lastime;
	else
		time(&wb.ut_time);
	loop();
	if (report != NULL)
		printrep();
	if (replin != NULL)
		printlin();
	exit(exitcode);
}

wread()
{
	return( fread(&wb, sizeof(wb), 1, stdin) == 1 );
	
}

/*
 * valid: check input wtmp record, return 1 if looks OK
 */
valid()
{
	register i, c;

	for (i = 0; i < NSZ; i++) {
		c = wb.ut_name[i];
		if (isalnum(c) || c == '$' || c == ' ')
			continue;
		else if (c == '\0')
			break;
		else
			return(0);
	}

	if((wb.ut_type >= EMPTY) && (wb.ut_type <= UTMAXTYPE))
		return(1);

	return(0);
}

/*
 *	fixup assumes that V6 wtmp (16 bytes long) is mixed in with
 *	V7 records (20 bytes each)
 *
 *	Starting with Release 5.0 of UNIX, this routine will no
 *	longer reset the read pointer.  This has a snowball effect
 *	On the following records until the offset corrects itself.
 *	If a message is printed from here, it should be regarded as
 *	a bad record and not as a V6 record.
 */
fixup(stream)
register FILE *stream;
{
	fprintf(stream, "bad wtmp: offset %lu.\n", ftell(stdin)-sizeof(wb));
	fprintf(stream, "bad record is:  %.12s\t%.8s\t%lu",
		wb.ut_line,
		wb.ut_name,
		wb.ut_time);
	fprintf( stream, "\t%s", ctime(&wb.ut_time));
#ifdef	V6
	fseek(stdin, (long)-4, 1);
#endif
	exitcode = 1;
}

loop()
{
	register timediff;
	register struct tbuf *tp;

	if( wb.ut_line[0] == '\0' )	/* It's an init admin process */
		return;			/* no connect accounting data here */
	switch(wb.ut_type) {
	case OLD_TIME:
		datetime = wb.ut_time;
		return;
	case NEW_TIME:
		if(datetime == 0)
			return;
		timediff = wb.ut_time - datetime;
		for (tp = tbuf; tp <= &tbuf[tsize]; tp++)
			tp->ttime += timediff;
		datetime = 0;
		ndates++;
		return;
	case BOOT_TIME:
		upall();
	case ACCOUNTING:
	case RUN_LVL:
		lastime = wb.ut_time;
		bootshut();
		return;
	case USER_PROCESS:
	case LOGIN_PROCESS:
	case INIT_PROCESS:
		update(&tbuf[iline()]);
		return;
	case DEAD_PROCESS:
	case EMPTY:
		return;
	default:
		fprintf(stderr, "acctcon1: invalid type %d for %s %s %s",
			wb.ut_type,
			wb.ut_name,
			wb.ut_line,
			ctime(&wb.ut_time));
	}
}

/*
 * bootshut: record reboot (or shutdown)
 * bump count, looking up wb.ut_line in sy table
 */
bootshut()
{
	register i;

	for (i = 0; i < nsys && !EQN(wb.ut_line, sy[i].sname); i++)
		;
	if (i >= nsys) {
		if (++nsys > NSYS) {
			fprintf(stderr,
				"acctcon1: recompile with larger NSYS\n");
			nsys = NSYS;
			return;
		}
		CPYN(sy[i].sname, wb.ut_line);
	}
	sy[i].snum++;
}

/*
 * iline: look up/enter current line name in tbuf, return index
 * (used to avoid system dependencies on naming)
 */
iline()
{
	register i;

	for (i = 0; i <= tsize; i++)
		if (EQN(wb.ut_line, tbuf[i].tline))
			return(i);
	if (++tsize >= A_TSIZE) {
		fprintf(stderr, "acctcon1: RECOMPILE WITH LARGER A_TSIZE\n");
		exit(2);
	}

	CPYN(tbuf[tsize].tline, wb.ut_line);
	tbuf[tsize].tdev = lintodev(wb.ut_line);
	return(tsize);
}

upall()
{
	register struct tbuf *tp;

	wb.ut_type = INIT_PROCESS;	/* fudge a logoff for reboot record */
	for (tp = tbuf; tp <= &tbuf[tsize]; tp++)
		update(tp);
}

/*
 * update tbuf with new time, write ctmp record for end of session
 */
update(tp)
struct tbuf *tp;
{
	long	told,	/* last time for tbuf record */
		tnew;	/* time of this record */
			/* Difference is connect time */

	told = tp->ttime;
	tnew = wb.ut_time;
	if (told > tnew) {
		fprintf(stderr, "acctcon1: bad times: old: %s", ctime(&told));
		fprintf(stderr, "new: %s", ctime(&tnew));
		exitcode = 1;
		tp->ttime = tnew;
		return;
	}
	tp->ttime = tnew;
	switch(wb.ut_type) {
	case USER_PROCESS:
		tp->tlsess++;
		if(tp->tname[0] != '\0') { /* Someone logged in without */
					   /* logging off. Put out record. */
			cb.ct_tty = tp->tdev;
			CPYN(cb.ct_name, tp->tname);
			cb.ct_uid = namtouid(cb.ct_name);
			cb.ct_start = told;
			pnpsplit(cb.ct_start, tnew-told, cb.ct_con);
			prctmp(&cb);
			tp->ttotal += tnew-told;
		}
		else	/* Someone just logged in */
			tp->tlon++;
		CPYN(tp->tname, wb.ut_name);
		break;
	case INIT_PROCESS:
	case LOGIN_PROCESS:
		tp->tloff++;
		if(tp->tname[0] != '\0') { /* Someone logged off */
			/* Set up and print ctmp record */
			cb.ct_tty = tp->tdev;
			CPYN(cb.ct_name, tp->tname);
			cb.ct_uid = namtouid(cb.ct_name);
			cb.ct_start = told;
			pnpsplit(cb.ct_start, tnew-told, cb.ct_con);
			prctmp(&cb);
			tp->ttotal += tnew-told;
			tp->tname[0] = '\0';
		}
	}
}

printrep()
{
	register i;

	freopen(report, "w", stdout);
	printf("from %s", ctime(&firstime));
	printf("to   %s", ctime(&lastime));
	if (ndates)
		printf("%d\tdate change%c\n",ndates,(ndates>1 ? 's' : '\0'));
	for (i = 0; i < nsys; i++)
		printf("%d\t%.12s\n", sy[i].snum, sy[i].sname);
}

/*
 *	print summary o      f line usage
 *	accuracy only guaranteed for wtmp file started fresh
 */
printlin()
{
	register struct tbuf *tp;
	double timet, timei;
	double ttime;
	int tsess, ton, toff;

	freopen(replin, "w", stdout);
	ttime = 0.0;
	tsess = ton = toff = 0;
	timet = MINS(lastime-firstime);
	printf("TOTAL DURATION IS %.0f MINUTES\n", timet);
	printf("LINE\tMINUTES\tPERCENT\t# SESS\t# ON\t# OFF\n");
	for (tp = tbuf; tp <= &tbuf[tsize]; tp++) {
		timei = MINS(tp->ttotal);
		ttime += timei;
		tsess += tp->tlsess;
		ton += tp->tlon;
		toff += tp->tloff;
		printf("%.8s\t%.0f\t%.0f\t%d\t%d\t%d\n",
			tp->tline,
			timei,
			(timet > 0.)? 100*timei/timet : 0.,
			tp->tlsess,
			tp->tlon,
			tp->tloff);
	}
	printf("TOTALS\t%.0f\t--\t%d\t%d\t%d\n", ttime, tsess, ton, toff);
}

prctmp(t)
register struct ctmp *t;
{

	printf("%u\t%u\t%.8s\t%lu\t%lu\t%lu",
		t->ct_tty,
		t->ct_uid,
		t->ct_name,
		t->ct_con[0],
		t->ct_con[1],
		t->ct_start);
	printf("\t%s", ctime(&t->ct_start));
}
 q    sZL   cmd/acct/acctcon2.c /*	@(#)acctcon2.c	1.3 of 3/31/82	*/
/*
 *	acctcon2 <ctmp >ctacct
 *	reads std. input (ctmp.h/ascii format)
 *	converts to tacct.h form, writes to std. output
 */

#include <sys/types.h>
#include "acctdef.h"
#include <stdio.h>
#include "ctmp.h"
#include "tacct.h"
char	*ctime();

struct	ctmp	cb;
struct	tacct	tb;

main(argc, argv)
char **argv;
{
	tb.ta_sc = 1;
	while (scanf("%hd\t%hu\t%s\t%lu\t%lu\t%lu\t%*[^\n]",
		&cb.ct_tty,
		&cb.ct_uid,
		cb.ct_name,
		&cb.ct_con[0],
		&cb.ct_con[1],
		&cb.ct_start) != EOF) {

		tb.ta_uid = cb.ct_uid;
		CPYN(tb.ta_name, cb.ct_name);
		tb.ta_con[0] = MINS(cb.ct_con[0]);
		tb.ta_con[1] = MINS(cb.ct_con[1]);
		fwrite(&tb, sizeof(tb), 1, stdout);
	}
}
	q    pZM   /cmd/acct/acctdef.h  /*	@(#)acctdef.h	1.6 of 3/3/83	*/
/*
 *	defines, typedefs, etc. used by acct programs
 */


/*
 *	acct only typedefs
 */
typedef	unsigned short	uid_t;

#if u3b || u3b5
#define HZ	100
#else
#define HZ	60
#endif

#define LSZ	12	/* sizeof line name */
#define NSZ	8	/* sizeof login name */
#define P	0	/* prime time */
#define NP	1	/* nonprime time */

/*
 *	limits which may have to be increased if systems get larger
 */
#define A_SSIZE	1000	/* max number of sessions in 1 acct run */
#define A_TSIZE	100	/* max number of line names in 1 acct run */
#define A_USIZE	500	/* max number of distinct login names in 1 acct run */

#define EQN(s1, s2)	(strncmp(s1, s2, sizeof(s1)) == 0)
#define CPYN(s1, s2)	strncpy(s1, s2, sizeof(s1))

#define SECSINDAY	86400L
#define SECS(tics)	((double) tics)/HZ
#define MINS(secs)	((double) secs)/60
#define MINT(tics)	((double) tics)/(60*HZ)

#ifdef pdp11
#define KCORE(clicks)	((double) clicks/16)
#endif
#if vax || ns32000
#define KCORE(clicks)	((double) clicks/2)
#endif
#if u3b || u3b5
#define KCORE(clicks)	((double) clicks*2)
#endif
Hq u	   M   cmd/acct/acctdisk.c /*	@(#)acctdisk.c	1.3 of 3/31/82	*/
/*
 *	acctdisk <dtmp >dtacct
 *	reads std.input & converts to tacct.h format, writes to output
 *	input:
 *	uid	name	#blocks
 */

#include <sys/types.h>
#include "acctdef.h"
#include <stdio.h>
#include "tacct.h"

struct	tacct	tb;
char	ntmp[NSZ+1];

main(argc, argv)
char **argv;
{
	tb.ta_dc = 1;
	while(scanf("%hu\t%s\t%f",
		&tb.ta_uid,
		ntmp,
		&tb.ta_du) != EOF) {

		CPYN(tb.ta_name, ntmp);
		fwrite(&tb, sizeof(tb), 1, stdout);
	}
}
tq    N   cmd/acct/acctdusg.c /*	@(#)acctdusg.c	1.2 of 3/31/82	*/
/*
 *	disk [-u file] [-p file] > dtmp-file
 *	-u	file for names of files not charged to anyone
 *	-p	get password info from file
 *	reads input (normally from find / -print)
 *	and compute disk resource consumption by login
 */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

#define NAMESZ 8
 
struct	disk{
	char	dsk_name[NAMESZ];	/* login name */
	unsigned dsk_uid;		/* user id of login name */
	int	dsk_dirsz;	/* # letters in pathname of login directory */
	char	*dsk_logdir;	/* ptr to path name of login directory */
	int	dsk_ns;			/* no of slashes in path name */
	long	dsk_du;			/* disk usage */
	struct	disk *dsk_np;		/* ptr to next struct */

};
char	*pfile ={ "/etc/passwd" };
char	*afile, *nfile;
 
struct disk	*Dp;	/* ptr to 1st entry in dirlist */
struct stat	statb;

FILE	*pswd, *nchrg;
FILE	*names ={stdin};
FILE	*acct  ={stdout};

char	fbuf[BUFSIZ];
char	*calloc();
long	inblks();

main(argc, argv)
char	**argv;

{
	while(--argc > 0){
		++argv;
		if(**argv == '-') switch((*argv)[1]) {
		case 'u':
			if (--argc <= 0)
				break;
			if ((nchrg = fopen(*(++argv),"w")) == NULL)
				openerr(*argv);
			chmod(*argv, 0644);
			continue;
		case 'p':
			if (--argc <= 0)
				break;
			pfile = *(++argv);
			continue;
		}
		fprintf(stderr,"Invalid argument: %s\n", *argv);
		exit(1);
	}
	if ((pswd = fopen(pfile, "r")) == NULL)
		openerr(pfile);

	while (fgets(fbuf,sizeof fbuf, pswd) != NULL) {
		makdlst(fbuf);	/* make a list of home directory names
				for every entry in password file */
	}
	fclose(pswd);

	dsort();

	while( fgets(fbuf, sizeof fbuf, names) != NULL) {
		fbuf[strndx(fbuf, '\n') ] = '\0';
		clean(fbuf);
		charge(fbuf);
	}
	if (names != stdin)
		      fclose(names);

	output();

	if (acct != stdout)
		fclose(acct);
	if (nchrg)
		fclose(nchrg);
#ifdef DEBUG
		pdisk();
#endif

	exit(0);
}
openerr(file)
char	*file;
{
	fprintf(stderr, "Cannot open %s\n", file);
	exit(1);
}

output()
{

	register struct disk *dp;

	for(dp = Dp; dp != NULL; dp=dp->dsk_np) {
		if(dp->dsk_du)
			fprintf(acct,
				"%05u\t%-8.8s\t%7lu\n",
				dp->dsk_uid,
				dp->dsk_name,
				dp->dsk_du);
	}
}

strndx(str, chr)
register char *str;
register char chr;
{

	register index;

	for (index=0; *str; str++,index++)
		if (*str == chr)
			return index;
	return -1;
}

/*
 *	make a list of home directory names
 *	for every entry in password file
 */

makdlst(p)
register char *p;
{

	static struct	disk *dl = {NULL};
	struct disk	*dp;
	int    i;

	if( (dp = (struct disk *)calloc(sizeof(struct disk), 1)) == NULL) {
	nocore:
		fprintf(stderr, "out of core\n");
		exit(2);
	}
	for(i=0; i<NAMESZ; i++) {	/* copy login name from 
				password file to structure */
		if((dp->dsk_name[i] = *p++) == ':') {
			dp->dsk_name[i] = '\0';
			break;
		}
	}
	while(*p++ != ':')	/* skip password field */
		;
	sscanf(p, "%u", &(dp->dsk_uid));

	for(i=ccount(p, ':')-1; i>0; i--) /* read to end of 
			line counting field delimited by : */
		while(*p++ != ':')  /* move up to path name */
			;

	dp->dsk_dirsz = strndx(p, ':'); /* length of path name */
	if((dp->dsk_logdir = calloc(dp->dsk_dirsz + 1, 1)) == NULL)
		goto nocore;

	strncpy(dp->dsk_logdir, p, dp->dsk_dirsz);

	if(stat(dp->dsk_logdir,&statb)== -1 ||
			(statb.st_mode & S_IFMT) != S_IFDIR) {
		cfree(dp->dsk_logdir);
		cfree(dp);
		return;
	}
	for(i=0; dp->dsk_logdir[i]; i++)
		if(dp->dsk_logdir[i] == '/')
			dp->dsk_ns++; /* count # of slashes */

	if(dl == NULL) { /* link ptrs */
		Dp = dl = dp;
	} else {
		dl->dsk_np = dp;
		dl = dp;
	}
	return;
}

/*
 *	read to end of line counting
 *	fields (delimited by :
 */
ccount(p,c)
register char *p, c;
{

	register i;

	i = 0;
	while(*p)
		if(*p++ == c)
			i++;
	return i;
}
/*
 *	sort by decreasing # of levels in login
 *	pathname and then by increasing uid
 */
dsort()
{

	register struct disk *dp1, *dp2, *pdp;
	int	change;

	if(Dp == NULL || Dp->dsk_np == NULL)
		return;

	change = 0;
	pdp = NULL;

	for(dp1 = Dp; ;) {
		if((dp2 = dp1->dsk_np) == NULL) {
			if(!change)
				break;
			dp1 = Dp;
			pdp = NULL;
			change = 0;
			continue;
		}
		if((dp1->dsk_ns < dp2->dsk_ns) ||
		   (dp1->dsk_ns==dp2->dsk_ns && dp1->dsk_uid > dp2->dsk_uid)) {
			swapd(pdp, dp1, dp2);
			change = 1;
			dp1 = dp2;
			continue;
		}
		pdp = dp1;
		dp1 = dp2;
	}
}

swapd(p,d1,d2)

register struct disk *p, *d1, *d2;
{
	struct disk *t;

	switch(p) {
	default:
		p->dsk_np = d2;
		t = d2->dsk_np;
		d2->dsk_np = d1;
		d1->dsk_np = t;
		break;
	case NULL:
		t = d2->dsk_np;
		d2->dsk_np = d1;
		d1->dsk_np = t;
		Dp = d2;
		break;
	}
}

charge(n)
register char *n;
{
	register struct disk *dp;
	register i;
	long	blks;

	if(stat(n,&statb) == -1)
		return;

	i = strlen(n);
	for(dp = Dp; dp != NULL; dp = dp->dsk_np) {
		if(i < dp->dsk_dirsz)
			continue;
		if(strncmp(dp->dsk_logdir, n, dp->dsk_dirsz) == 0 &&
		   (n[dp->dsk_dirsz] == '/' || n[dp->dsk_dirsz] == '\0'))
			break;
	}

	blks = inblks(statb.st_size);
	if(blks > 8L)	/* correct for indirect blocks */
/*
 *		blks += (blks-10+127)/128 + (blks-10-128+16383)/16384 +
 *			(blks-10-128-16384+2097151)/2097152;
 */
		blks += (blks+117)/128 + (blks+16245)/16384 + (blks+2080629)/2097152;

	if(dp == NULL) {
		if(nchrg && (statb.st_size) &&
		   (statb.st_mode&S_IFMT) == S_IFDIR)
			fprintf(nchrg, "%5u\t%7lu\t%s\n",
			statb.st_uid, blks, n);
		return;
	}

	dp->dsk_du += (statb.st_mode&S_IFMT) == S_IFDIR ? blks
		:((statb.st_mode&S_IFMT)==S_IFREG ?
			(blks / statb.st_nlink) : 0L);
}

long
inblks(bytes)
long bytes;
{
	return(bytes % 512L ? (bytes/512L) + 1L : bytes/512L );
}

#ifdef DEBUG
pdisk()
{
	register struct disk *dp;

	for(dp=Dp; dp!=NULL; dp=dp->dsk_np)
		printf("%.8s\t%5u\t%7lu\t%5u\t%5u\t%s\n",
			dp->dsk_name,
			dp->dsk_uid,
			dp->dsk_du,
			dp->dsk_dirsz,
			dp->dsk_ns,
			dp->dsk_logdir);
}
#endif

clean(p)
register char *p;
{
	register char *s1, *s2;

	for(s1=p; *s1; ) {
		s2 = s1;
		while(*s1 == '/')
			s1++;
		s1 = s1<= s2 ? s2 : s1-1;
		if(s1 != s2) {
			strcpy(s2,s1);
			s1 = s2;
		}
		if(*++s2 == '.') 
		switch(*++s2) {
		case '/':
			strcpy(s1,s2);
			continue;
		case '.':
			if(*++s2 != '/')
				break;
			if(s1 > p)
				while(*--s1 != '/' && s1 > p)
					;
			strcpy(s1,s2);
			continue;
		}
		while(*s2 && *++s2 != '/')
			;
		s1 = s2;
	}
	return;
}
q m	   N    cmd/acct/acctmerg.c /*	@(#)acctmerg.c	1.4 of 1/21/83	*/
/*
 *	acctmerg [-a] [-i] [-p] [-t] [-u] [-v] [file...]
 *	-a	output in tacct.h/ascii (instead of tacct.h)
 *	-i	input is in tacct.h/ascii (instead of tacct.h)
 *	-p	print input files with no processing
 *	-t	output single record that totals all input
 *	-u	summarize by uid, rather than uid/name
 *	-v	output in verbose tacct.h/ascii
 *	reads std input and 0-NFILE files, all in tacct.h format,
 *	sorted by uid/name.
 *	merge/adds all records with same uid/name (or same uid if -      u,
 *	or all records if -t], writes to std. output
 *	(still in tacct.h format)
 *	note that this can be used to summarize the std input
 */

#include <sys/types.h>
#include "acctdef.h"
#include <stdio.h>
#include "tacct.h"

#define NFILE	10
int	nfile;			/* index of last used in fl */
FILE	*fl[NFILE]	= {stdin};

struct	tacct tb[NFILE];	/* current record from each file */
struct	tacct	tt = {
	0,
	"TOTAL"
};
int	asciiout;
int	asciiinp;
int	printonly;
int	totalonly;
int	uidsum;
int	verbose;
struct tacct	*getleast();

main(argc, argv)
char **argv;
{
	register i;
	register struct tacct *tp;

	while (--argc > 0) {
		if (**++argv == '-')
			switch (*++*argv) {
			case 'a':
				asciiout++;
				continue;
			case 'i':
				asciiinp++;
				continue;
			case 'p':
				printonly++;
				continue;
			case 't':
				totalonly++;
				continue;
			case 'u':
				uidsum++;
				continue;
			case 'v':
				verbose++;
				asciiout++;
				continue;
			}
		else {
			if (++nfile >= NFILE) {
				fprintf(stderr, "acctmerg: >%d files\n", NFILE);
				exit(1);
			}
			if ((fl[nfile] = fopen(*argv, "r")) == NULL) {
				fprintf(stderr, "acctmerg: can't open %s\n", *argv);
				exit(1);
			}
		}
	}

	if (printonly) {
		for (i = 0; i <= nfile; i++)
			while (getnext(0))
				prtacct(&tb[0]);
		exit(0);
	}

	for (i = 0; i <= nfile; i++)
		if(getnext(i) == 0)
			fprintf(stderr,"%s: read error file %d\n",argv[0],i);

	while ((tp = getleast()) != NULL)	/* get least uid of all files, */
		sumcurr(tp);			/* sum all entries for that uid, */
	if (totalonly)				/* and write the 'summed' record */
		output(&tt);
}

/*
 *	getleast returns ptr to least (lowest uid)  element of current 
 *	avail, NULL if none left; always returns 1st of equals
 */
struct tacct *getleast()
{
	register struct tacct *tp, *least;

	least = NULL;
	for (tp = tb; tp <= &tb[nfile]; tp++) {
		if (tp->ta_name[0] == '\0')
			continue;
		if (least == NULL ||
			tp->ta_uid < least->ta_uid ||
			((tp->ta_uid == least->ta_uid) &&
			!uidsum &&
			(strncmp(tp->ta_name, least->ta_name, NSZ) < 0)))
			least = tp;
	}
	return(least);
}

/*
 *	sumcurr sums all entries with same uid/name (into tp->tacct record)
 *	writes it out, gets new entry
 */
sumcurr(tp)
register struct tacct *tp;
{
	struct tacct tc;

		copyn(&tc, tp, sizeof(struct tacct));
	tacctadd(&tt, tp);	/* gets total of all uids */
	getnext(tp-&tb[0]);	/* get next one in same file */
	while (tp <= &tb[nfile])
		if (tp->ta_name[0] != '\0' &&
			tp->ta_uid == tc.ta_uid &&
			(uidsum || EQN(tp->ta_name, tc.ta_name))) {
			tacctadd(&tc, tp);
			tacctadd(&tt, tp);
			getnext(tp-&tb[0]);
		} else
			tp++;	/* look at next file */
	if (!totalonly)
		output(&tc);
}

tacctadd(t1, t2)
register struct tacct *t1, *t2;
{
	t1->ta_cpu[0] = t1->ta_cpu[0] + t2->ta_cpu[0];
	t1->ta_cpu[1] = t1->ta_cpu[1] + t2->ta_cpu[1];
	t1->ta_kcore[0] = t1->ta_kcore[0] + t2->ta_kcore[0];
	t1->ta_kcore[1] = t1->ta_kcore[1] + t2->ta_kcore[1];
	t1->ta_con[0] = t1->ta_con[0] + t2->ta_con[0];
	t1->ta_con[1] = t1->ta_con[1] + t2->ta_con[1];
	t1->ta_du = t1->ta_du + t2->ta_du;
	t1->ta_pc += t2->ta_pc;
	t1->ta_sc += t2->ta_sc;
	t1->ta_dc += t2->ta_dc;
	t1->ta_fee += t2->ta_fee;
}

output(tp)
register struct tacct *tp;
{
	if (asciiout)
		prtacct(tp);
	else
		fwrite(tp, sizeof(*tp), 1, stdout);
}
/*
 *	getnext reads next record from stream i, returns 1 if one existed
 */
getnext(i)
register i;
{
	register struct tacct *tp;

	tp = &tb[i];
	tp->ta_name[0] = '\0';
	if (fl[i] == NULL)
		return(0);
	if (asciiinp) {
		if (fscanf(fl[i],
			"%hu\t%s\t%e %e %e %e %e %e %e %lu\t%hu\t%hu\t%hu",
			&tp->ta_uid,
			tp->ta_name,
			&tp->ta_cpu[0], &tp->ta_cpu[1],
			&tp->ta_kcore[0], &tp->ta_kcore[1],
			&tp->ta_con[0], &tp->ta_con[1],
			&tp->ta_du,
			&tp->ta_pc,
			&tp->ta_sc,
			&tp->ta_dc,
			&tp->ta_fee) != EOF)
			return(1);
	} else {
		if (fread(tp, sizeof(*tp), 1, fl[i]) == 1)
			return(1);
	}
	fl[i] = NULL;
	return(0);
}

char fmt[] = "%hu\t%.9s\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\t%.0f\t%lu\t%hu\t%hu\t%hu\n";
char fmtv[] = "%hu\t%.9s\t%e %e %e %e %e %e %e %lu %hu\t%hu\t%hu\n";

prtacct(tp)
register struct tacct *tp;
{

	printf(verbose ? fmtv : fmt,
		tp->ta_uid,
		tp->ta_name,
		tp->ta_cpu[0], tp->ta_cpu[1],
		tp->ta_kcore[0], tp->ta_kcore[1],
		tp->ta_con[0], tp->ta_con[1],
		tp->ta_du,
		tp->ta_pc,
		tp->ta_sc,
		tp->ta_dc,
		tp->ta_fee);
}
q k	   ^ZP   Hcmd/acct/accton.c /*	@(#)accton.c	1.5 of 1/21/83	*/
/*
 *	accton - calls syscall with super-user privileges
 */
#include	<sys/types.h>
#include	<errno.h>
#include	<sys/stat.h>
#include	<stdio.h>

#define	ROOT	0
#define	ADM	4
#define	ERR	(-1)
#define	OK	0
#define	NOGOOD	1
#define	MATCH	0
#define	prmsg(X)	fprintf(stderr, "%s: %s: %s\n", \
				 arg0, X, sys_errlist[errno]);

char		pacct[] = "/usr/adm/pacct";
char		wtmp[] = "/etc/wtmp";
char		*arg0;
extern char	*sys_errlist[];

main(argc,argv)
int argc;
char **argv;
{
	register int	uid;

	arg0 = argv[0];
	uid = getuid();
	if(uid == ROOT || uid == ADM) {
		if(setuid(ROOT) == ERR) {
			prmsg("cannot setuid (check command mode and owner)");
			exit(1);
		}
		if(ckfile(pacct) == NOGOOD)
			exit      (1);

		if(ckfile(wtmp) == NOGOOD)
			exit(1);

		if (argc > 1) {
			if(acct(argv[1]) == ERR) {
				if(errno == EBUSY)
					fprintf(stderr, "%s: %s: %s\n",
						arg0,
						"accounting is busy",
						"cannot turn accounting ON");
				else
					prmsg("cannot turn accounting ON");
				exit(1);
			}
		}
	/*
	 * The following else branch currently never returns
	 * an ERR.  In other words, you may turn the accounting
	 * off to your heart's content.
	 */
		else if(acct((char *)0) == ERR) {
			prmsg("cannot turn accounting OFF");
			exit(1);
		}
		exit(0);

	}
	fprintf(stderr,"%s: permission denied - UID must be root/adm\n", arg0);
	exit(1);
}

ckfile(admfile)
register char	*admfile;
{
	struct stat		stbuf;
	register struct stat	*s = &stbuf;

	if(stat(admfile, s) == ERR)
		if(creat(admfile, 0664) == ERR) {
			prmsg("cannot create");
			return(NOGOOD);
		}

	if(s->st_uid != ADM || s->st_gid != ADM)
		if(chown(admfile, ADM, ADM) == ERR) {
			prmsg("cannot change owner");
			return(NOGOOD);
		}

	if(s->st_mode & 0777 != 0664)
		if(chmod(admfile, 0664) == ERR) {
			prmsg("cannot chmod");
			return(NOGOOD);
		}

	return(OK);
}
q    Q   cmd/acct/acctprc1.c /*	@(#)acctprc1.c	1.4 of 3/3/83	*/
/*
 *	acctprc1 [ctmpfile]
 *	reads std. input (acct.h format), adds login names
 *	writes std. output (ptmp.h/ascii format)
 *	if ctmpfile is given, it is expected have ctmp.h/ascii data,
 *	sorted by uid/name; it is used to make better guesses at login names
 */

#include <sys/types.h>
#include <sys/param.h>
#include "acctdef.h"
#include <stdio.h>
#include <pwd.h>
#include <sys/acct.h>
#include "ctmp.h"
#include "ptmp.h"
#define MYKIND(flag)	((flag & ACCTF) == 0)

struct	acct	ab;
struct	ctmp	cb;
struct	ptmp	pb;

struct urec {				/* 1 for each distinct uid/name */
	uid_t	ur_uid;			/* sorted by uid/name */
	char	ur_name[NSZ];
	struct srec	*ur_srec;		/* ptr to first session */
	short	ur_cnt;			/* # sessions */
} ur[A_USIZE];
struct urec *urlast	= ur;

int	ssize;
struct srec {				/* 1 for each distinct session */
	dev_t	sr_tty;			/* dev, used to connect with process*/
	time_t	sr_start;		/* start time of session */
	time_t	sr_end;			/* end time of session */
} sr[A_SSIZE];
char	*getname(), *getnamc();
char	*uidtonam();

main(argc, argv)
char **argv;
{
	long	elaps[2];
	long	etime, stime, mem;
	long	expand();

	while (--argc > 0) {
		if (**++argv == '-')
			switch(*++*argv) {
			}
		else {
			readctmp(*argv);
		}
	}

	while (fread(&ab, sizeof(ab), 1, stdin) == 1) {
		if (!MYKIND(ab.ac_flag))
			continue;
		pb.pt_uid = ab.ac_uid;
		CPYN(pb.pt_name, getname(ab.ac_uid, ab.ac_tty, ab.ac_btime));
		/*
		 * approximate cpu P/NP split as same as elapsed time
		 */
		if ((etime = SECS(expand(ab.ac_etime))) == 0)
			etime = 1;
		stime = expand(ab.ac_stime) + expand(ab.ac_utime);
		mem = expand(ab.ac_mem);
		pnpsplit(ab.ac_btime, etime, elaps);
		pb.pt_cpu[0] = (double)stime * (double)elaps[0] / etime;
		pb.pt_cpu[1] = (stime > pb.pt_cpu[0])? stime - pb.pt_cpu[0] : 0;
		pb.pt_cpu[1] = stime - pb.pt_cpu[0];
		if (stime)
			pb.pt_mem = (mem + stime - 1) / stime;
		else
			pb.pt_mem = 0;	/* unlikely */
		printf("%u\t%.8s\t%lu\t%lu\t%u\n",
			pb.pt_uid,
			pb.pt_name,
			pb.pt_cpu[0], pb.pt_cpu[1],
			pb.pt_mem);
	}
}

/*
 *	return ptr to name corresponding to uid
 *	try ctmp first, then use uidtonam (internal list or passwd file)
 */
char *
getname(uid, tty, start)
uid_t	uid;
dev_t	tty;
time_t	start;
{
	register char *p;

	if ((p = getnamc(uid, tty, start)) != NULL)
		return(p);
	return(uidtonam(uid));
}

/*
 *	read ctmp file, build up urec-srec data structures for
 *	later use by getnamc
 */
readctmp(fname)
char *fname;
{
	FILE *fp;
	register struct urec *up;
	register struct srec *sp;

	if ((fp = fopen(fname, "r")) == NULL) {
		fprintf(stderr, "acctprc1: can't open %s\n", fname);
		return;
	}

	up = NULL;
	sp = sr;
	while (fscanf(fp, "%hd\t%hu\t%s\t%lu\t%lu\t%lu\t%*[^\n]",
		&cb.ct_tty,
		&cb.ct_uid,
		cb.ct_name,
		&cb.ct_con[0],
		&cb.ct_con[1],
		&cb.ct_start) != EOF) {
		if (up == NULL || cb.ct_uid != up->ur_uid ||
			!EQN(cb.ct_name, up->ur_name)) {
			if (up == NULL)
				up = ur;
			else if (++up >= &ur[A_USIZE]) {
				fprintf(stderr, "acctprc1: INCREASE A_USIZE\n");
				exit(1);
			}
			up->ur_uid = cb.ct_uid;
			CPYN(up->ur_name, cb.ct_name);
			up->ur_srec = sp;
			up->ur_cnt = 0;
		}
		if (sp >= &sr[A_SSIZE-1]) {
			fprintf(stderr, "acctprc1: INCREASE A_SSIZE\n");
			exit(1);
		}
		sp->sr_tty = cb.ct_tty;
		sp->sr_start = cb.ct_start;
		sp->sr_end = cb.ct_start + cb.ct_con[0] + cb.ct_con[1];
		sp++;
		up->ur_cnt++;
	}
	if (up != NULL)
		urlast = ++up;
	fclose(fp);
}

/*
 *	using urec-srec data (if any), make best guess at login name
 *	corresponding to uid, return ptr to the name.
 *	must match on tty; use start time to help guess
 *	for any urec having same uid as uid, search array of associated
 *	srecs for those having same tty
 *	if start time of process is within range of session, that's it
 *	if none can be found within range, give it to person of same uid
 *	who last logged off on that terminal
 */
char *
getnamc(uid, tty, start)
r      egister uid_t uid;
dev_t	tty;
time_t	start;
{
	register struct urec *up;
	register struct srec *sp;
	struct srec *splast;
	long latest;
	char *guess;

	latest = 0;
	guess = NULL;
	for (up = ur; up < urlast && uid >= up->ur_uid; up++)
		if (uid == up->ur_uid) {
			sp = up->ur_srec;
			splast = sp+up->ur_cnt;
			for (; sp < splast; sp++)
				if (tty == sp->sr_tty) {
					if (start >= sp->sr_start &&
						start <= sp->sr_end)
						return(up->ur_name);
					if (start >= sp->sr_start &&
						sp->sr_end > latest) {
						latest = sp->sr_end;
						guess = up->ur_name;
					}
				}
		}

	return(guess);
}
q    ZR   Acmd/acct/acctprc2.c /*	@(#)acctprc2.c	1.5 of 3/3/83	*/
/*
 *	acctprc2 <ptmp1 >ptacct
 *	reads std. input (in ptmp.h/ascii format)
 *	hashes items with identical uid/name together, sums times
 *	sorts in uid/name order, writes tacct.h records to output
 */

#include <sys/types.h>
#include "acctdef.h"
#include <stdio.h>
#include "ptmp.h"
#include "tacct.h"

struct	ptmp	pb;
struct	tacct	tb;

struct	utab	{
	uid_t	ut_uid;
	char	ut_name[NSZ];
	float	ut_cpu[2];	/* cpu time (mins) */
	float	ut_kcore[2];	/* kcore-mins */
	long	ut_pc;		/* # processes */
} ub[A_USIZE];
static	usize;
int	ucmp();

main(argc, argv)
char **argv;
{
	while (scanf("%hu\t%s\t%lu\t%lu\t%u",
		&pb.pt_uid,
		pb.pt_name,
		&pb.pt_cpu[0], &pb.pt_cpu[1],
		&pb.pt_mem) != EOF)
			enter(&pb);
	squeeze();
	qsort(ub, usize, sizeof(ub[0]), ucmp);
	output();
}

enter(p)
register struct ptmp *p;
{
	register unsigned i;
	int j;
	double memk;

	/* clear end of short users' names */
	for(i = strlen(p->pt_name) + 1; i < NSZ; p->pt_name[i++] = '\0') ;
	/* now hash the uid and login name */
	for(i = j = 0; p->pt_name[j] != '\0'; ++j)
		i = i*7 + p->pt_name[j];
	i = i*7 + p->pt_uid;
	j = 0;
	for (i %= A_USIZE; ub[i].ut_name[0] && j++ < A_USIZE; i = (i+1)% A_USIZE)
		if (p->pt_uid == ub[i].ut_uid && EQN(p->pt_name, ub[i].ut_name))
			break;
	if (j >= A_USIZE) {
		fprintf(stderr, "acctprc2: INCREASE A_USIZE\n");
		exit(1);
	}
	if (ub[i].ut_name[0] == 0) {	/*this uid not yet in table so enter it*/
		ub[i].ut_uid = p->pt_uid;
		CPYN(ub[i].ut_name, p->pt_name);
	}
	ub[i].ut_cpu[0] += MINT(p->pt_cpu[0]);
	ub[i].ut_cpu[1] += MINT(p->pt_cpu[1]);
	memk = KCORE(pb.pt_mem);
	ub[i].ut_kcore[0] += memk * MINT(p->pt_cpu[0]);
	ub[i].ut_kcore[1] += memk * MINT(p->pt_cpu[1]);
	ub[i].ut_pc++;
}

squeeze()		/*eliminate holes in hash table*/
{
	register i, k;

	for (i = k = 0; i < A_USIZE; i++)
		if (ub[i].ut_name[0]) {
			ub[k].ut_uid = ub[i].ut_uid;
			CPYN(ub[k].ut_name, ub[i].ut_name);
			ub[k].ut_cpu[0] = ub[i].ut_cpu[0];
			ub[k].ut_cpu[1] = ub[i].ut_cpu[1];
			ub[k].ut_kcore[0] = ub[i].ut_kcore[0];
			ub[k].ut_kcore[1] = ub[i].ut_kcore[1];
			ub[k].ut_pc = ub[i].ut_pc;
			k++;
		}
	usize = k;
}

ucmp(p1, p2)
register struct utab *p1, *p2;
{
	if (p1->ut_uid != p2->ut_uid)
		/* the following (short) typecasts are a kludge fix
		 * for a bug in the 5.0 C compiler.  The bug returns a
		 * result that is always positive from the subtraction
		 * because of the unsigned short type of ut_uid.
		 */
		return((short)p1->ut_uid - (short)p2->ut_uid);
	return(strncmp(p1->ut_name, p2->ut_name, NSZ));
}

output()
{
	register i;

	for (i = 0; i < usize; i++) {
		tb.ta_uid = ub[i].ut_uid;
		CPYN(tb.ta_name, ub[i].ut_name);
		tb.ta_cpu[0] = ub[i].ut_cpu[0];
		tb.ta_cpu[1] = ub[i].ut_cpu[1];
		tb.ta_kcore[0] = ub[i].ut_kcore[0];
		tb.ta_kcore[1] = ub[i].ut_kcore[1];
		tb.ta_pc = ub[i].ut_pc;
		fwrite(&tb, sizeof(tb), 1, stdout);
	}
}
_q J   YR   cmd/acct/acctwtmp.c /*	@(#)acctwtmp.c	1.2 of 3/31/82	*/
/*
 *	acctwtmp reason >> /etc/wtmp
 *	writes utmp.h record (with current time) to end of std. output
 *	acctwtmp `uname` >> /etc/wtmp as part of startup
 *	acctwtmp pm >> /etc/wtmp  (taken down for pm, for example)
 */
#include <stdio.h>
#include "acctdef.h"
#include <sys/types.h>
#include <utmp.h>

struct	utmp	wb;

main(argc, argv)
char **argv;
{
	if(argc < 2) {
		fprintf(stderr, "Usage: %s reason [ >> %s ]\n",
			argv[0], WTMP_FILE);
		exit(1);
	}

	strncpy(wb.ut_line, argv[1], LSZ);
	wb.ut_line[11] = NULL;
	wb.ut_type = ACCOUNTING;
	time(&wb.ut_time);
	fseek(stdout, 0L, 2);
	fwrite(&wb, sizeof(wb), 1, stdout);
}
pq #   dZS   7cmd/acct/chargefee.sh #	@(#)chargefee.sh	1.2 of 3/31/82	#
#	"chargefee login-name number"
#	"emits tacct.h/ascii record to charge name $number"
cd /usr/adm
PATH=/usr/lib/acct:/bin:/usr/bin:/etc
if test $# -lt 2; then
	echo "usage: chargefee name number"
	exit
fi
_entry="`grep \^$1: /etc/passwd`"
if test -z "${_entry}"; then
	echo "can't find login name $1"
	exit
fi
case "$2"  in
-[0-9]*|[0-9]*);;
*)
	echo "charge invalid: $2"
	exit
esac

if test ! -r fee; then
	nulladm fee
fi
_userid=`echo "${_entry}" | cut -d: -f3`  # get the UID
echo  "${_userid} $1 0 0 0 0 0 0 0 0 0 0 $2"  >>fee
Cq    =ZQ   cmd/acct/ckpacct.sh #	@(#)ckpacct.sh	1.2 of 3/31/82	#
#       "periodically check the size of /usr/adm/pacct"
#       "if over $1 blocks (500) default, execute turnacct switch"
#       "should be run as adm"

PATH=/usr/lib/acct:/bin:/us      r/bin:/etc
trap "rm -f /usr/adm/cklock*; exit 0" 0 1 2 3 9 15
export PATH

_max=${1-500}
_MIN_BLKS=500
cd /usr/adm

#	set up lock files to prevent simultaneous checking

cp /dev/null cklock
chmod 400 cklock
ln cklock cklock1
if test $? -ne 0 ; then exit 1; fi

#	If there are less than $_MIN_BLKS free blocks left on the /usr
#	file system, turn off the accounting (unless things improve
#	the accounting wouldn't run anyway).  If something has
#	returned the file system space, restart accounting.  This
#	feature relies on the fact that ckpacct is kicked off by the
#	cron at least once per hour.

#ifdef ns32000
_blocks=`df / | sed "s/.*:  *\([0-9][0-9]*\) blocks.*/\1/"`
#else
_blocks=`df /usr | sed "s/.*:  *\([0-9][0-9]*\) blocks.*/\1/"`
#endif

if [ "$_blocks" -lt $_MIN_BLKS   -a  -f /tmp/acctoff ];then
	echo "ckpacct: /usr still low on space ($_blocks blks); \c"
	echo "acctg still off"
	( echo "ckpacct: /usr still low on space ($_blocks blks); \c"
	echo "acctg still off" ) | mail root adm
	exit 1
elif [ "$_blocks" -lt $_MIN_BLKS ];then
	echo "ckpacct: /usr too low on space ($_blocks blks); \c"
	echo "turning acctg off"
	( echo "ckpacct: /usr too low on space ($_blocks blks); \c"
	echo "turning acctg off" ) | mail root adm
	nulladm /tmp/acctoff
	turnacct off
	exit 1
elif [ -f /tmp/acctoff ];then
	echo "ckpacct: /usr free space restored; turning acctg on" | \
		mail root adm
	rm /tmp/acctoff
	turnacct on
fi

_cursize="`du -s pacct | sed 's/	.*//'`"
if [ "${_max}" -lt "${_cursize}" ]; then
	turnacct switch
fi
q N   @ZT   .cmd/acct/ctmp.h /*	@(#)ctmp.h	1.2 of 3/31/82	*/
/*
 *	connect time record (various intermediate files)
 */
struct ctmp {
	dev_t	ct_tty;			/* major minor */
	uid_t	ct_uid;			/* userid */
	char	ct_name[8];		/* login name */
	long	ct_con[2];		/* connect time (p/np) secs */
	time_t	ct_start;		/* session start time */
};
q n	   %ZU   "cmd/acct/diskusg.c  /*	@(#)diskusg.c	1.3 of 7/22/83	*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/ino.h>
#include <sys/stat.h>
#include <sys/filsys.h>
#include <sys/sysmacros.h>
#include <pwd.h>
#include <fcntl.h>

#ifndef Fs2BLK
#define Fs2BLK	0
#endif

#ifndef FsINOS
#define FsINOS(dev, x)	((x&~07)+1)
#endif

#define BLOCK		512	/* Block size for reporting */

#if pdp11
#define		NINODE		(INOPB * 2 * 10)
#else
#define		NINODE		(INOPB * 2 * 32)
#endif
#define		MAXUSERS	1000
#define		MAXIGN		10
#define		UNUSED		-1
#define		FAIL		-1
#define		MAXNAME		8
#define		SUCCEED		0
#define		TRUE		1
#define		FALSE		0

struct	filsys	sblock;
struct	dinode	dinode[NINODE];
struct  passwd *getpwent();

int	VERBOSE = 0;
FILE	*ufd = 0;
int	index;
unsigned ino, nfiles;

struct acct  {
	int	uid;
	long	usage;
	char	name [MAXNAME+1];
} userlist [MAXUSERS];

char	*ignlist[MAXIGN];
int	igncnt = {0};

char	*cmd;


unsigned hash();
main(argc, argv)
int argc;
char **argv;
{
	extern	int	optind;
	extern	char	*optarg;
	register c;
	register FILE	*fd;
	register	rfd;
	struct	stat	sb;
	int	sflg = {FALSE};
	char	*pfile = {"/etc/passwd"};
	int	errfl = {FALSE};

	cmd = argv[0];
	while((c = getopt(argc, argv, "vu:p:si:")) != EOF) switch(c) {
	case 's':
		sflg = TRUE;
		break;
	case 'v':
		VERBOSE = 1;
		break;
	case 'i':
		ignore(optarg);
		break;
	case 'u':
		ufd = fopen(optarg, "a");
		break;
	case 'p':
		pfile = optarg;
		break;
	case '?':
		errfl++;
		break;
	}
	if(errfl) {
		fprintf(stderr, "Usage: %s [-sv] [-p pw_file] [-u file] [-i ignlist] [file ...]\n", cmd);
		exit(10);
	}

	hashinit();
	if(sflg == TRUE) {
		if(optind == argc){
			adduser(stdin);
		} else {
			for( ; optind < argc; optind++) {
				if( (fd = fopen(argv[optind], "r")) == NULL) {
					fprintf(stderr, "%s: Cannot open %s\n", cmd, argv[optind]);
					continue;
				}
				adduser(fd);
				fclose(fd);
			}
		}
	}
	else {
		setup(pfile);
		for( ; optind < argc; optind++) {
			if( (rfd = open(argv[optind], O_RDONLY)) < 0) {
				fprintf(stderr, "%s: Cannot open %s\n", cmd, argv[optind]);
				continue;
			}
			if(fstat(rfd, &sb) >= 0){
				if ( (sb.st_mode & S_IFMT) == S_IFCHR ||
				     (sb.st_mode & S_IFMT) == S_IFBLK ) {
					ilist(argv[optind], rfd);
				} else {
					fprintf(stderr, "%s: %s is not a special file -- ignored\n", cmd, argv[optind]);
				}
			} else {
				fprintf(stderr, "%s: Cannot stat %s\n", cmd, argv[optind]);
			}
			close(rfd);
		}
	}
	output();
	exit(0);
}

adduser(fd)
register FILE	*fd;
{
	int	usrid;
	long	blcks;
	char	login[MAXNAME+10];

	while(fscanf(fd, "%d %s %ld\n", &usrid, login, &blcks) == 3) {
		if( (index = hash(usrid)) == FAIL) return(FAIL);
		if(userlist[index].uid == UNUSED) {
			userlist[index].uid = usrid;
			strncpy(userlist[index].name, login, MAXNAME);
		}
		userlist[index].usage += blcks;
	}
}

ilist(file, fd)
char	*file;
register fd;
{
	register dev_t	dev;
	register i, j;

	if (fd < 0 ) {
		return (FAIL);
	}

	sync();

	/* Fake out block size to be 512 */
	dev = 0;

	/* Read in super-block of filesystem */
	bread(fd, 1, &sblock, sizeof(sblock), dev);

	/* Check for filesystem names to ignore */
	if(!todo(sblock.s_fname))
		return;
	/* Check for size of fil      esystem to be 512 or 1K */
	if (sblock.s_magic == FsMAGIC && sblock.s_type == Fs2b)
		dev = Fs2BLK;	/* 1K */
	else
		dev = 0;	/* 512 */


	nfiles = (sblock.s_isize-2) * FsINOPB(dev);

	/* Determine physical block 2 */
	i = FsINOS(dev, 2);
	i = FsITOD(dev, i);

	/* Start at physical block 2, inode list */
	for (ino = 0; ino < nfiles; i += NINODE/FsINOPB(dev)) {
		bread(fd, i, dinode, sizeof(dinode), dev);
		for (j = 0; j < NINODE && ino++ < nfiles; j++)
			if (dinode[j].di_mode & S_IFMT)
				if(count(j, dev) == FAIL) {
					if(VERBOSE)
						fprintf(stderr,"BAD UID: file system = %s, inode = %u, uid = %u\n",
					    	file, ino, dinode[j].di_uid);
					if(ufd)
						fprintf(ufd, "%s %u %u\n", file, ino, dinode[j].di_uid);
				}
	}
	return (0);
}

ignore(str)
register char	*str;
{
	char	*skip();

	for( ; *str && igncnt < MAXIGN; str = skip(str), igncnt++)
		ignlist[igncnt] = str;
	if(igncnt == MAXIGN) {
		fprintf(stderr, "%s: ignore list overflow. Recompile with larger MAXIGN\n", cmd);
	}
}
bread(fd, bno, buf, cnt, dev)
register fd;
register unsigned bno;
register struct  dinode  *buf;
register dev_t dev;
{
	lseek(fd, (long)bno*FsBSIZE(dev), 0);
	if (read(fd, buf, cnt) != cnt)
	{
		fprintf(stderr, "read error %u\n", bno);
		exit(1);
	}
}

count(j, dev)
register j;
register dev_t dev;
{
	long	blocks();

	if ( dinode[j].di_nlink == 0 || dinode[j].di_mode == 0 )
		return(SUCCEED);
	if( (index = hash(dinode[j].di_uid)) == FAIL || userlist[index].uid == UNUSED )
		return (FAIL);
	userlist[index].usage += blocks(j, dev);
	return (SUCCEED);
}


output()
{
	for (index=0; index < MAXUSERS ; index++)
		if ( userlist[index].uid != UNUSED && userlist[index].usage != 0 )
			printf("%u	%s	%ld\n",
			    userlist[index].uid,
			    userlist[index].name,
			    userlist[index].usage);
}

#define SNGLIND(dev)	(FsNINDIR(dev))
#define DBLIND(dev)	(FsNINDIR(dev)*FsNINDIR(dev))
#define	TRPLIND(dev)	(FsNINDIR(dev)*FsNINDIR(dev)*FsNINDIR(dev))

long
blocks(j, dev)
register int j;
register dev_t dev;
{
	register long blks;

	blks = (dinode[j].di_size + FsBSIZE(dev) - 1)/FsBSIZE(dev);
	if(blks > 10) {
		blks += (blks-10+SNGLIND(dev)-1)/SNGLIND(dev) +
			(blks-10-SNGLIND(dev)+DBLIND(dev)-1)/DBLIND(dev) +
			(blks-10-SNGLIND(dev)-DBLIND(dev)+TRPLIND(dev)-1)/TRPLIND(dev);
	}
	if(FsBSIZE(dev) != BLOCK) {
		blks = (blks+BLOCK/FsBSIZE(dev))*FsBSIZE(dev)/BLOCK;
	}
	return(blks);
}

unsigned
hash(j)
register unsigned j;
{
	register unsigned start;
	register unsigned circle;
	circle = start = j % MAXUSERS;
	do
	{
		if ( userlist[circle].uid == j || userlist[circle].uid == UNUSED )
			return (circle);
		circle = (circle + 1) % MAXUSERS;
	} while ( circle != start);
	return (FAIL);
}

hashinit() {
	for(index=0; index < MAXUSERS ; index++)
	{
		userlist[index].uid = UNUSED;
		userlist[index].usage = 0;
		userlist[index].name[0] = '\0';
	}
}

setup(pfile)
char	*pfile;
{
	register struct passwd	*pw;

	if( !setpwent(pfile)) {
		fprintf(stderr, "%s: Cannot open %s\n", cmd, pfile);
		exit(5);
	}
	while ( (pw=getpwent()) != NULL )
	{
		if ( (index=hash(pw->pw_uid)) == FAIL )
		{
			fprintf(stderr,"diskacct: INCREASE SIZE OF MAXUSERS\n");
			return (FAIL);
		}
		if ( userlist[index].uid == UNUSED )
		{
			userlist[index].uid = pw->pw_uid;
			strncpy( userlist[index].name, pw->pw_name, MAXNAME);
		}
	}
}

todo(fname)
register char	*fname;
{
	register	i;

	for(i = 0; i < igncnt; i++) {
		if(strncmp(fname, ignlist[i], 6) == 0) return(FALSE);
	}
	return(TRUE);
}

char	*
skip(str)
register char	*str;
{
	while(*str) {
		if(*str == ' ' ||
		    *str == ',') {
			*str = '\0';
			str++;
			break;
		}
		str++;
	}
	return(str);
}

extern long atol();
extern char *fgets();

static FILE *pwf = NULL;
static char line[BUFSIZ+1];
static struct passwd passwd;

setpwent(pfile)
register char *pfile;
{
	if(pwf == NULL)
		pwf = fopen(pfile, "r");
	else
		rewind(pwf);
	return(pwf != NULL);
}

void
endpwent()
{
	if(pwf != NULL) {
		(void) fclose(pwf);
		pwf = NULL;
	}
}

static char *
pwskip(p)
register char *p;
{
	while(*p && *p != ':' && *p != '\n')
		++p;
	if(*p == '\n')
		*p = '\0';
	else if(*p)
		*p++ = '\0';
	return(p);
}

struct passwd *
getpwent()
{
	register char *p;
	long	x;

	if(pwf == NULL) {
		return(0);
	}
	p = fgets(line, BUFSIZ, pwf);
	if(p == NULL)
		return(0);
	passwd.pw_name = p;
	p = pwskip(p);
	passwd.pw_passwd = p;
	p = pwskip(p);
	x = atol(p);	
	passwd.pw_uid = (x < 0 || x > MAXUID)? (MAXUID+1): x;
	p = pwskip(p);
	x = atol(p);
	passwd.pw_gid = (x < 0 || x > MAXUID)? (MAXUID+1): x;
	p = pwskip(p);
	passwd.pw_gecos = p;
	p = pwskip(p);
	passwd.pw_dir = p;
	p = pwskip(p);
	passwd.pw_shell = p;
	(void) pwskip(p);

	p = passwd.pw_passwd;
	while(*p && *p != ',')
		p++;
	if(*p)
		*p++ = '\0';
	passwd.pw_age = p;
	return(&passwd);
}
q    ,YU   kcmd/acct/dodisk.sh  #	@(#)dodisk.sh	1.4 of 5/18/83	#
# 'perform disk accounting'
_dir=/usr/adm
_pickup=acct/nite
PATH=/usr/lib/acct:/bin:/usr/bin:/etc:
export PATH
set -- `getopt o $*`
if [ $? -ne 0 ]
then
	echo "Usage: $0 [ -o ] [ filesystem ... ]"
	exit 1
fi
for i in $*; do
	case $i in
	-o)	SLOW=1; shift;;
	--)	shift; br      eak;;
	esac
done

cd ${_dir}
date

if [ "$SLOW" = "" ]
then
	if [ $# -lt 1 ]
	then
		args=`cat /etc/checklist`
	else
		args="$*"
	fi
	diskusg $args > dtmp
else
	if [ $# -lt 1 ]
	then
		args="/"
	else
		args="$*"
	fi
	for i in $args; do
		if [ ! -d $i ]
		then
			echo "$0: $i is not a directory -- ignored"
		else
			dir="$i $dir"
		fi
	done
	if [ "$dir" = "" ]
	then
		echo "$0: No data"
		> dtmp
	else
		find $dir -print | acctdusg > dtmp
	fi
fi

date
sort +0n +1 -o dtmp dtmp
acctdisk <dtmp >disktmp
chmod 644 disktmp
chown adm disktmp
mv disktmp ${_pickup}/disktacct
 q 1   YV   .cmd/acct/fwtmp.c h/*	@(#)fwtmp.c	1.2 of 3/31/82	*/
# include <stdio.h>
# include <sys/types.h>
# include <utmp.h>
# include "acctdef.h"

struct	utmp	Ut;

main ( c, v, e )
char	**v, **e;
int	c;
{

	int	iflg,cflg;

	iflg = cflg = 0;

	while ( --c > 0 ){
		if(**++v == '-') while(*++*v) switch(**v){
		case 'c':
			cflg++;
			continue;
		case 'i':
			iflg++;
			continue;
		}
		break;
	}

	for(;;){
		if(iflg){
			if(inp(stdin,&Ut) == EOF)
				break;
		} else {
			if(fread(&Ut,sizeof Ut, 1, stdin) != 1)
				break;
		}
		if(cflg)
			fwrite(&Ut,sizeof Ut, 1, stdout);
		else
		  printf("%-8.8s %-4.4s %-12.12s %5hd %2hd %4.4ho %4.4ho %lu %s",
				Ut.ut_name,
				Ut.ut_id,
				Ut.ut_line,
				Ut.ut_pid,
				Ut.ut_type,
				Ut.ut_exit.e_termination,
				Ut.ut_exit.e_exit,
				Ut.ut_time,
				ctime(&Ut.ut_time)+4);
	}
	exit ( 0 );
}
inp(file, u)
FILE *file;
register struct utmp *u;
{

	char	buf[BUFSIZ];
	register char *p;
	register i;

	if(fgets((p = buf), BUFSIZ, file)==NULL)
		return EOF;

	for(i=0; i<NSZ; i++)	/* Allow a space in name field */
		u->ut_name[i] = *p++;
	for(i=NSZ-1; i >= 0; i--) {
		if(u->ut_name[i] == ' ')
			u->ut_name[i] = '\0';
		else
			break;
	}
	p++;

	for(i=0; i<4; i++)
		if((u->ut_id[i] = *p++)==' ')
			u->ut_id[i] = '\0';
	p++;

	for(i=0; i<LSZ; i++)	/* Allow a space in line field */
		u->ut_line[i] = *p++;
	for(i=LSZ-1; i >= 0; i--) {
		if(u->ut_line[i] == ' ')
			u->ut_line[i] = '\0';
		else
			break;
	}

	sscanf(p, "%hd %hd %ho %ho %ld",
		&u->ut_pid,
		&u->ut_type,
		&u->ut_exit.e_termination,
		&u->ut_exit.e_exit,
		&u->ut_time);

	return((unsigned)u);
}
q    YV   cmd/acct/holidays * @(#)holidays	1.3 of 1/20/83
* Prime/Nonprime Table for UNIX Accounting System
*
* Curr	Prime	Non-Prime
* Year	Start	Start
*
  1983	0830	1700
*
* Day of	Calendar	Company
* Year		Date		Holiday
*
   52		Feb 21		Wash. Birthday
  150		May 30		Memorial Day
  185		Jul 4		Indep. Day
  248		Sep 5		Labor Day
  328		Nov 24		Thanksgiving Day
  329		Nov 25		day after Thanksgiving
  360		Dec 26		Christmas
nq    W    cmd/acct/lastlogin.sh #	@(#)lastlogin.sh	1.2 of 3/31/82	#
#	"lastlogin - keep record of date each person last logged in"
#	"bug - the date shown is usually 1 more than it should be "
#	"       because lastlogin is run at 4am and checks the last"
#	"       24 hrs worth of process accounting info (in pacct)"
PATH=/usr/lib/acct:/bin:/usr/bin:/etc
cd /usr/adm/acct
if test ! -r sum/loginlog; then
	nulladm sum/loginlog
fi
#	"cleanup loginlog - delete entries of those no longer in"
#	"/etc/passwd and add an entry for those recently added"
#	"line 1 - get file of current logins in same form as loginlog"
#	"line 2 - merge the 2 files; use uniq to delete common"
#	"lines resulting in those lines which need to be"
#	"deleted or added from loginlog"
#	"line 3 - result of sort will be a file with 2 copies"
#	"of lines to delete and 1 copy of lines that are "
#	"valid; use uniq to remove duplicate lines"
cat /etc/passwd | sed "s/\([^:]*\).*/00-00-00  \1/" |\
sort +1 - sum/loginlog | uniq -u +10 |\
sort +1 - sum/loginlog |uniq -u > sum/tmploginlog
cp sum/tmploginlog sum/loginlog
#	"update loginlog"
_d="`date +%y-%m-%d`"
_day=`date +%m%d`
#	"lines 1 and 2 - remove everything from the total"
#	"acctng records with connect info except login"
#	"name and adds the date"
#	"line 3 - sorts in reverse order by login name; gets"
#	"1st occurrence of each login name and resorts by date"
acctmerg -a < nite/ctacct.$_day | \
 sed -e "s/^[^ 	]*[ 	]\([^ 	]*\)[ 	].*/$_d  \1/" | \
 sort -r +1 - sum/loginlog | uniq +10 | sort >sum/tmploginlog
cp sum/tmploginlog sum/loginlog
rm -f sum/tmploginlog
q A   <     cmd/acct/lib lq    Y~   [cmd/acct/lib/Makefile #	@(#)Makefile	1.2 of 3/31/82	#
ROOT=
PFX=
CC=$(PFX)cc
AS=$(PFX)as
AR=$(PFX)ar
LD=$(PFX)ld
TESTDIR = .
LIB = a.a
CFLAGS = -O
INCDIR = ..
FRC =

FILES= \
	$(LIB)(pnpsplit.o) \
	$(LIB)(copyn.o) \
	$(LIB)(devtolin.o) \
	$(LIB)(expand.o) \
	$(LIB)(lintodev.o) \
	$(LIB)(namtouid.o) \
	$(LIB)(tmless.o) \
	$(LIB)(tmsecs.o) \
	$(LIB)(uidtonam.o) \
	$(LIB)(substr.o) \
	$(LIB)(regex.o) \
	$(LIB)(regcmp.o)

all:	$(LIB) $(FRC)

$(LIB):	$(FILES)
	@echo lib $(LIB) is now up to date

clean:
	-rm -f *.o

clobber:	clean
	-rm -f $(LIB)

FRC:

.c.a:
	$(CC) $(CFLAGS) -I$(INCDIR) -c $<
	$(AR) rv $@ $*.o
	rm -f $*.o

2q    ?    cmd/acct/lib/copyn.c  /*	@(#)copyn.c	1.2 of 3/31/82	*/
/*
 * Copy n bytes from s2 to s1
 * return s1
 */

char *
copyn(s1, s2, n)
register char *s      1, *s2;
{
	register i;
	register char *os1;

	os1 = s1;
	for (i = 0; i < n; i++)
		*s1++ = *s2++;
	return(os1);
}
q    ?   cmd/acct/lib/devtolin.c /*	@(#)devtolin.c	1.2 of 3/31/82	*/
/*
 *	convert device to linename (as in /dev/linename)
 *	return ptr to LSZ-byte string, "?" if not found
 *	device must be character device
 *	maintains small list in tlist for speed
 */

#include <sys/types.h>
#include "acctdef.h"
#include <stdio.h>
#include <sys/dir.h>

#define TSIZE1	50	/* # distinct names, for speed only */
static	tsize1;
static struct tlist {
	char	tname[LSZ];	/* linename */
	dev_t	tdev;		/* device */
} tl[TSIZE1];

static struct direct d;

dev_t	lintodev();

char *
devtolin(device)
dev_t device;
{
	register struct tlist *tp;
	FILE *fdev;

	for (tp = tl; tp < &tl[tsize1]; tp++)
		if (device == tp->tdev)
			return(tp->tname);

	if ((fdev = fopen("/dev", "r")) == NULL)
		return("?");
	while (fread(&d, sizeof(d), 1, fdev) == 1)
		if (d.d_ino != 0 && lintodev(d.d_name) == device) {
			if (tsize1 < TSIZE1) {
				tp->tdev = device;
				CPYN(tp->tname, d.d_name);
				tsize1++;
			}
			fclose(fdev);
			return(d.d_name);
		}
	fclose(fdev);
	return("?");
}
q    Z?   cmd/acct/lib/expand.c /*	@(#)expand.c	1.3 of 3/3/83	*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/acct.h>

time_t
expand(ct)
register comp_t ct;
{
	register e;
	register time_t f;

	e = (ct >> 13) & 07;
	f = ct & 017777;
	while (e-- > 0)
		f <<= 3;
	return f;
}
"q    @   cmd/acct/lib/lintodev.c /*	@(#)lintodev.c	1.2 of 3/31/82	*/
/*
 *	convert linename to device
 *	return -1 if nonexistent or not character device
 */
#include "acctdef.h"
#include <sys/types.h>
#include <sys/stat.h>
static	char	devtty[5+LSZ+1]	= "/dev/xxxxxxxx";

dev_t
lintodev(linename)
char linename[LSZ];
{
	struct stat sb;
	strncpy(&devtty[5], linename, LSZ);
	if (stat(devtty, &sb) != -1 && (sb.st_mode&S_IFMT) == S_IFCHR)
		return((dev_t)sb.st_rdev);
	return((dev_t)-1);
}
eq    @   cmd/acct/lib/namtouid.c /*	@(#)namtouid.c	1.3 of 3/3/83	*/
/*
 *	namtouid converts login names to uids
 *	maintains ulist for speed only
 */
#include "acctdef.h"
#include <stdio.h>
#include <pwd.h>
static	usize;
static	struct ulist {
	char	uname[NSZ];
	uid_t	uuid;
} ul[A_USIZE];
char	ntmp[NSZ+1];

uid_t
namtouid(name)
char	name[NSZ];
{
	register struct ulist *up;
	register uid_t tuid;
	struct passwd *getpwnam();
	register struct passwd *pp;

	for (up = ul; up < &ul[usize]; up++)
		if (strncmp(name, up->uname, NSZ) == 0)
			return(up->uuid);
	strncpy(ntmp, name, NSZ);
	setpwent();
	if ((pp = getpwnam(ntmp)) == NULL)
		tuid = -1;
	else {
		tuid = pp->pw_uid;
		if (usize < A_USIZE) {
			CPYN(up->uname, name);
			up->uuid = tuid;
			usize++;
		}
	}
	return(tuid);
}
q    A   cmd/acct/lib/pnpsplit.c /*	@(#)pnpsplit.c	1.3 of 6/22/82	*/
/*
 * pnpsplit splits interval into prime & nonprime portions
 * ONLY ROUTINE THAT KNOWS ABOUT HOLIDAYS AND DEFN OF PRIME/NONPRIME
 */
#include "acctdef.h"
#include <stdio.h>
#include <time.h>

#define	NHOLIDAYS	20	/* max number of company holidays per year */

/* validate that hours and minutes of prime/non-prime read in
 * from holidays file fall within proper boundaries.
 * Time is expected in the form and range of 0000-2359.
 */
#define	okay(time)	((time/100>=0) && (time/100<=24) \
				 && (time%100>=0) && (time%100<60))

static int	thisyear = 1970;	/* this is changed by holidays file */
static int	holidays[NHOLIDAYS];	/* holidays file day-of-year table */
static char	holfile[] = { "/usr/lib/acct/holidays\0" };

/*
 *	prime(0) and nonprime(1) times during a day
 *	for BTL, prime time is 9AM to 5PM
 */
static struct hours {
	int	h_sec;		/* normally always zero */
	int	h_min;		/* initialized from holidays file (time%100) */
	int	h_hour;		/* initialized from holidays file (time/100) */
	int	h_type;		/* prime/nonprime of previous period */
} h[4];
int	daysend[] = {60, 59, 23};	/* the sec, min, hr of the day's end */

struct tm *localtime();
long	tmsecs();

/*
 * split interval of length etime, starting at start into prime/nonprime
 * values, return as result
 * input values in seconds
 */
pnpsplit(start, etime, result)
long start, etime, result[2];
{
	struct tm cur, end;
	long tcur, tend;
	long tmp;
	register sameday;
	register struct hours *hp;

	if (thisyear)	/* once holidays file is read, this is zero */
		checkhol();

	tcur = start;
	tend = start+etime;
	copyn(&end, localtime(&tend), sizeof(end));
	result[P] = 0;
	result[NP] = 0;

	while (tcur < tend) {	/* one iteration per day or part thereof */
		copyn(&cur, localtime(&tcur), sizeof(cur));
		sameday = cur.tm_yday == end.tm_yday;
		if (ssh(&cur)) {	/* ssh:only NP */
			if (sameday) {
				result[NP] += tend-tcur;
				break;
			} else {
				tmp = tmsecs(&cur, daysend);
				result[NP] += tmp;
				tcur += tmp;
			}
		} else {	/* working day, P or NP */
			for (hp = h; tmless(hp, &cur); hp++);
			for (; hp->h_sec >= 0; hp++) {
				if (sameday && tmless(&end, hp)) {
					result[hp->h_type] = tend-tcur;
					tcur = tend;
					break;	/* all done */
				}       else {	/* time to next P/NP change */
					tmp = tmsecs(&cur, hp);
					result[hp->h_type] += tmp;
					tcur += tmp;
					cur.tm_sec = hp->h_sec;
					cur.tm_min = hp->h_min;
					cur.tm_hour = hp->h_hour;
				}
			}
		}
	}
}

/*
 *	Starting day after Christmas, complain if holidays not yet updated.
 *	This code is only executed once per program invocation.
 */
checkhol()
{
	register struct tm *tp;
	long t;

	if(inithol() == 0) {
		fprintf(stderr, "pnpsplit: holidays table setup failed\n");
		thisyear = 0;
		holidays[0] = -1;
		return;
	}
	time(&t);
	tp = localtime(&t);
	tp->tm_year += 1900;
	if ((tp->tm_year == thisyear && tp->tm_yday > 359)
		|| tp->tm_year > thisyear)
		fprintf(stderr,
			"***UPDATE %s WITH NEW HOLIDAYS***\n", holfile);
	thisyear = 0;	/* checkhol() will not be called again */
}

/*
 * ssh returns 1 if Sat, Sun, or Holiday
 */
ssh(ltp)
register struct tm *ltp;
{
	register i;

	if (ltp->tm_wday == 0 || ltp->tm_wday == 6)
		return(1);
	for (i = 0; holidays[i] >= 0; i++) {
		if (ltp->tm_yday < holidays[i])
			continue;
		else if (ltp->tm_yday == holidays[i])
			return(1);
		else if (ltp->tm_yday > holidays[i])
			break;	/* holidays is sorted */
	}
	return(0);
}

/*
 * inithol - read from an ascii file and initialize the "thisyear"
 * variable, the times that prime and non-prime start, and the
 * holidays array.
 */
inithol()
{
	FILE		*fopen(), *holptr;
	char		*fgets(), holbuf[128];
	register int	line = 0,
			holindx = 0,
			errflag = 0;
	void		sort();
	int		pstart, npstart;
	int		doy;	/* day of the year */

	if((holptr=fopen(holfile, "r")) == NULL) {
		perror(holfile);
		fclose(holptr);
		return(0);
	}
	while(fgets(holbuf, sizeof(holbuf), holptr) != NULL) {
		if(holbuf[0] == '*')	/* Skip over comments */
			continue;
		else if(++line == 1) {	/* format: year p-start np-start */
			if(sscanf(holbuf, "%4d %4d %4d",
				&thisyear, &pstart, &npstart) != 3) {
				fprintf(stderr,
					"%s: bad {yr ptime nptime} conversion\n",
					holfile);
				errflag++;
				break;
			}

			/* validate year */
			if(thisyear < 1970 || thisyear > 2000) {
				fprintf(stderr, "pnpsplit: invalid year: %d\n",
					thisyear);
				errflag++;
				break;
			}

			/* validate prime/nonprime hours */
			if((! okay(pstart)) || (! okay(npstart))) {
				fprintf(stderr,
					"pnpsplit: invalid p/np hours\n");
				errflag++;
				break;
			}

			/* Set up start of prime time; 2400 == 0000 */
			h[0].h_sec = 0;
			h[0].h_min = pstart%100;
			h[0].h_hour = (pstart/100==24) ? 0 : pstart/100;
			h[0].h_type = NP;

			/* Set up start of non-prime time; 2400 == 0000 */
			h[1].h_sec = 0;
			h[1].h_min = npstart%100;
			h[1].h_hour = (npstart/100==24) ? 0 : npstart/100;
			h[1].h_type = P;

			/* This is the end of the day */
			h[2].h_sec = 60;
			h[2].h_min = 59;
			h[2].h_hour = 23;
			h[2].h_type = NP;

			/* The end of the array */
			h[3].h_sec = -1;

			continue;
		}
		else if(holindx >= NHOLIDAYS) {
			fprintf(stderr, "pnpsplit: too many holidays, ");
			fprintf(stderr, "recompile with larger NHOLIDAYS\n");
			errflag++;
			break;
		}

		/* Fill up holidays array from holidays file */
		sscanf(holbuf, "%d	%*s %*s	%*[^\n]\n", &doy);
		if(doy < 1 || doy > 366) {
			fprintf(stderr,
				"pnpsplit: invalid day of year %d\n", doy);
			errflag++;
			break;
		}
		holidays[holindx++] = (doy - 1);
	}
	fclose(holptr);
	if(!errflag && holindx < NHOLIDAYS) {
		sort(holidays, holindx - 1);
		holidays[holindx] = -1;
		return(1);
	}
	else
		return(0);
}

/*
 * sort - a version of the bubblesort algorithm from BAASE, Alg 2.1
 *
 * sorts the holidays array into nondecreasing order
 */
void
sort(array, nitems)
int	*array;		/* a pointer to the holidays array */
int	nitems;		/* the number of elements in the array */
{
	register int	index,	/* index going though holidays array */
			flag,	/* flag > 0 if more sorting is needed */
			k;

	flag = nitems;
	while(flag > 0) {
		k = flag - 1;
		flag = 0;
		for(index=0; index <= k; ++index) {
			if(array[index] > array[index+1]) {
				flag = array[index];	/* briefly use "flag"*/
				array[index] = array[index+1];
				array[index+1] = flag;
				flag = index;
			}
		}
	}

}
mq    bYB   cmd/acct/lib/regcmp.c /*	@(#)regcmp.c	1.3 of 3/31/82	*/
#define SSIZE	50
#define TGRP	48
#define A256	02
#define ZERO	01
#define	NBRA	10
#define CIRCFL	32;
#define SLOP	5
#define	EOF	0

#define	CBRA	60
#define GRP	40
#define SGRP	56
#define PGRP	68
#define EGRP	44
#define RNGE	03
#define	CCHR	20
#define	CDOT	64
#define	CCL	24
#define	NCCL	8
#define	CDOL	28
#define	CEOF	52
#define	CKET	12

#define	STAR	01
#define PLUS	02
#define MINUS	16

int	*__sp_;
char	*__stmax;
int	__i_size;
char *
regcmp(cs1,cs2,cs3,cs4,cs5,cs6,cs7,cs8,cs9,cs10) 
char *cs1,*cs2,*cs3,*cs4,*cs5,*cs6,*cs7,*cs8,*cs9,*cs10;
{
	register c;
	register char *ep, *sp;
	int *adx;
	int i,cflg;
	char *lastep, *sep, *eptr;
	char bracket[NBRA], *bracketp;
	int nbra,ngrp;
	int cclcnt;
	char stack[SSIZE];

	__sp_ = (int *)stack;
	*__sp_ = -1;
	__stmax = &stack[SSIZE];

	adx = (int *)&cs1;
	i = nbra = ngrp = 0;
	while(*adx)  i += __size(*adx++);
	adx = (int *)&cs1;
	sp = (char *)      *adx++;
	if((sep = ep = (char *)malloc(2*i+SLOP)) == (char *)0)
		return(0);
	bracketp = bracket;
	if ((c = *sp++) == EOF) goto cerror;
	if (c=='^') {
		c = *sp++;
		*ep++ = CIRCFL;
	}
	if ((c=='*') || (c=='+') || (c=='{'))
		goto cerror;
	sp--;
	for (;;) {
		if ((c = *sp++) == EOF) {
			if (*adx) {
				sp = (char *)*adx++;
				continue;
			}
			*ep++ = CEOF;
			if (--nbra > NBRA || *__sp_ != -1)
				goto cerror;
			__i_size = ep - sep;
			return(sep);
		}
		if ((c!='*') && (c!='{')  && (c!='+'))
			lastep = ep;
		switch (c) {

		case '(':
			if (!__rpush(ep)) goto cerror;
			*ep++ = CBRA;
			*ep++ = -1;
			continue;
		case ')':
			if (!(eptr=(char *)__rpop())) goto cerror;
			if ((c = *sp++) == '$') {
				if ('0' > (c = *sp++) || c > '9')
					goto cerror;
				*ep++ = CKET;
				*ep++ = *++eptr = nbra++;
				*ep++ = (c-'0');
				continue;
			}
			*ep++ = EGRP;
			*ep++ = ngrp++;
			sp--;
			switch (c) {
			case '+':
				*eptr = PGRP;
				break;
			case '*':
				*eptr = SGRP;
				break;
			case '{':
				*eptr = TGRP;
				break;
			default:
				*eptr = GRP;
				continue;
			}
			i = ep - eptr - 2;
			for (cclcnt = 0; i >= 256; cclcnt++)
				i -= 256;
			if (cclcnt > 3) goto cerror;
			*eptr |= cclcnt;
			*++eptr = i;
			continue;

		case '\\':
			*ep++ = CCHR;
			if ((c = *sp++) == EOF)
				goto cerror;
			*ep++ = c;
			continue;

		case '{':
			*lastep |= RNGE;
			cflg = 0;
		nlim:
			if ((c = *sp++) == '}') goto cerror;
			i = 0;
			do {
				if ('0' <= c && c <= '9')
					i = (i*10+(c-'0'));
				else goto cerror;
			} while (((c = *sp++) != '}') && (c != ','));
			if (i>255) goto cerror;
			*ep++ = i;
			if (c==',') {
				if (cflg++) goto cerror;
				if((c = *sp++) == '}') {
					*ep++ = -1;
					continue;
				}
				else {
					sp--;
					goto nlim;
				}
			}
			if (!cflg) *ep++ = i;
			else if ((ep[-1]&0377) < (ep[-2]&0377)) goto cerror;
			continue;

		case '.':
			*ep++ = CDOT;
			continue;

		case '+':
			if (*lastep==CBRA || *lastep==CKET)
				goto cerror;
			*lastep |= PLUS;
			continue;

		case '*':
			if (*lastep==CBRA || *lastep==CKET)
			goto cerror;
			*lastep |= STAR;
			continue;

		case '$':
			if ((*sp != EOF) || (*adx))
				goto defchar;
			*ep++ = CDOL;
			continue;

		case '[':
			*ep++ = CCL;
			*ep++ = 0;
			cclcnt = 1;
			if ((c = *sp++) == '^') {
				c = *sp++;
				ep[-2] = NCCL;
			}
			do {
				if (c==EOF)
					goto cerror;
				if ((c=='-') && (cclcnt>1) && (*sp!=']')) {
					*ep++ = ep[-1];
					ep[-2] = MINUS;
					cclcnt++;
					continue;
				}
				*ep++ = c;
				cclcnt++;
			} while ((c = *sp++) != ']');
			lastep[1] = cclcnt;
			continue;

		defchar:
		default:
			*ep++ = CCHR;
			*ep++ = c;
		}
	}
   cerror:
	free(sep);
	return(0);
}
__size(strg) char *strg;
{
	int	i;

	i = 1;
	while(*strg++) i++;
	return(i);
}
__rpop() {
	return (*__sp_ == -1)?0:*__sp_--;
}
__rpush(ptr) char *ptr;
{
	if (++__sp_ > (int *)__stmax) return(0);
	*__sp_ = (int)ptr;
	return(1);
}
q    C   ?cmd/acct/lib/regex.c  /*	@(#)regex.c	1.3 of 3/31/82	*/
#define SSIZE	50
#define TGRP	48
#define A256	01
#define A512	02
#define A768	03
#define	NBRA	10
#define CIRCFL	32
#define	EOF	-1

#define	CBRA	60
#define GRP	40
#define SGRP	56
#define PGRP	68
#define EGRP	44
#define RNGE	03
#define	CCHR	20
#define	CDOT	64
#define	CCL	24
#define	NCCL	8
#define	CDOL	28
#define	CEOF	52
#define	CKET	12

#define	STAR	01
#define PLUS	02
#define MINUS	16
char	*__braslist[NBRA];
char	*__braelist[NBRA];
char	*__loc1;
int	__bravar[NBRA];
int	*__st[SSIZE + 1];
int	*__eptr_,*__lptr_;
int	__cflg;
char *
regex(addrc,addrl,a1,a2,a3,a4,a5) char *addrc, *addrl, *a1, *a2, *a3, *a4, *a5;
{
	int cur,in;
	register int *adx;
	register char *p1, *p2;

	for(in=0;in<NBRA;in++) {
		__braslist[in] = 0;
		__bravar[in] = -1;
	}
	__cflg = 0;
	cur = __execute(addrc,addrl);
	adx = (int *)&a1;
	for(in=0;in<NBRA;in++) {
		if ((p1 = __braslist[in]) && (__bravar[in] >= 0)) {
			p2 = (char *)adx[__bravar[in]];
			while(p1 < __braelist[in]) *p2++ = *p1++;
			*p2 = '\0';
		}
	}
	if (!__cflg) return (addrl==(char *)cur)?(char *)0:(char *)cur;
	else return (char *)cur;
}

__execute(addrc,addrl)
char *addrc,*addrl;
{
	register char *p1, *p2, c;
	int i;

	p1 = addrl;
	p2 = addrc;
	__eptr_ = (int *)&__st[SSIZE];
	__lptr_ = (int *)&__st[0];
	if (*p2==CIRCFL) {
		__loc1 = p1;
		return (i=__advance(p1,++p2))?i:(int)addrl;
	}
	/* fast check for first character */
	if (*p2==CCHR) {
		c = p2[1];
		do {
			if (*p1!=c)
				continue;
			__eptr_ = (int *)&__st[SSIZE];
			__lptr_ = (int *)&__st[0];
			if (i=__advance(p1, p2))  {
				__loc1 = p1;
				return(i);
			}
		} while (*p1++);
		return((int)addrl);
	}
	/* regular algorithm */
	do {
	__eptr_ = (int *)&__st[SSIZE];
	__lptr_ = (int *)&__st[0];
		if (i=__advance(p1, p2))  {
			__loc1 = p1;
			return(i);
		}
	} while (*p1++);
	return((int)addrl);
}

__advance(alp, aep)
{
	register char *lp, *ep, *curlp;
	char *sep,*dp;
	char *nextep;
	int i,lcnt,dcnt,gflg;

	lp = (char *)alp;
	ep = (char *)aep;
	gflg = 0;
	for (;;) {
		switch(*ep++) {

	case CCHR:
		if (*ep++ == *lp++)
			continue;
		return(0);

	case EGRP|RNGE:
		return((int)l      p);
	case EGRP:
	case GRP:
		ep++;
		continue;

	case EGRP|STAR:
		__xpop(0);
	case EGRP|PLUS:
		__xpush(0,++ep);
		return((int)lp);

	case CDOT:
		if (*lp++)
			continue;
		return(0);

	case CDOL:
		if (*lp==0)
			continue;
		lp++;
		return(0);

	case CEOF:
		__cflg = 1;
		return((int)lp);

	case TGRP:
	case TGRP|A768:
	case TGRP|A512:
	case TGRP|A256:
		i = (((ep[-1]&03)<<8) + (*ep)&0377);
		ep++;
		__xpush(0,ep + i + 2);
		gflg = 1;
		__getrnge(&lcnt,&dcnt,&ep[i]);
		while(lcnt--)
			if (!(lp=(char *)__advance(lp,ep)))
				return(0);
		__xpush(1,curlp=lp);
		while(dcnt--)
			if(!(dp=(char *)__advance(lp,ep))) break;
			else __xpush(1,lp=dp);
		ep = (char *)__xpop(0);
		goto star;
	case CCHR|RNGE:
		sep = ep++;
		__getrnge(&lcnt,&dcnt,ep);
		while(lcnt--)
			if(*lp++!=*sep) return(0);
		curlp = lp;
		while(dcnt--)
			if(*lp++!=*sep) break;
		if (dcnt < 0) lp++;
		ep += 2;
		goto star;
	case CDOT|RNGE:
		__getrnge(&lcnt,&dcnt,ep);
		while(lcnt--)
			if(*lp++ == '\0') return(0);
		curlp = lp;
		while(dcnt--)
			if(*lp++ == '\0') break;
		if (dcnt < 0) lp++;
		ep += 2;
		goto star;
	case CCL|RNGE:
	case NCCL|RNGE:
		__getrnge(&lcnt,&dcnt,(ep + (*ep&0377)));
		while(lcnt--)
			if(!__cclass(ep,*lp++,ep[-1]==(CCL|RNGE))) return(0);
		curlp = lp;
		while(dcnt--)
			if(!__cclass(ep,*lp++,ep[-1]==(CCL|RNGE))) break;
		if (dcnt < 0) lp++;
		ep += (*ep + 2);
		goto star;
	case CCL:
		if (__cclass(ep, *lp++, 1)) {
			ep += *ep;
			continue;
		}
		return(0);

	case NCCL:
		if (__cclass(ep, *lp++, 0)) {
			ep += *ep;
			continue;
		}
		return(0);

	case CBRA:
		__braslist[*ep++] = lp;
		continue;

	case CKET:
		__braelist[*ep] = lp;
		__bravar[*ep] = ep[1];
		ep += 2;
		continue;

	case CDOT|PLUS:
		if (*lp++ == '\0') return(0);
	case CDOT|STAR:
		curlp = lp;
		while (*lp++);
		goto star;

	case CCHR|PLUS:
		if (*lp++ != *ep) return(0);
	case CCHR|STAR:
		curlp = lp;
		while (*lp++ == *ep);
		ep++;
		goto star;

	case PGRP:
	case PGRP|A256:
	case PGRP|A512:
	case PGRP|A768:
		if (!(lp=(char *)__advance(lp,ep+1))) return(0);
	case SGRP|A768:
	case SGRP|A512:
	case SGRP|A256:
	case SGRP:
		i = (((ep[-1]&03) << 8) + (*ep&0377));
		ep++;
		__xpush(0,ep + i);
		__xpush(1,curlp=lp);
		while (i=__advance(lp,ep))
			__xpush(1,lp=(char *)i);
		ep = (char *)__xpop(0);
		gflg = 1;
		goto star;

	case CCL|PLUS:
	case NCCL|PLUS:
		if (!__cclass(ep,*lp++,ep[-1]==(CCL|PLUS))) return(0);
	case CCL|STAR:
	case NCCL|STAR:
		curlp = lp;
		while (__cclass(ep, *lp++, ((ep[-1]==(CCL|STAR)) || (ep[-1]==(CCL|PLUS)))));
		ep += *ep;
		goto star;

	star:
		do {
			if(!gflg) lp--;
			else if (!(lp=(char *)__xpop(1))) break;
			if (i=__advance(lp, ep)) 
				return(i);
		} while (lp > curlp);
		return(0);

	default:
		return(0);
	}
	}
}
__cclass(aset, ac, af)
{
	register char *set, c;
	register n;

	set = (char *)aset;
	if ((c = ac) == 0)
		return(0);
	n = *set++;
	while (--n) {
		if (*set == MINUS) {
			if ((set[2] - set[1]) < 0) return(0);
			if (*++set <= c) {
				if (c <= *++set)
					return(af);
			}
			else ++set;
			++set;
			n -= 2;
			continue;
		}
		if (*set++ == c)
			return(af);
	}
	return(!af);
}
__xpush(i,p) int i; char *p;
{
	if (__lptr_ >= __eptr_) {write(2,"stack overflow\n",15);exit(1);}
	if (i) *__lptr_++ = (int)p;
	else   *__eptr_-- = (int)p;
	return(1);
}
__xpop(i) int i;
{
	if (i)
		return (__lptr_ < (int *)&__st[0])?0:*--__lptr_;
	else
		return (__eptr_ > (int *)&__st[SSIZE])?0:*++__eptr_;
}
__getrnge(i,j,k) int *i,*j; char *k;
{
	*i = (*k++&0377);
	if (*k == -1) *j = 20000;
	else *j = ((*k&0377) - *i);
	return(1);
}
;q    C   bcmd/acct/lib/substr.c /*	@(#)substr.c	1.2 of 3/31/82	*/
/*
	Place the `len' length substring of `as' starting at `as[origin]'
	in `aresult'.
	Return `aresult'.
 
  Note: The copying of as to aresult stops if either the
	specified number (len) characters have been copied,
	or if the end of as is found.
	A negative len generally guarantees that everything gets copied.
*/

char *substr(as, aresult, origin, len)
char *as, *aresult;
int origin;
register unsigned len;
{
	register char *s, *result;

	s = as + origin;
	result = aresult;
	++len;
	while (--len && (*result++ = *s++)) ;
	if (len == 0)
		*result = 0;
	return(aresult);
}
q |   C   ~cmd/acct/lib/tmless.c /*	@(#)tmless.c	1.2 of 3/31/82	*/
/*
 *	return 1 if t1 earlier than t2 (times in localtime format)
 *	assumed that t1 and t2 are in same day
 */
#include <time.h>

tmless(t1, t2)
register struct tm *t1, *t2;
{
	if (t1->tm_hour != t2->tm_hour)
		return(t1->tm_hour < t2->tm_hour);
	if (t1->tm_min != t2->tm_min)
		return(t1->tm_min < t2->tm_min);
	return(t1->tm_sec < t2->tm_sec);
}
q x    YD   fcmd/acct/lib/tmsecs.c /*	@(#)tmsecs.c	1.2 of 3/31/82	*/
/*
 *	tmsecs returns number of seconds from t1 to t2,
 *	times expressed in localtime format.
 *	assumed that t1 <= t2, and are in same day.
 */

#include <time.h>
long
tmsecs(t1, t2)
register struct tm *t1, *t2;
{
	return((t2->tm_sec - t1->tm_sec) +
		60*(t2->tm_min - t1->tm_min) +
		3600L*(t2->tm_hour - t1->tm_hour));
}
q    YD   Dcmd/acct/lib/uidtonam.c /*	@(#)uid      tonam.c	1.2 of 3/31/82	*/
/*
 * convert uid to login name; interface to getpwuid that keeps up to USIZE1
 * names to avoid unnecessary accesses to passwd file
 * returns ptr to NSZ-byte name (not necessarily null-terminated)
 * returns ptr to "?" if cannot convert
 */

#include "acctdef.h"
#include <stdio.h>
#include <pwd.h>

#define USIZE1	50
static	usize1;
static struct ulist {
	char	uname[NSZ];
	uid_t	uuid;
} ul[USIZE1];

char *
uidtonam(uid)
uid_t	uid;
{
	register struct ulist *up;
	struct passwd *getpwuid();
	register struct passwd *pp;

	for (up = ul; up < &ul[usize1]; up++)
		if (uid == up->uuid)
			return(up->uname);
	setpwent();
	if ((pp = getpwuid(uid)) == NULL)
		return("?");
	else {
		if (usize1 < USIZE1) {
			up->uuid = uid;
			CPYN(up->uname, pp->pw_name);
			usize1++;
		}
		return(pp->pw_name);
	}
}
q n'     
s~   cmd/acct/lib/Makefile.O #	@(#)Makefile	1.2 of 3/31/82	#
TESTDIR = .
LIB = a.a
CFLAGS = -O
INCDIR = ..
FRC =

FILES= \
	$(LIB)(pnpsplit.o) \
	$(LIB)(copyn.o) \
	$(LIB)(devtolin.o) \
	$(LIB)(expand.o) \
	$(LIB)(lintodev.o) \
	$(LIB)(namtouid.o) \
	$(LIB)(tmless.o) \
	$(LIB)(tmsecs.o) \
	$(LIB)(uidtonam.o) \
	$(LIB)(substr.o) \
	$(LIB)(regex.o) \
	$(LIB)(regcmp.o)

all:	$(LIB) $(FRC)

$(LIB):	$(FILES)
	@echo lib $(LIB) is now up to date

clean:
	-rm -f *.o

clobber:	clean
	-rm -f $(LIB)

FRC:

.c.a:
	$(CC) $(CFLAGS) -I$(INCDIR) -c $<
	ar rv $@ $*.o
	rm -f $*.o

rq v   YW   5cmd/acct/monacct.sh #	@(#)monacct.sh	1.2 of 3/31/82	#
#	"this procedure should be run periodically ( by month or fiscal )"
_adm=/usr/adm
_sum=${_adm}/acct/sum
_fiscal=${_adm}/acct/fiscal
PATH=:/usr/lib/acct:/bin:/usr/bin:/etc
export PATH


#if test $# -ne 1; then
#	echo "usage: monacct fiscal-number"
#	exit
#fi

_period=${1-`date +%m`}

cd ${_adm}

#	"move summary tacct file to fiscal directory"
mv ${_sum}/tacct ${_fiscal}/tacct${_period}

#	"delete the daily tacct files"
rm -f ${_sum}/tacct????

#	"restart summary tacct file"
nulladm ${_sum}/tacct

#	"move summary cms file to fiscal directory
mv ${_sum}/cms ${_fiscal}/cms${_period}

#	"restart summary cms file"
nulladm ${_sum}/cms

#	"remove old prdaily reports"
rm -f ${_sum}/rprt*

#	"produce monthly reports"
prtacct ${_fiscal}/tacct${_period} > ${_fiscal}/fiscrpt${_period}
acctcms -a -s ${_fiscal}/cms${_period} |  \
pr -h "TOTAL COMMAND SUMMARY FOR FISCAL ${_period}" >> ${_fiscal}/fiscrpt${_period}
pr -h "LAST LOGIN" -3 ${_sum}/loginlog >> ${_fiscal}/fiscrpt${_period}

#	"add commands here to do any charging of fees, etc"
exit
;q u   YX    cmd/acct/nulladm.sh #	@(#)nulladm.sh	1.2 of 3/31/82	#
#	"nulladm name..."
#	"creates each named file mode 664"
#	"make sure owned by adm (in case created by root)"
for _file
do
	cp /dev/null $_file
	chmod 664 $_file
	chgrp adm $_file
	chown adm $_file
done
;q    >X   Ccmd/acct/prctmp.sh  #	@(#)prctmp.sh	1.3 of 12/15/82	#
#	"print session record file (ctmp.h/ascii) with headings"
#	"prctmp file [heading]"
PATH=/usr/lib/acct:/bin:/usr/bin:/etc
(cat <<!; cat $*) | pr -h "SESSIONS, SORTED BY ENDING TIME"

MAJ/MIN			CONNECT SECONDS	START TIME	SESSION START
DEVICE	UID	LOGIN	PRIME	NPRIME	(NUMERIC)	DATE	TIME


!
{q    JY   @cmd/acct/prdaily.sh #	@(#)prdaily.sh	1.5 of 7/22/83	#
#	"prdaily	prints daily report"
#	"last command executed in runacct"
#	"if given a date mmdd, will print that report"
PATH=/usr/lib/acct:/bin:/usr/bin:/etc

set -- `getopt cl $*`
if [ $? != 0 ]
then
	echo Usage: prdaily [-c] [-l] [mmdd]
	exit 2
fi
for i in $*
do
	case $i in
	-c)	CMDEXCPT=1; shift;;
	-l)	LINEEXCPT=1; shift;;
	--)	shift; break;;
	esac
done
date=`date +%m%d`
_sysname="`uname`"
_nite=/usr/adm/acct/nite
_lib=/usr/lib/acct
_sum=/usr/adm/acct/sum

cd ${_nite}
if [ `expr "$1" : [01][0-9][0-3][0-9]` -eq 4 -a "$1" != "$date" ]; then
	if [ "$CMDEXCPT" = "1" ]
	then
		echo "Cannot print command exception reports except for `date '+%h %d'`"
		exit 5
	fi
	if [ "$LINEEXCPT" = "1" ]
	then
		acctmerg -a < ${_sum}/tacct$1 | awk -f ${_lib}/ptelus.awk
		exit $?
	fi
	cat ${_sum}/rprt$1
	exit 0
fi

if [ "$CMDEXCPT" = 1 ]
then
	acctcms -a -s ${_sum}/daycms | awk -f ${_lib}/ptecms.awk
fi
if [ "$LINEEXCPT" = 1 ]
then
	acctmerg -a < ${_sum}/tacct${date} | awk -f ${_lib}/ptelus.awk
fi
if [ "$CMDEXCPT" = 1 -o "$LINEEXCPT" = 1 ]
then
	exit 0
fi
(cat reboots; echo ""; cat lineuse) | pr -h "DAILY REPORT FOR ${_sysname}"  

prtacct daytacct "DAILY USAGE REPORT FOR ${_sysname}"  
pr -h "DAILY COMMAND SUMMARY" daycms
pr -h "MONTHLY TOTAL COMMAND SUMMARY" cms 
pr -h "LAST LOGIN" -3 ../sum/loginlog  
exit 0
q m   ZY   cmd/acct/prtacct.sh #	@(#)prtacct.sh	1.3 of 8/25/82	#
#	"print daily/summary total accounting (any file in tacct.h format)"
#	"prtacct file [heading]"
PATH=/usr/lib/acct:/bin:/usr/bin:/etc
_filename=${1?"missing filename"}
(cat <<!; acctmerg -t -a <${_filename}; acctmerg -p <${_filename}) | pr -h "$2"
	LOGIN 	   CPU (MINS)	  KCORE-MINS	CONNECT (MINS)	DISK	# OF	# OF	# DISK	FEE
UID	NAME 	 PRIME	NPRIME	PRIME	NPRIME	PRIME	NPRIME	BLOCKS	PROCS	SESS	SAMPLES	
!
q k   XZ   cmd/acct/ptecms.awk #	'@      (#)ptecms.awk	1.1 of 5/18/83'
BEGIN {
	MAXCPU = 20.0		# report if cpu usage greater than this
	MAXKCORE = 1000.0	# report if KCORE usage is greater than this
	}
NF == 4		{
			print "\t\t\t\t" $1 " Time Exception Command Usage Summary"
		}

NF == 3		{
			print "\t\t\t\tCommand Exception Usage Summary"
		}

NR == 1		{
			MAXCPU = MAXCPU + 0.0
			MAXKCORE = MAXKCORE + 0.0
			print "\t\t\t\tTotal CPU > " MAXCPU " or Total KCORE > " MAXKCORE
		}

NF <= 4 && length != 0	{
				next
			}

$1 == "COMMAND" || $1 == "NAME"		{
						print
						next
					}

NF == 10 && ( $4 > MAXCPU || $3 > MAXKCORE ) && $1 != "TOTALS"

NF == 13 && ( $5 + $6 > MAXCPU || $4 > MAXKCORE ) && $1 != "TOTALS"

length == 0


 q    NYg7   cmd/acct/ptelus.awk #	'@(#)ptelus.awk	1.2 of 8/15/83'
BEGIN	{
	MAXCPU = 20.		# report if cpu usage is greater than this
	MAXKCORE = 500.		# report is Kcore usage is greater than this
	MAXCONNECT = 120.	# report if connect time is greater than this
	}
NR == 1	 {
	MAXCPU = MAXCPU + 0
	MAXKCORE = MAXKCORE + 0
	MAXCONNECT = MAXCONNECT + 0
	printf "Logins with exceptional Prime/Non-prime Time Usage\n"
	printf ( "CPU > %d or KCORE > %d or CONNECT > %d\n\n\n", MAXCPU, MAXKCORE, MAXCONNECT)
	printf "\tLogin\t\tCPU (mins)\tKCORE-mins\tCONNECT-mins\tdisk"
	printf "\t# of\t# of\t# Disk\tfee\n"
	printf "UID\tName\t\tPrime\tNprime\tPrime\tNprime\t"
	printf "Prime\tNprime\tBlocks\tProcs\tSess\tSamples\n\n"
	}
$3 > MAXCPU || $4 > MAXCPU || $5 > MAXKCORE || $6 > MAXKCORE || $7 > MAXCONNECT || $8 > MAXCONNECT {
				printf("%d\t%-8.8s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
				}
sq    VZ   cmd/acct/ptmp.h /*	@(#)ptmp.h	1.2 of 3/31/82	*/
/*
 *	per process temporary data
 */
struct ptmp {
	uid_t	pt_uid;			/* userid */
	char	pt_name[8];		/* login name */
	long	pt_cpu[2];		/* CPU (sys+usr) P/NP time tics */
	unsigned pt_mem;		/* avg. memory size (64byte clicks) */
};	
q i   X[   } cmd/acct/remove.sh  #	@(#)remove.sh	1.2 of 3/31/82	#
rm -f /usr/adm/acct/sum/wtmp*
rm -f /usr/adm/acct/sum/pacct*
rm -f /usr/adm/acct/nite/lock*
eq    \\   40cmd/acct/runacct.sh #	@(#)runacct.sh	1.2 of 3/31/82	#
#       "nitely accounting shell, should be run from cron (adm) at 4am"
#	"does process, connect, disk, and fee accounting"
#	"prepares command summaries"
#	"shell is restartable and provides reasonable diagnostics"
_adm=/usr/adm
_nite=/usr/adm/acct/nite
_sum=/usr/adm/acct/sum
_wtmp=/etc/wtmp
export PATH
PATH=/usr/lib/acct:/bin:/usr/bin:/etc
_statefile=${_nite}/statefile
_active=${_nite}/active
_lastdate=${_nite}/lastdate
_errormsg="\n\n************ ACCT ERRORS : see  ${_active}${_date}********\n\n"
_MIN_BLKS=500

cd ${_adm}
#		"make sure that 2 crons weren't started, or leftover problems"
date  > ${_nite}/lock1
chmod 400 ${_nite}/lock1
ln ${_nite}/lock1 ${_nite}/lock
if test $? -ne 0; then
	_lnkerr="\n\n*********** 2 CRONS or ACCT PROBLEMS***********\n\n\n"
	(date ; echo "$_lnkerr" ) >/dev/console
	echo "$_lnkerr" | mail adm root
	echo "ERROR: locks found, run aborted" >> ${_active}
	rm -f ${_nite}/lock*
	exit 1
fi

# Check to see if there is enough space in /usr to do nitely accounting
#
_blocks=`df /usr | sed "s/.*:  *\([0-9][0-9]*\) blocks.*/\1/"`
if [ "$_blocks" -le $_MIN_BLKS ];then
	echo "runacct: Insufficient space in /usr ($_blocks blks); \c"
	echo "Terminating procedure"
	( echo "runacct: Insufficient space in /usr ($_blocks blks); \c"
	echo "Terminating procedure" ) | \
		 tee /dev/console ${_active} | mail root adm
	rm -f ${_nite}/lock*
	exit 1
fi


case $# in
0)
#	"as called by the cron each day"
	_date="`date +%m%d`"
	if test ! -r ${_lastdate} ; then
		echo "0000" > ${_lastdate}
	fi
	if test "${_date}" = "`cat ${_lastdate}`"; then
		(date; echo "${_errormsg}") > /dev/console
		echo "${_errormsg}" | mail root adm
		echo "ERROR: acctg already run for `date`: check ${_lastdate}" >> ${_active}
		rm -f ${_nite}/lock*
		mv ${_active} ${_active}${_date}
		exit 1
	fi
	echo ${_date} > ${_lastdate}
	echo "SETUP" > ${_statefile}
	nulladm ${_active}
	echo "\n\n\n\n\n**********  SYSTEM ACCOUNTING STARTED `date`  **********\n\n\n\n\n" > /dev/console
	;;

1)
#	"runacct MMDD  (date)  will restart at current state"
	_date=$1
	echo "restarting acctg for ${_date} at `cat ${_statefile}`" >> ${_active}
	echo "\n\n\n\n\n********** SYSTEM ACCOUNTING RESTARTED `date` **********\n\n\n\n\n" > /dev/console
	;;

2)
#	"runacct MMDD STATE  restart at specified state"
	_date=$1
	echo "restarting acctg for ${_date} at $2" >> ${_active}
	echo "previous state was `cat ${_statefile}`" >> ${_active}
	echo "$2" > ${_statefile}
	echo "\n\n\n\n\n********** SYSTEM ACCOUNTING RESTARTED `date` **********\n\n\n\n\n" > /dev/console
	;;
*)
	(date; echo "${_errormsg}") > /dev/console
	echo "${_errormsg}" | mail root adm
	echo "ERROR: runacct called with invalid arguments" > ${_active}
	rm -f ${_nite}/lock*
	mv ${_active} ${_active}${_date}
	exit 1
	;;
esac


#	"processing is broken down into seperate, restartable states"
#	"the statefile is updated at the end of each state so       that the"
#	"next loop through the while statement switches to the next state"
while [ 1 ]
do
case "`cat ${_statefile}`" in
SETUP)

cd ${_adm}
(date ; ls -l fee pacct* ${_wtmp}* ) >> ${_active}

#	"switch current pacct file"
turnacct switch
_rc=$?
if test ${_rc} -ne 0; then
	(date ; echo "${_errormsg}" ) > /dev/console
	echo "${_errormsg}" | mail root adm
	echo "ERROR: turnacct switch returned rc=${_rc}" >> ${_active}
	rm -f ${_nite}/lock*
	mv ${_active} ${_active}${_date}
	exit 1
fi

#	" give pacct files unique names for easy restart "
for _i in pacct?*
do
	if test -r S${_i}.${_date} ; then
		 (date ; echo "${_errormsg}" ) > /dev/console
		echo "${_errormsg}" | mail root adm
		echo "ERROR: S${_i}.${_date} already exists" >> ${_active}
		echo "file setups probably already run" >> ${_active}
		rm -f ${_nite}/lock*
		mv ${_active} ${_active}${_date}
		exit 1
	fi
	mv ${_i} S${_i}.${_date}
done


#	"add current time on end"
if test -r ${_nite}/wtmp.${_date} ; then
	(date ; echo "${_errormsg}" ) > /dev/console
	echo "${_errormsg}" | mail root adm
	echo "ERROR: ${_nite}/wtmp.${_date} already exists: run setup manually" > ${_active}
	rm -f ${_nite}/lock*
	mv ${_active} ${_active}${_date}
	exit 1
fi
cp ${_wtmp} ${_nite}/wtmp.${_date}
acctwtmp "runacct" >> ${_nite}/wtmp.${_date}
nulladm ${_wtmp}


echo "files setups complete" >> ${_active}
echo "WTMPFIX" > ${_statefile}
;;


WTMPFIX)
#	"verify the integrity of the wtmp file"
#	"wtmpfix will automatically fix date changes"
cd ${_nite}
nulladm tmpwtmp wtmperror
wtmpfix < wtmp.${_date} > tmpwtmp 2>wtmperror
if test $? -ne 0 ; then
	(date ; echo "${_errormsg}") | mail root adm
	echo "${_errormsg}" > /dev/console
	echo "ERROR: wtmpfix errors see ${_nite}/wtmperror${_date}" >> ${_active}
	rm -f ${_nite}/lock*
	mv ${_active} ${_active}${_date}
	mv wtmperror wtmperror${_date}
	exit 1
fi

echo "wtmp processing complete" >> ${_active}
echo "CONNECT1" > ${_statefile}
;;


CONNECT1)
#	"produce connect records in the ctmp.h format"
#	"the lineuse and reboots files are used by prdaily"
cd ${_nite}
nulladm lineuse reboots ctmp log
acctcon1 -t -l lineuse -o reboots < tmpwtmp  2> log |\
sort +1n +2 > ctmp 

# if the following test is true, then pnpsplit complained about
# the year and holidays not being up to date.  This used to be
# a fatal error, but now it will continue to process the accounting.
# 
if test -s log ; then 
	(date ; cat ${_nite}/log) | mail adm root
	echo "${_errormsg}" > /dev/console
	cat ${_nite}/log >> ${_active}${_date}
fi

echo "CONNECT2" > ${_statefile}
;;


CONNECT2)
#	"convert ctmp.h records in tacct records"
cd ${_nite}
nulladm ctacct.${_date}
acctcon2 < ctmp | acctmerg > ctacct.${_date}

echo "connect acctg complete" >> ${_active}
echo "PROCESS" > ${_statefile}
;;


PROCESS)
#	"correlate Spacct and ptacct files by number"
#	"will not process Spacct file if corresponding ptacct exists"
#	"remove the ptacct file to rurun the Spacct file"
#	"if death occurs here, rerunacct should remove last ptacct file"

cd ${_nite}
for _Spacct in ${_adm}/Spacct*.${_date}
do
	_ptacct=`basename ${_Spacct} | sed 's/Sp/pt/'`
	if test -s ${_ptacct}; then
		echo "WARNING: accounting already run for ${_Spacct}" \
			>> ${_active}
		echo "WARNING: remove ${_nite}/${_ptacct} to rerun" \
			>> ${_active}
	else
		nulladm ${_ptacct}
                acctprc1 ctmp < ${_Spacct} |\
			acctprc2 > ${_ptacct}
		echo "process acctg complete for ${_Spacct}" >> ${_active}
	fi
done
echo "all process actg complete for ${_date}" >> ${_active}
echo "MERGE" > ${_statefile}
;;


MERGE)
cd ${_nite}
#	"merge ctacct and ptacct files together"
acctmerg ptacct*.${_date} < ctacct.${_date} > daytacct

echo "tacct merge to create daytacct complete" >> ${_active}
echo "FEES" > ${_statefile}
;;


FEES)
cd ${_nite}
#	"merge in fees"
if test -s ${_adm}/fee; then
	cp daytacct tmpdayt
	sort +0n +2 ${_adm}/fee | acctmerg -i | acctmerg tmpdayt  > daytacct
	echo "merged fees" >> ${_active}
	rm -f tmpdayt
else
	echo "no fees" >> ${_active}
fi
echo "DISK" > ${_statefile}
;;


DISK)
cd ${_nite}
#	"the last act of any disk acct procedure should be to mv its"
#	"entire output file to disktacct, where it will be picked up"
if test -r disktacct; then
	cp daytacct tmpdayt
	acctmerg disktacct  < tmpdayt > daytacct
	echo "merged disk records" >> ${_active}
	rm -f tmpdayt disktacct
else
	echo "no disk records" >> ${_active}
fi
echo "MERGETACCT" > ${_statefile}
;;

MERGETACCT)
cd ${_adm}/acct
#	"save each days tacct file in sum/tacct.${_date}"
#	"if sum/tacct gets corrupted or lost, could recreate easily"
#	"the mounthly acctg procedure should remove all sum/tacct files"
cp nite/daytacct sum/tacct${_date}
if test ! -r sum/tacct; then
	echo "WARNING: recreating ${_adm}/sum/tacct " >> ${_active}
	nulladm sum/tacct
fi

#	"merge in todays tacct with the summary tacct"
cp sum/tacct sum/tacctprev
acctmerg sum/tacctprev  < sum/tacct${_date} > sum/tacct

echo "updated sum/tacct" >> ${_active}
echo "CMS" > ${_statefile}
;;


CMS)
cd ${_adm}/acct
#	"do command summaries"
nulladm sum/daycms
if test ! -r sum/cms; then
	nulladm sum/cms
	echo "WARNING: recrea      ting ${_adm}/sum/cms " >> ${_active}
fi
cp sum/cms sum/cmsprev
acctcms ${_adm}/Spacct*.${_date}  > sum/daycms
acctcms -s sum/daycms sum/cmsprev  > sum/cms
acctcms -a -s sum/daycms | sed -n 1,56p  > nite/daycms
acctcms -a -s sum/cms | sed -n 1,56p  > nite/cms
lastlogin 
echo "command summaries complete" >> ${_active}
echo "USEREXIT" > ${_statefile}
;;


USEREXIT)
#	"any installation dependant accounting programs should be run here"


echo "CLEANUP" > ${_statefile}
;;


CLEANUP)
cd ${_adm}/acct
#	" finally clear files; could be done next morning if desired"
nulladm ${_adm}/fee
rm -f ${_adm}/Spacct*.${_date}
#	"put reports onto a file"
prdaily >> sum/rprt${_date};
rm -f nite/lock*
rm -f nite/ptacct*.${_date} nite/ctacct.${_date}
rm -f nite/wtmp.${_date} nite/wtmperror${_date} nite/active${_date}
mv nite/tmpwtmp nite/owtmp
echo "system accounting completed at `date`" >> ${_active}
echo "********** SYSTEM ACCOUNTING COMPLETED `date` **********" > /dev/console
echo "COMPLETE" > ${_statefile}
exit 0
;;

*)
	(date;echo "${_errormsg}") > /dev/console
	echo "${_errormsg}" | mail adm root
	echo "ERROR: invalid state, check ${_statefile}" >> active
	rm -f ${_nite}/lock*
	mv ${_active} ${_active}${_date}
	exit 1
	;;
esac
done


#	" runacct is normally called with no arguments from the cron"
#	" it checks its own locks to make sure that 2 crons or previous"
#	" problems have not occured"

#	" runacct uses the statefile to record its progress"
#	" each state updates the statefile upon completion"
#	" then the next loop though the while picks up the new state"

#	" to restart this shell,  check the active file for diagnostics"
#	" fix up any corrupted data (ie. bad pacct or wtmp files)"
#	" if runacct detected the error it removes the locks"
#	" remove the locks if necessary, otherwise runacct will complain"
#	" the lastdate file should be removed or changed"
#	" restart runacct at current state with:  runacct MMDD"
#	" to override the statefile: runacct MMDD STATE"


#	" if runacct has been executed after the latest failure"
#	" ie. it ran ok today but failed yesterday"
#	" the statefile will not be correct"
#	" check the active files and restart properly"

#	" if runacct failed in the PROCESS state, remove the last"
#	" ptacct file because it may not be complete"

#	" if shell has failed several days, do SETUP manually"
#	" then rerun runacct once for each day failed"
#	" could use fwtmp here to split up wtmp file correctly"

#	" normally not a good idea to restart the SETUP state"
#	" should be done manually, or just cleanup first"


#	" FILE USAGE:	all files in /usr/adm/ac/nite unless specified"

#	" statefile	records progess of runacct"
#	" lastdate	last day runacct ran in date +%m%d format"
#	" lock lock1	controls serial use of runacct"
#	" active	place for all descriptive and error messages"
#	" fd2log	fd2 output for runacct ( see cron entry ) "
#	" wtmp.MMDD owtmp yesterdays wtmp file"
#	" tmpwtmp	yesterdays wtmp corrected by wtmpfix"
#	" wtmperror	place for wtmpfix error messages"
#	" lineuse	lineusage report used in prdaily"
#	" reboots	reboots report used in prdaily"
#	" ctmp	ctmp.h records from acctcon1"
#	" log		place for error messages from acctcon1"
#	" ctacct.MMDD	connect tacct records for MMDD"
#	" ptacct.n.MMDD	process tacct records n files for MMDD"
#	" daytacct	total tacct records for this days accounting"
#	" disktacct	disk tacct records produced by disk shell"
#	" daycms	ascii daily command summary used by prdaily"
#	" cms		acsii total command summary used by prdaily"

#	" following files in /usr/adm directory"

#	" fee		output from chargefee program"
#	" pacct		active pacct file"
#	" pacctn	switched pacct files"
#	" Spacctn.MMDD	pacct files for MMDD after SETUP state"
#	" wtmp		active wtmp file"

#	" following files in /usr/adm/acct/sum"

#	" loginlog	output of lastlogin used in prdaily"
#	" tacct		total tacct file for current fiscal"
#	" tacct.MMDD	tacct file for day MMDD"
#	" cms		total cms file for current fiscal"
#	" rprt.MMDD	output of prdaily program"
#	" wtmp.MMDD	saved copy of wtmp for MMDD"
#	" pacct.MMDD	concatenated version of all pacct files for MMDD"
#	" cmsprev	total cms file without latest update"
#	" tacctprev	total tacct file without latest update"
#	" daycms	cms files for todays usage"
q d   e]   4cmd/acct/shutacct.sh .#	@(#)shutacct.sh	1.2 of 3/31/82	#
#	"shutacct [arg] - shuts down acct, called from /etc/shutdown"
#	"whenever system taken down"
#	"arg	added to /etc/wtmp to record reason, defaults to shutdown"
PATH=/usr/lib/acct:/bin:/usr/bin:/etc
_reason=${1-"acctg off"}
acctwtmp  "${_reason}"  >>/etc/wtmp
turnacct off
q a   k]    cmd/acct/startup.sh #	@(#)startup.sh	1.2 of 3/31/82	#
#	"startup (acct) - should be called from /etc/rc"
#	"whenever system is brought up"
PATH=/usr/lib/acct:/bin:/usr/bin:/etc
acctwtmp "acctg on" >>/etc/wtmp
turnacct on
#	"clean up yesterdays accounting files"
remove
cq `   $Y^   ?cmd/acct/tacct.h s/*	@(#)tacct.h	1.2 of 3/31/82	*/
/*
 *	total accounting (for acct period), also for day
 */

struct	tacct	{
	uid_t		ta_uid;		/* userid       */
	char		ta_name[8];	/* login name */
	float		ta_cpu[2];	/* cum. cpu time, p/np (mins) */
	float		ta_kcore[2];	/* cum kcore-minutes, p/np */
	float		ta_con[2];	/* cum. connect time, p/np, mins */
	float		ta_du;		/* cum. disk usage */
	long		ta_pc;		/* count of processes */
	unsigned short	ta_sc;		/* count of login sessions */
	unsigned short	ta_dc;		/* count of disk samples */
	unsigned short	ta_fee;		/* fee for special services */
};
tq    Y^   cmd/acct/turnacct.sh .#	@(#)turnacct.sh	1.2 of 3/31/82	#
#	"control process accounting (must be root)"
#	"turnacct on	makes sure it's on"
#	"turnacct off	turns it off"
#	"turnacct switch	switches pacct to pacct?, starts fresh one"
#	"/usr/adm/pacct is always the current pacct file"
PATH=/usr/lib/acct:/bin:/usr/bin:/etc
cd /usr/adm
case "$1"  in
on)
	if test ! -r pacct
	then
		nulladm pacct
	fi
	accton pacct
	rc=$?
	;;
off)
	accton
	rc=$?
	;;
switch)
	if test -r pacct
	then
		_i=1
		while test -r pacct${_i}
		do
			_i="`expr ${_i} + 1`"
		done
		mv pacct pacct${_i}
	fi
	nulladm pacct
	accton
	accton pacct
	_rc=$?
	if test ${_rc} -ne 0; then
		echo "accton failed"
		rm pacct
		mv pacct${_i} pacct
		exit ${_rc}
	fi
	;;
*)
	echo "Usage: turnacct on|off|switch"
	_rc=1
	;;
esac
exit ${_rc}
Cq \   	Y_   	cmd/acct/wtmpfix.c h/*	@(#)wtmpfix.c	1.2 of 3/31/82	*/
#

/*
 * wtmpfix - adjust wtmp file and remove date changes.
 *
 *	wtmpfix <wtmp1 >wtmp2
 *
 */

# include <stdio.h>
# include <ctype.h>
# include <sys/types.h>
# include <utmp.h>
# include "acctdef.h"
# include <signal.h>

FILE	*Wtmp, *Opw;

char	*Ofile	={ "/tmp/wXXXXXX" };

struct	dtab
{
	long	d_off1;		/* file offset start */
	long	d_off2;		/* file offset stop */
	long	d_adj;		/* time adjustment */
	struct dtab *d_ndp;	/* next record */
};

struct	dtab	*Fdp;		/* list header */
struct	dtab	*Ldp;		/* list trailer */


long	ftell();
struct	utmp	wrec, wrec2;

intr()
{

	signal(SIGINT,SIG_IGN);
	unlink(Ofile);
	exit(1);
}

main(argc, argv)
char	**argv;
{

	static long	recno = 0;
	register struct dtab *dp;

	if(argc < 2){
		argv[argc] = "-";
		argc++;
	}

	if((int)signal(SIGINT,intr) == -1) {
		perror("signal");
		exit(1);
	}

	mktemp(Ofile);
	if((Opw=fopen(Ofile,"w"))==NULL)
		err("cannot make temporary: %s", Ofile);

	while(--argc > 0){
		argv++;
		if(strcmp(*argv,"-")==0)
			Wtmp = stdin;
		else if((Wtmp = fopen(*argv,"r"))==NULL)
			err("Cannot open: %s", *argv);
		while(winp(Wtmp,&wrec)){
			if(recno == 0 || wrec.ut_type==BOOT_TIME){
				mkdtab(recno,&wrec);
			}
			if(invalid(wrec.ut_name)) {
				fprintf(stderr,
					"wtmpfix: logname \"%8.8s\" changed to \"INVALID\"\n",
					wrec.ut_name);
				strncpy(wrec.ut_name, "INVALID", NSZ);
			}
			if(wrec.ut_type==OLD_TIME){
				if(!winp(Wtmp,&wrec2))
					err("Input truncated at offset %ld",recno);
				if(wrec2.ut_type!=NEW_TIME)
					err("New date expected at offset %ld",recno);
				setdtab(recno,&wrec,&wrec2);
				recno += (2 * sizeof(struct utmp));
				wout(Opw,&wrec);
				wout(Opw,&wrec2);
				continue;
			}
			wout(Opw,&wrec);
			recno += sizeof(struct utmp);
		}
		if(Wtmp!=stdin)
			fclose(Wtmp);
	}
	fclose(Opw);
	if((Opw=fopen(Ofile,"r"))==NULL)
		err("Cannot read from temp: %s", Ofile);
	recno = 0;
	while(winp(Opw,&wrec)){
		adjust(recno,&wrec);
		recno += sizeof(struct utmp);
/*		if(wrec.ut_type==OLD_TIME || wrec.ut_type==NEW_TIME)
			continue;	*/
		wout(stdout,&wrec);
	}
	fclose(Opw);
	unlink(Ofile);
	exit(0);
}

/*	err() writes an error message to the standard error and then
 *	calls the interrupt routine to clean up the temporary file
 *	and exit.  The variable "f" is the format specification that
 *	can contain up to 3 arguments (m1, m2, m3).
 */
err(f,m1,m2,m3)
{

	fprintf(stderr,f,m1,m2,m3);
	fprintf(stderr,"\n");
	intr();
}

/*	winp() reads a record from a utmp.h-type file pointed to
 *	by the stream pointer "f" into the structure whose address
 *	is given by the variable "w".
 *	This reading takes place in two stages: first the raw
 *	records from the utmp.h files are read in (usually /etc/wtmp)
 *	and written into the temporary file (Opw); then the records
 *	are read from the temporary file and placed on the standard 
 *	output.
 */
winp(f,w)
register FILE *f;
register struct utmp *w;
{

	if(fread(w,sizeof(struct utmp),1,f)!=1)
		return 0;
	if((w->ut_type >= EMPTY) && (w->ut_type <= UTMAXTYPE))
		return ((unsigned)w);
	else {
		fprintf(stderr,"Bad file at offset %ld\n",
			ftell(f)-sizeof(struct utmp));
		fprintf(stderr,"%-12s %-8s %lu %s",
			w->ut_line,w->ut_user,w->ut_time,ctime(&w->ut_time));
		intr();
	}
}

/*	wout() writes an output record of type utmp.h.  The
 *	variable "f" is a file descripter of either the temp
 *	file or the standard output.  The variable "w" is an
 *	address of the entry in the utmp.h structure.
 */
wout(f,w)
{

	fwrite(w,sizeof(struct utmp),1,f);
}

mkdtab(p,w)
long	p;
register struct utmp *w;
{

	register struct dtab *dp;

	dp = Ldp;
	if(dp == NULL){
		dp = (struct dtab *)calloc(sizeof(struct dtab),1);
		if(dp == NULL)
			err("out of core");
		Fdp = Ldp = dp;
	}
	dp->d_off1 = p;
}

setdtab(p,w1,w2)
long	p;
regi      ster struct utmp *w1, *w2;
{

	register struct dtab *dp;

	if((dp=Ldp)==NULL)
		err("no dtab");
	dp->d_off2 = p;
	dp->d_adj = w2->ut_time - w1->ut_time;
	if((Ldp=(struct dtab *)calloc(sizeof(struct dtab),1))==NULL)
		err("out of core");
	Ldp->d_off1 = dp->d_off1;
	dp->d_ndp = Ldp;
}

adjust(p,w)
long	p;
register struct utmp *w;
{

	long pp;
	register struct dtab *dp;

	pp = p;

	for(dp=Fdp;dp!=NULL;dp=dp->d_ndp){
		if(dp->d_adj==0)
			continue;
		if(pp>=dp->d_off1 && pp < dp->d_off2)
			w->ut_time += dp->d_adj;
	}
}

/*
 *	invalid() determines whether the name field adheres to
 *	the criteria set forth in acctcon1.  If the name violates
 *	conventions, it returns a truth value meaning the name is
 *	invalid; if the name is okay, it returns false indicating
 *	the name is not invalid.
 */
#define	VALID	0
#define	INVALID	1

invalid(name)
char	*name;
{
	register int	i;

	for(i=0; i<NSZ; i++) {
		if(name[i] == '\0')
			return(VALID);
		if( ! (isalnum(name[i]) || (name[i] == '$')
			|| (name[i] == ' ') )) {
			return(INVALID);
		}
	}
	return(VALID);
}
 q WA        cmd/adb q    ~   Tcmd/adb/adb.mk x#	@(#)adb.mk	1.2
ROOT=
PFX=
TESTDIR = .
FRC =
INSDIR =
CFLAGS = -O
LDFLAGS=
IFLAG = -i

all:
	-if vax ;\
	then cd vax; make -f adb.mk CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" TESTDIR=$(TESTDIR) ; \
	elif ns32000 ;\
	then cd ns32000; make -f adb.mk CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" TESTDIR=$(TESTDIR) PFX="$(PFX)" ROOT="$(ROOT)"; \
	else cd pdp11; make -f adb.mk FFLAG="$(FFLAG)" IFLAG="$(IFLAG)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" TESTDIR=$(TESTDIR) ; fi
install:
	-if vax ;\
	then cd vax; make -f adb.mk CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" TESTDIR=$(TESTDIR) install; \
	elif ns32000 ;\
	then cd ns32000; make -f adb.mk CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" TESTDIR=$(TESTDIR) PFX="$(PFX)" ROOT="$(ROOT)" install; \
	else cd pdp11; make -f adb.mk FFLAG="$(FFLAG)" IFLAG="$(IFLAG)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" TESTDIR=$(TESTDIR) install; fi
clean:
	-if vax ; then cd vax; make -f adb.mk clean TESTDIR=$(TESTDIR);\
	elif ns32000 ; then cd ns32000; make -f adb.mk clean TESTDIR=$(TESTDIR);\
	else cd pdp11; make -f adb.mk FFLAG="$(FFLAG)" IFLAG="$(IFLAG)" clean TESTDIR=$(TESTDIR); fi
clobber:
	-if vax ; then cd vax; make -f adb.mk clobber TESTDIR=$(TESTDIR); \
	elif ns32000 ; then cd ns32000; make -f adb.mk clobber TESTDIR=$(TESTDIR); \
	else cd pdp11; make -f adb.mk FFLAG="$(FFLAG)" IFLAG="$(IFLAG)" clobber TESTDIR=$(TESTDIR); fi
q A   e%     cmd/adb/vax q K   T'(   @cmd/adb/vax/a.out.h /*	@(#)a.out.h	1.2	*/
/*
 * Format of an a.out header
 */
 
#ifndef u3b

struct	exec {	/* a.out header */
#if u370
	int		a_magic;	/* magic number */
	int		a_stamp;	/* The version of a.out	*/
					/* format of this file.	*/
#else
	short		a_magic;	/* magic number */
#endif
#if vax
	short		a_stamp;
#endif
	unsigned	a_text;		/* size of text segment */
					/* in bytes		*/
					/* padded out to next	*/
					/* page boundary with	*/
					/* binary zeros.	*/
	unsigned	a_data;		/* size of initialized data */
					/* segment in bytes	*/
					/* padded out to next	*/
					/* page boundary with	*/
					/* binary zeros.	*/
	unsigned	a_bss;		/* Actual size of	*/
					/* uninitialized data	*/
					/* segment in bytes.	*/
	unsigned	a_entry;	/* entry point */
#if vax || u370
	unsigned	a_trsize;	/* size of text relocation */
	unsigned	a_drsize;	/* size of data relocation */
#endif
#if u370
	unsigned	a_origin;	/* The origin to which 	*/
					/* this file was	*/
					/* relocated.		*/
	unsigned	a_actext;	/* The actual size of	*/
					/* the text segment in	*/
					/* bytes.		*/
	unsigned	a_acdata;	/* The actual size of	*/
					/* the data segment in	*/
					/* bytes.		*/
#endif
#if pdp11
	char		a_unused;	/* not used */
	unsigned char	a_hitext;	/* high order text bits */
	char		a_flag;		/* reloc info stripped */
	char		a_stamp;	/* environment stamp */
#endif
};

#define	A_MAGIC1	0407		/* normal */
#define	A_MAGIC0	0401		/* lpd (UNIX/RT) */
#define	A_MAGIC2	0410		/* read-only text */
#define	A_MAGIC3	0411		/* separated I&D */
#define	A_MAGIC4	0405		/* overlay */
#define	A_MAGIC5	0437		/* system overlay, separated I&D */

#if vax || u370
struct relocation_info {
	  long  r_address;	/* relative to current segment */
	  unsigned int
		r_symbolnum:24,	/* if extern then symbol table */
				/* ordinal (0, 1, 2, ...) else */
				/* segment number (same as symbol types) */
	        r_pcrel:1, 	/* if so, segment offset has already */
				/* been subtracted */
	  	r_length:2,	/* 0=byte, 1=word, 2=long */
	  	r_extern:1,	/* does not include value */
				/* of symbol referenced */
	  	r_offset:1,	/* already includes origin */
				/* of this segment (?) */
		r_pad:3;	/* nothing, yet */
};
#endif
struct nlist
{
	char		*n_name;
	unsigned long	n_value;
	short		n_scnum;
	unsigned short	n_type;
	char		n_sclass;
	char		n_numaux;
};
/* in invocation of BADMAG macro, argument should not be a function. */

#define	BADMAG(X) (X.a_magic != A_MAGIC1 &&\
		X.a_magic != A_MAGIC2 &&\
		X.a_magic != A_MAGIC3 &&\
		X.a_magic != A_MAGIC4       &&\
		X.a_magic != A_MAGIC5 &&\
		X.a_magic != A_MAGIC0)

	/* values for type flag */

#define	N_UNDF	0	/* undefined */
#define	N_TYPE	037
#define	N_FN	037	/* file name symbol */

#if pdp11
#define	N_TEXT	02	/* text symbol */
#define	N_DATA	03	/* data symbol */
#define	N_BSS	04	/* bss symbol */
#define	N_REG	024	/* register name */
#define	N_EXT	040	/* external bit, or'ed in */
#define	FORMAT	"%.6o"	/* to print a value */
#else
/* by cfb 21 Aug 82 */
#define SECT1 1
#define SECT2 2
#define SECT3 3
/* end of cfb stuff */
#define	N_TEXT	04	/* text */
#define	N_DATA	06	/* data */
#define	N_BSS	010
#define	N_GSYM	0040	/* global sym: name,,type,0 */
#define	N_FNAME 0042	/* procedure name (f77 kludge): name,,,0 */
#define	N_FUN	0044	/* procedure: name,,linenumber,address */
#define	N_STSYM 0046	/* static symbol: name,,type,address */
#define	N_LCSYM 0050	/* .lcomm symbol: name,,type,address */
#define	N_BSTR	0060	/* begin structure: name,,, */
#define	N_RSYM	0100	/* register sym: name,,register,offset */
#define	N_SLINE	0104	/* src line: ,,linenumber,address */
#define	N_ESTR	0120	/* end structure: name,,, */
#define	N_SSYM	0140	/* structure elt: name,,type,struct_offset */
#define	N_SO	0144	/* source file name: name,,,address */
#define	N_BENUM	0160	/* begin enum: name,,, */
#define	N_LSYM	0200	/* local sym: name,,type,offset */
#define	N_SOL	0204	/* #line source filename: name,,,address */
#define	N_ENUM	0220	/* enum element: name,,,value */
#define	N_PSYM	0240	/* parameter: name,,type,offset */
#define	N_ENTRY	0244	/* alternate entry: name,,linenumber,address */
#define	N_EENUM	0260	/* end enum: name,,, */
#define	N_LBRAC	0300	/* left bracket: ,,nesting level,address */
#define	N_RBRAC	0340	/* right bracket: ,,nesting level,address */
#define	N_BCOMM	0342	/* begin common: name,,, */
#define	N_ECOMM	0344	/* end common: name,,, */
#define	N_ECOML	0350	/* end common (local name): ,,,address */
#define	N_STRU	0374	/* 2nd entry for structure: str tag,,,length */
#define	N_LENG	0376	/* second stab entry with length information */
#define	N_EXT	01	/* external bit, or'ed in */
#define	FORMAT	"%.8x"
#define	STABTYPES 0340
#endif

#else

/* static char ID_filhdrh[] = "@(#) filehdr.h: 4.1.1.12 8/27/80"; */
/*
 *	Format of a 3B a.out header
 */

struct filehdr {
	unsigned short	f_magic;	/* magic number */
	unsigned short	f_nscns;	/* number of sections */
	long		f_timdat;	/* time & date stamp */
	long		f_symptr;	/* file pointer to symtab */
	long		f_nsyms;	/* number of symtab entries */
	unsigned short	f_opthdr;	/* sizeof(optional hdr) */
	unsigned short	f_flags;	/* flags */
	};


/*
 *   Bits for f_flags:
 *
 *	F_RELFLG	relocation info stripped from file
 *	F_EXEC		file is executable  (i.e. no unresolved
 *				externel references)
 *	F_LNNO		line nunbers stripped from file
 *	F_LSYMS		local symbols stripped from file
 *	F_MINMAL	this is a minimal object file (".m") output of fextract
 *	F_UPDATE	this is a fully bound update file, output of ogen
 *	F_SWABD		this file has had its bytes swabbed (in names)
 *	F_AR16WR	this file created on AR16WR machine(e.g. 11/70)
 *	F_AR32WR	this file created on AR32WR machine(e.g. vax)
 *	F_AR32W		this file created on AR32W machine (e.g. 3b,maxi)
 *	F_PATCH		file contains "patch" list in optional header
 */

#define  F_RELFLG	0000001
#define  F_EXEC		0000002
#define  F_LNNO		0000004
#define  F_LSYMS	0000010
#define  F_MINMAL	0000020
#define  F_UPDATE	0000040
#define  F_SWABD	0000100
#define  F_AR16WR	0000200
#define  F_AR32WR	0000400
#define  F_AR32W	0001000
#define  F_PATCH	0002000

/*
 *   Magic Numbers
 */

#define  N3BMAGIC	0550

#define	FILHDR	struct filehdr
#define	FILHSZ	sizeof(FILHDR)

/* static char ID_scnhdrh[] = "@(#) scnhdr.h: 4.1.1.9 8/22/80"; */

/*
 *	Format of a 3B a.out section header
 */

struct scnhdr {
	char		s_name[8];	/* section name */
	long		s_paddr;	/* physical address */
	long		s_vaddr;	/* virtual address */
	long		s_size;		/* section size */
	long		s_scnptr;	/* file ptr to raw data for section */
	long		s_relptr;	/* file ptr to relocation */
	long		s_lnnoptr;	/* file ptr to line numbers */
	unsigned short	s_nreloc;	/* number of relocation entries */
	unsigned short	s_nlnno;	/* number of line number entries */
	long		s_flags;	/* flags */
	};

#define	SCNHDR	struct scnhdr
#define	SCNHSZ	sizeof(SCNHDR)

/*
 * Define constants for names of "special" sections
 */

#define _TEXT ".text"
#define _DATA ".data"
#define _BSS  ".bss"

/*
 * The low 4 bits of s_flags is used as a section "type"
 */

#define STYP_REG	0x00		/* "regular" section:
						allocated, relocated, loaded */
#define STYP_DSECT	0x01		/* "dummy" section:
						not allocated, relocated,
						not loaded */
#define STYP_NOLOAD	0x02		/* "noload" section:
						allocated, relocated,
						 not loaded */
#define STYP_GROUP	0x04		/* "grouped" section:
						formed of input sections */
#define STYP_PAD	0x08		/* "padding" section:
						not allocated, not relocated,
						 loaded */

/*
 * static char ID_aouth[] = "@(#) aouthdr.h: 4.1.1.2 8/22/80";
 * static char ID_sgsh[] = "@(#) sgs.h: 2.1.1.9 8/22/80";
 */

/*
 *	Format of the       UNIX (optional) header
 */

/*	The symbol N3BMAGIC is defined in filehdr.h	*/

#define MAGIC	N3BMAGIC
#define TVMAGIC (MAGIC+1)

#define ISMAGIC(x)	((((unsigned short)x)==(unsigned short)MAGIC)||(((unsigned short)x)==(unsigned short)TVMAGIC))

/* Must include ar.h so that ARMAG is defined for ISARCHIVE and BADMAGIC */
#include	<ar.h>

#define	ISARCHIVE(x)	((unsigned short) x == (unsigned short) ARMAG)
#define BADMAGIC(x)	((((x) >> 8) < 7) && !ISMAGIC(x) && !ISARCHIVE(x))

/*
 *	When a UNIX aout header is to be built in the optional header,
 *	the following magic numbers can appear in that header:
 *
 *		AOUT1MAGIC : default : one output segment is generated
 *		AOUT2MAGIC :	      : two segments are generated
 *						(separate I and D space )
 */

#define AOUT1MAGIC 0407
#define AOUT2MAGIC 0410

typedef	struct aouthdr {
	short	magic;		/* see magic.h				*/
	short	flags;		/* see below				*/
	long	tsize;		/* text size in bytes, padded to FW
				   bdry					*/
	long	dsize;		/* initialized data "  "		*/
	long	bsize;		/* uninitialized data "   "		*/
	long	nsize;		/* nsyms table size in bytes		*/
	long	ssize;		/* ssyms table size in bytes		*/
	long	entry;		/* entry pt.				*/
	long	text_start;	/* base of text used for this file	*/
	long	data_start;	/* base of data used for this file	*/
} AOUTHDR;


/*
 *	Bits for a.out header flags word
 */

/* set if reloc info stripped from file					*/
#define	RELFLG		01
/* set if user specified base of text (default 0)			*/
#define	SETTEXT		02
/* set if user specified base of data (def next seg after text)		*/
#define	SETDATA		04
/* set if nsyms not given						*/
#define	NSYMFLG		010

/* static char ID_reloch[] = "@(#) reloc.h: 4.1.1.14 8/22/80"; */

/*
 *	Format of a 3B relocation entry
 */

struct reloc {
	long	r_vaddr;	/* (virtual) address of reference */
	long	r_symndx;	/* index into symbol table */
	unsigned short	r_type;		/* relocation type */
	};


/*
 *	relocation types
 *
 *	reloc. already performed to symbol in the same section
 *	24-bit direct reference
 *	24-bit "relative" reference
 *	16-bit optimized "indirect" TV reference
 *	24-bit "indirect" TV reference
 *	32-bit "indirect" TV reference
 *	32-bit direct reference
 */

#define  R_ABS		0
#define  R_DIR24	04
#define  R_REL24	05
#define  R_OPT16	014
#define  R_IND24	015
#define  R_IND32	016
#define  R_DIR32	06

#define	RELOC	struct reloc
#define	RELSZ	10	/* sizeof(RELOC) */

/* static char ID_lnumh[] = "@(#) linenum.h: 4.1.1.5 8/22/80"; */

/*
 *	Format of a 3B line number entry
 *
 *  There is one line number entry for every 
 *  "breakpointable" source line in a section.
 *  Line numbers are grouped on a per function
 *  basis; the first entry in a function grouping
 *  will have l_lnno = 0 and in place of physical
 *  address will be the symbol table index of
 *  the function name.
 */

struct lineno
{
	union
	{
		long	l_symndx ;	/* sym. table index of function name
						iff l_lnno == 0      */
		long	l_paddr ;	/* (physical) address of line number */
	}		l_addr ;
	unsigned short	l_lnno ;	/* line number */
} ;

#define	LINENO	struct lineno
#define	LINESZ	6	/* sizeof(LINENO) */

/*
 *   STORAGE CLASSES
 */

#define  C_EFCN          -1    /* physical end of function */
#define  C_NULL          0
#define  C_AUTO          1     /* automatic variable */
#define  C_EXT           2     /* external symbol */
#define  C_STAT          3     /* static */
#define  C_REG           4     /* register variable */
#define  C_EXTDEF        5     /* external definition */
#define  C_LABEL         6     /* label */
#define  C_ULABEL        7     /* undefined label */
#define  C_MOS           8     /* member of structure */
#define  C_ARG           9     /* function argument */
#define  C_STRTAG        10    /* structure tag */
#define  C_MOU           11    /* member of union */
#define  C_UNTAG         12    /* union tag */
#define  C_TPDEF         13    /* type definition */
#define C_USTATIC	 14    /* undefined static */
#define  C_ENTAG         15    /* enumeration tag */
#define  C_MOE           16    /* member of enumeration */
#define  C_REGPARM	 17    /* register parameter */
#define  C_FIELD         18    /* bit field */
#define  C_BLOCK         100   /* ".bb" or ".eb" */
#define  C_FCN           101   /* ".bf" or ".ef" */
#define  C_EOS           102   /* end of structure */
#define  C_FILE          103   /* file name */

#define  C_ALIAS	 105   /* duplicate tag */

/*		Number of characters in a symbol name */
#define  SYMNMLEN	8
/*		Number of characters in a file name */
#define  FILNMLEN	14
/*		Number of array dimensions in auxiliary entry */
#define  DIMNUM		4

struct syment
{
	union
	{
		char	*n_name;
		struct
		{
			long	_n_zeroes;
			long	_n_offset;
		} _n_n;
		char	*_n_nptr[ 2 ];
	} _n;
	unsigned long	n_value;	/* value of symbol */
	short	n_scnum;	/* section number */
	unsigned short	n_type;	/* type and derived type */
	char	n_sclass;	/* storage class */
	char	n_numaux;	/* number of auxiliary entries */
};

#define	n_name		_n._n_name
#define	n_nptr		_n._n_nptr[ 1 ]
#define	n_zeroes	_n._n_n._n_zeroes
#define	n_offset	_n._n_n._n_offse      t

/*	UNIX name for a symbol table entry */

#define	nlist	syment

/*
   Relocatable symbols have a section number of the
   section in which they are defined.  Otherwise, section
   numbers have the following meanings:
*/
        /* undefined symbol */
#define  N_UNDEF	0
        /* special debugging symbol -- value of symbol is meaningless */
#define  N_DEBUG	-2

/*
   The fundamental type of a symbol packed into the low 
   4 bits of the word.
*/

#define  T_NULL     0
#define  T_ARG      1          /* function argument (only used by compiler) */
#define  T_CHAR     2          /* character */
#define  T_SHORT    3          /* short integer */
#define  T_INT      4          /* integer */
#define  T_LONG     5          /* long integer */
#define  T_FLOAT    6          /* floating point */
#define  T_DOUBLE   7          /* double word */
#define  T_STRUCT   8          /* structure  */
#define  T_UNION    9          /* union  */
#define  T_ENUM     10         /* enumeration  */
#define  T_MOE      11         /* member of enumeration */
#define  T_UCHAR    12         /* unsigned character */
#define  T_USHORT   13         /* unsigned short */
#define  T_UINT     14         /* unsigned integer */
#define  T_ULONG    15         /* unsigned long */

/*
 * derived types are:
 */

#define  DT_NON      0          /* no derived type */
#define  DT_PTR      1          /* pointer */
#define  DT_FCN      2          /* function */
#define  DT_ARY      3          /* array */

/*
 *   type packing constants
 */

#define  N_BTMASK     017
#define  N_TMASK      060
#define  N_TMASK1     0300
#define  N_TMASK2     0360
#define  N_BTSHFT     4
#define  N_TSHIFT     2

/*
 *   MACROS
 */

	/*   Basic Type of  x   */

#define  BTYPE(x)  ((x) & N_BTMASK)

	/*   Is  x  a  pointer ?   */

#define  ISPTR(x)  (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))

	/*   Is  x  a  function ?  */

#define  ISFCN(x)  (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))

	/*   Is  x  an  array ?   */

#define  ISARY(x)  (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))

	/* Is x a structure, union, or enumeration TAG? */

#define ISTAG(x)  ((x)==C_STRTAG || (x)==C_UNTAG || (x)==C_ENTAG)

#define  INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(DT_PTR<<N_BTSHFT)|(x&N_BTMASK))

#define  DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))

/*
 *	AUXILIARY ENTRY FORMAT
 */

union auxent
{
	struct
	{
		long		x_tagndx;	/* str, un, or enum tag indx */
		union
		{
			struct
			{
				unsigned short	x_lnno;	/* declaration line number */
				unsigned short	x_size;	/* str, union, array size */
			} x_lnsz;
			long	x_fsize;	/* size of function */
		} x_misc;
		union
		{
			struct			/* if ISFCN, tag, or .bb */
			{
				long	x_lnnoptr;	/* ptr to fcn line # */
				long	x_endndx;	/* entry ndx past block end */
			} 	x_fcn;
			struct			/* if ISARY, up to 4 dimen. */
			{
				unsigned short	x_dimen[DIMNUM];
			} 	x_ary;
		}		x_fcnary;
		unsigned short  x_tvndx;		/* tv index */
	} 	x_sym;
	struct
	{
		char	x_fname[FILNMLEN];
	} 	x_file;
        struct
        {
                long    x_scnlen;          /* section length */
                unsigned short  x_nreloc;  /* number of relocation entries */
                unsigned short  x_nlinno;  /* number of line numbers */
        }       x_scn;

	struct
	{
		unsigned short	x_tvlen;	/* length of .tv */
		unsigned short	x_tvran[2];	/* tv range */
		long		x_tvfill;	/* tv fill value */
	}	x_tv;	/* info about .tv section (in auxent of symbol .tv)) */
};

#define	SYMENT	struct syment
#define	SYMESZ	18	/* sizeof(SYMENT) */

#define	AUXENT	union auxent
#define	AUXESZ	18	/* sizeof(AUXENT) */

#endif
q C   X,   lcmd/adb/vax/access.c ./*	@(#)access.c	1.2	*/
#include "defs.h"

SCCSID(@(#)access.c	1.2);

static unsigned accfile(mode, adr, sptype, value)
    int mode;
    int adr;
    int sptype;
    int value;
{
    short pmode;
    short rd;
    int   curfile;
    int w;

    if (sptype == NSP)
        return(0);

    rd = (mode == RD);

    if (pid) {      /* Does a process exist? */
         pmode = (sptype & DSP ? (rd ? RDUSER : WDUSER) : 
                               (rd ? RIUSER : WIUSER));
		 errno = 0;
         w = ptrace(pmode, pid, adr, value);
         if (w == -1 && errno != 0)
             errflg = (sptype & DSP ? BADDAT : BADTXT);
         return(w);
    }
    w = 0;
    if (mode == WT && wtflag == O_RDONLY)
        error("not in write mode");

    if ( ! chkmap(&adr ,sptype))
        return(0);

    curfile = (sptype & DSP ? slshmap.ufd : qstmap.ufd);
    if (lseek(curfile, (long) adr&0x7fffffff, 0) == -1L ||
       (rd ? read(curfile, (char *) &w, sizeof(w)) : 
	    write(curfile, (char *) &value, sizeof(w))) == -1)
			errflg = (sptype&DSP ? BADDAT : BADTXT);
    return(w);
}

/* file handling and access routines */

void put(adr, sptype, value)
    int adr;
    int sptype;
    int value;
{
    (void) accfile(WT, adr, sptype, value);
}

unsigned get(adr, sptype)
    int adr;
    int sptype;
{
    return(accfile(RD, adr, sptype, 0));
}

unsigned chkget(n, sptype)
    int n;
    int sptype;
{
    unsigned w;

    w = get(n, sptype);
    chkerr()      ;
    return(w);
}

unsigned bchkget(n, sptype) 
    int n;
    int sptype;
{
    return(chkget(n, sptype) & LOBYTE);
}

static int chkmap(adr, sptype)
    int *adr;
    short sptype;
{
    MAPPTR amap;

    amap = (sptype & DSP ? &slshmap : &qstmap);
    if (sptype&STAR || !within(*adr, amap->b1, amap->e1)) { 
        if (within(*adr, amap->b2, amap->e2))
            *adr += (amap->f2) - (amap->b2);
        else { 
            errflg = (sptype&DSP ? BADDAT : BADTXT); 
            return(0);
        }
    }
    else
        *adr += (amap->f1) - (amap->b1);
    return(1);
}

static int within(adr, lbd, ubd)
    int adr;
    unsigned lbd;
    unsigned ubd;
{
    return(adr >= lbd && adr < ubd);
}
q @   ,   _ cmd/adb/vax/adb.mk c#	@(#)adb.mk	1.4
#
.SUFFIXES:
.SUFFIXES: .o .c .e .r .f .y .yr .ry .ey .ye .l .s

CFLAGS = -O
AS = as -

TESTDIR = .
INS = /etc/install -i -n /bin 
INSDIR =

BIN = /bin
USRBIN = /usr/bin
LIBA = lib/liba
LIBM = lib/libm
LIBC = lib/libc
LIBS = lib/libS
INCRT = /usr/include

FRC =


all:	$(TESTDIR)/adb

$(TESTDIR)/adb:\
	access.o\
	command.o\
	expr.o\
	extern.o\
	format.o\
	input.o\
	main.o\
	opcode.o\
	output.o\
	pcs.o\
	print.o\
	runpcs.o\
	setup.o\
	sym.o\
	/$(LIBC).a\
	$(INCRT)/time.h\
	$(INCRT)/mon.h\
	$(INCRT)/stdio.h\
	$(INCRT)/varargs.h\
	$(INCRT)/ctype.h\
	$(INCRT)/values.h\
	$(INCRT)/errno.h\
	$(INCRT)/termio.h\
	$(FRC)
		$(CC) $(CFLAGS) $(LDFLAGS) -o $(TESTDIR)/adb *.o

access.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


command.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


expr.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


extern.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


format.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


input.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


main.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INC      RT)/sys/pcb.h\
	machine.h\
	$(FRC)


opcode.o:\
	defs.h\
	
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	instrs.h\
	$(FRC)


output.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


pcs.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


print.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


runpcs.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


setup.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)


sym.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/psl.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	$(INCRT)/sys/pcb.h\
	machine.h\
	$(FRC)
	$(CC) $(CFLAGS) -DFLEXNAMES -c sym.c


FRC:

install:	all
		$(INS) $(TESTDIR)/adb $(INSDIR)
clean:
		-rm -f *.o

clobber:	clean
		-rm -f $(TESTDIR)/adb

q    ,   Mcmd/adb/vax/command.c /*	@(#)command.c	1.2	*/
/*
 *  Command decoding 
 */

#include "defs.h"

SCCSID(@(#)command.c	1.2);

static char eqformat[128] = "z";
static char stformat[128] = "X\"= \"^i";
static int  locmsk;

void command(buf, defcom)
    STRING  buf;
    char    defcom;
{
    int    itype;
    int    ptype;
    int    modifier;
    int    regptr;
    int    longpr;
    int    eqcom;
    char   wformat[1];
    char   savc;
    int    w;
    int    savdot;
    STRING savlp = lp;

    if (buf) { 
        if (*buf == EOR)
            return;
        else 
            lp = buf;
    }

    do {
        if (adrflg = expr(0))
            ditto = dot = expv;
        adrval = dot;

        TR1PRINT("Adrflg = %s, ", (adrflg ? "TRUE" : "FALSE"));
        TR1PRINT("adrval = %#x\n", adrval);

        if (rdc() == ',' && expr(0)) {
            cntflg = TRUE;
            cntval = expv;
        }
        else {
            cntflg = FALSE;
            cntval = 1;
            lp--;
        }

        TR1PRINT("Cntflg = %s, ", (cntflg ? "TRUE" : "FALSE"));
        TR1PRINT("cntval = %d\n", cntval);
   
        if ( ! eocmd(rdc()))
            lastcom = lastc;
              else { 
            if (adrflg == 0)
                dot = inkdot(dotinc);
            lp--;
            lastcom = defcom;
        }
   
        TR1PRINT("Type of command: %c\n", lastcom & STRIP);

        switch(lastcom & STRIP) {
   
            case '/':
                itype = DSP;
                ptype = DSYM;
                goto trystar;
   
            case '=':
                itype = NSP;
                ptype = NSYM;
                goto trypr;
   
            case '?':
                itype = ISP;
                ptype = ISYM;
                goto trystar;
   
trystar:
                if (rdc() == '*') {
                    lastcom |= QUOTE; 
                    itype |= STAR;
                }
                else
                    lp--;
   
trypr:
                longpr = FALSE;
                eqcom = lastcom == '=';

                switch (rdc()) {
   
                    case 'm': 
						{ /* Reset map data */
							short  fcount;
							MAP    *smap;
							union {
								MAP *m;
								int *mp;
							} amap;

							if (eqcom)
								error(BADEQ);
							smap = (itype & DSP ? &slshmap : &qstmap);
							amap.m = smap;
							fcount = 3;
							if (itype & STAR)
								amap.mp += 3;
							while (fcount-- && expr(0))
								*(amap.mp)++ = expv;
							if (rdc() == '?')
								smap->ufd = fsym;
							else if (lastc == '/')
								smap->ufd = fcor;
							else
								lp--;
						}
						break;


                    case 'l': /* Search for exp */
                        if (eqcom) 
                            error(BADEQ);
                        savdot = dot;
			expr(0);
                        locval = expv;
			switch (rdc())
			{
				case 'b':
					locmsk = 0xff;
					dotinc = 1;
					break;
				case 'w':
					locmsk = 0xffff;
					dotinc = 2;
					break;
				case 'l':
					locmsk = -1L;
					dotinc = 4;
					break;
				case 'o':
					locmsk = 0xff;
					for(;;)
					{
						w=get(dot,itype);
						if(errflg||mkfault||locval==
							(w&locmsk))
							break;
						printins(itype,w,0);
						dot=inkdot(dotinc);
					}
					psymoff(dot,ptype,"");
					goto out;
				default:
					lp--;
					if(expr(0))
						locmsk = expv;
					else
						locmsk = -1L;
					dotinc = 1;
					break;
			}
			if(expr(0))
				dotinc = expv;
                        for ( ; ; ) {
                            w = get(dot, itype);
                            if (errflg != NULL || mkfault || 
                                (w & locmsk) == locval) 
                                break; 
                            dot = inkdot(dotinc);
                        }
                        if (errflg != NULL) {
                            dot = savdot;
                            errflg = NOMATCH;
                        }
                        psymoff(dot, ptype, "");
                        break;

                    case 'W':
                        longpr = TRUE;

                    case 'w':
                        if (eqcom)
                            error(BADEQ);
                        wformat[0] = lastc;
                        (void) expr(1);
                        do {
                            savdot = dot; 
                            psymoff(dot, ptype, ":%16t"); 
                            (void) exform(1, wformat, itype, ptype);
                            errflg = NULL;
                            dot = savdot;
                            put(dot, itype, expv);
                            savdot = dot;
                            adbpr("=%8t");
                            (void) exform(1, wformat, itype, ptype);
                            newline();
                        } while (expr(0) && errflg == NULL);
                        dot = savdot;
                        chkerr();
                        break;

                    default:
                        lp--;
                        getformat(eqcom ? eqformat : stformat);
                        if ( ! eqcom)
                            psymoff(dot, IDSYM, ":%16t");
                        scanform(cntval, (eqcom ? eqformat : stformat),
                            itype, ptype);
                }
                break;

            case '>':
                lastcom = 0;
                savc = rdc();
				{
					struct grres res;
					res = getreg(savc);
					if (res.sf) {
					    regptr = res.roff;
						ADBREG(regptr) = dot;
						(void) ptrace(WUREGS, pid, SYSREG(regptr), 
							ADBREG(regptr));
					}
					else if ((modifier = varchk(savc)) != -1)
						var[modifier] = dot;
					else 
						error(BADVAR);
				}
                break;

            case '!':
                lastcom = 0;
                shell();
                break;

            case '$':
                lastcom = 0;
                dollar(nextchar());
                break;

            case ':':
                if ( ! executing) { 
                    executing = TRUE;
                    subpcs(nextchar());
                    executing = FALSE;
                    lastcom = 0;
                }
                break;

            case 0:
                prints(DBNAM      E);
                break;

            default:
                error(BADCOM);
        }

out:        flushbuf();
    } while (rdc() == ';');
    if (buf)
        lp = savlp; 
    else
        lp--; 
}
;q    X,   cmd/adb/vax/defs.h ./*	@(#)defs.h	1.4	*/
/*
 *  Common definitions
 */

#include	<sys/param.h>
#include	<signal.h>
#include	<sys/types.h>
#include	<sys/sysmacros.h>
#include	"a.out.h"
#include	<setjmp.h>
#include	<sys/text.h>
#include	<fcntl.h>
#include	<sys/dir.h>
#include	<sys/file.h>
#include	<sys/proc.h>
#include	<sys/tty.h>
#include	<sys/termio.h>
#include	<sys/inode.h>
#include	<sys/psl.h>
#include	<sys/user.h>
#include	<sys/errno.h>
#include	<sys/reg.h>
#include	<sys/stat.h>
#include	<stdio.h>
#include	<ctype.h>
#include	"mode.h"
#include	"functs.h"
#include	"extern.h"
#include	"sys.h"
#include	"lib.h"
#include	"filehdr.h"
#include	"syms.h"
#include	"scnhdr.h"
#include	"aouthdr.h"
#include	"storclass.h"

#define VARNO 36
#define VARB  11
#define VARD  13
#define VARE  14
#define VARF 15
#define VARM  22
#define VARS  28
#define VART  29

#define RD 0
#define WT 1

#define NSP      0
#define ISP      1
#define DSP      2
#define NSYM     0
#define ISYM     4
#define DSYM     8
#define IDSYM    12
#define ENDSYMS  (-1)
#define EXTRASYM (-2)

#define BPT      03
#define BKPTSET  1
#define BKPTEXEC 2

/*
 *  Ptrace mode defines
 */
#define SETTRC 0
#define RIUSER 1
#define RDUSER 2
#define RUREGS 3
#define WIUSER 4
#define WDUSER 5
#define WUREGS 6
#define CONTIN 7
#define EXIT   8
#define SINGLE 9

#define MAXREGS   17
#define ADBREG(A) (u.u_ar0[A])
#define SYSREG(A) ((int) (((char *) (&ADBREG(A))) - ((char *) &u)))

#define EOR    '\n'
#define SPACE  ' '
#define TB     '\t'

#define DBNAME  "adb\n"

#define LPRMODE "%R"
#define OFFMODE "+%R"

/* Symbol table in a.out file */
#define SYMBOLSIZE  18

#define DEFRADIX  16
#define MAXARG	  32
#define LINSIZ	1024
#define STAR       4
#define MAXOFF   255
#define MAXPOS    80
#define MAXLIN   128
#define QUOTE   0200
#define STRIP   0177
#define LOBYTE  0377
#define EVEN      -2

#define TRUE   (-1)
#define FALSE  0

#define shorten(a) ((short)(a))

#define SCCSID(A) static char Sccsid[] = "A"

#define TRPRINT(S) if (trace) (void) fprintf(stderr, S)
#define TR1PRINT(S, V) if (trace) (void) fprintf(stderr, S, V)
sq    ,   cmd/adb/vax/expr.c ./*	@(#)expr.c	1.2	*/
#include "defs.h"

SCCSID(@(#)expr.c	1.2);

static int  savframe;
static int  savpc;
static char isymbol[BUFSIZ];
static void readsym();
static void chkloc();

static SYMPTR lookupsym(symstr)
	STRING symstr;
{
	SYMPTR symp;

	symset();
	while ( symp = symget() )
	{
		skip_aux(symp);
		if( symp->n_scnum == N_DEBUG )
			continue;
		if( eqsym( symp->n_nptr, symstr, '_' ) ) 
			return(symp);
	}
	return(0);
}

int expr(a)                       /* term | term dyadic expr |  */
{ 
	short rc;
	int   lhs;

	(void) rdc(); 
	lp--; 
	rc = term(a);

	while (rc) {  
		lhs = expv;

	    switch (readchar()) {

	        case '+':
	            (void) term(a|1); 
				expv += lhs; 
				break;

	        case '-':
	            (void) term(a|1); 
				expv = lhs - expv;
				break;

	        case '#':
	            (void) term(a|1);
				expv = round(lhs, expv);
				break;

	        case '*':
	            (void) term(a|1);
				expv *= lhs;
				break;

	        case '%':
	            (void) term(a|1);
				expv = lhs / expv;
				break;
	        
	        case '&':
	            (void) term(a|1);
				expv &= lhs;
				break;

	        case '|':
	            (void) term(a|1);
				expv |= lhs;
				break;
	  
	        case ')':
				if ((a&2) == 0)
					error(BADKET);

	        default:
	            lp--;
	            return(rc);
	    }
	}
	return(rc);
}

static term(a)              /* item | monadic item | (expr) | */
{
	switch (readchar()) {

	    case '*':
	        (void) term(a|1);
			expv = chkget(expv, DSP);
			return(1);

	    case '@':
	        (void) term(a|1);
			expv = chkget(expv, ISP);
			return(1);

	    case '-':
	        (void) term(a|1);
			expv = -expv;
			return(1);

	    case '~':
	        (void) term(a|1);
			expv = ~expv;
			return(1);

	    case '(':
	        (void) expr(2);
	        if (*lp!=')')
				error(BADSYN);
	        else { 
				lp++;
				return(1);
	        }

	    default:
	        lp--;
	        return(item(a));
	}
}

static item(a) /* name [ . local ] | number | . | ^ | 
	              <var | <REG | 'x | | */
	int a;
{
	short  base;
	short  d;
	short  regptr;
	char   savc;
	int    frame;
	int oldframe;
	SYMPTR symp;
	int autonum;
	int argp;
	int word;

	(void) readchar();
	if (symchar(0)) 
	{
		readsym();
		if (lastc == '.') 
		{
			frame = ADBREG(FP);
			callpc = ADBREG(PC);
			while (errflg == NULL)  
			{
				savpc = callpc;
				(void) findsym(callpc, ISYM);
				if( eqsym( symbol.n_nptr, isymbol, '_' ) )
				{
					break;
				}
				callpc = get(frame+16, DSP);
				oldframe = frame; /* for possible adjustment */
				frame = get(frame+12, DSP) & EVEN;
				if (frame == 0)
					error(NOCFN);
			}
			if(frame!=ADBREG(FP))
				frame = oldframe;
			savframe = frame;
			(void) readc      har();
			if(getnum(readchar))
			{
				(void)readchar();
				autonum = expv;
				word = get(frame+6,DSP)&0xffff;
				if(word&0x2000)
				{
					argp = calcap(frame, word);
					localsym(frame,argp,frame!=oldframe);
					if(numlocs >= autonum+1)
					{
						localval = expv = locadr -(4 * autonum);
						adbpr("%8t%s.%X%  =  ", symbol.n_nptr,autonum);
						adbpr("%R\n",get(localval,DSP));
					}
					else
						error(BADSYM);
				}
				else
					error(BADSYM);
			} 
			else
				error(BADSYM);
		}
		else if ((symp = lookupsym(isymbol)) == 0)
			error(BADSYM);
		else 
			expv = symp->n_value;
		lp--;

	} 
	else if (getnum(readchar)) 
		;
	else if (lastc == '.') 
	{
		(void)readchar();
		if(getnum(readchar))
		{
			(void)readchar();
			autonum = expv;
			word=get(ADBREG(FP)+6,DSP)&0xffff;
			if(word&0x2000)
			{
				argp=calcap(ADBREG(FP),word);
				localsym(ADBREG(FP),argp,1);
				if(numlocs >= autonum+1)
				{
					localval=expv=locadr-(4*(autonum+1));
						adbpr("%8t%s.%X%  =  ",symbol.n_nptr,autonum);
						adbpr("%R\n",get(localval, DSP));
				}
				else
					error(BADSYM);
			}
			else
				error(BADSYM);
		}
		else 
			expv = dot;
	    lp--;

	} 
	else if (lastc == '"')
		expv = ditto;

	else if (lastc == '+') 
		expv = inkdot(dotinc);

	else if (lastc == '^')
		expv = inkdot(-dotinc);

	else if (lastc == '<') { 
		savc = rdc();
		{
			struct grres res;
			res = getreg(savc);
			if (res.sf)
				expv = ADBREG(res.roff);
			else if ((base = varchk(savc)) != -1)
				expv = var[base];
			else 
				error(BADVAR);
		}
	} 
	else if (lastc == '\'') { 
	    d = 4; 
	    expv = 0;
	    while (quotchar() != '\0') {  
	        if (d--) { 
				if (d == 1)
	                expv <<= 16; 
	            expv |= ((d&1) ? lastc : lastc << 8);
	        }
			else
				error(BADSYN);
	    }

	} 
	else if (a)
	    error(NOADR);
	else { 
	    lp--; 
	    return(0);
	}
	return(1);
}

/* Service routines for expression reading */
int getnum(rdf) 
	char (*rdf)();
{
	int  base;
	int  d;
	int  frpt;
	BOOL hex = FALSE;
	union {
		float r; 
		int   i;
	} real;

	if (isdigit(lastc) || (hex = TRUE, lastc == '#' &&
	                     hexdigit((*rdf)()))) { 
		expv = 0;
	    base = (hex ? 16 : radix);
		while ((base > 10 ? hexdigit(lastc) : isdigit(lastc))) {  
			expv *= base;
			if ((d = convdig(lastc)) >= base)
				error(BADSYN);
			expv += d;
			(*rdf)();
			if (expv == 0) { 
				if ((lastc == 'x' || lastc == 'X')) { 
					hex = TRUE;
					base = 16;
					(*rdf)();
				} 
				else if ((lastc == 't' || lastc=='T')) { 
					hex = FALSE; 
					base=10; 
					(*rdf)();
				} 
				else if ((lastc == 'o' || lastc=='O')) { 
					hex = FALSE; 
					base = 8; 
					(*rdf)();
				}
			}
		}
		if (lastc == '.' && (base == 10 || expv == 0) && !hex) { 
			real.r = expv;
			frpt = 0;
			base = 10;
			while (isdigit((*rdf)())) { 
				real.r *= base;
				frpt++;
				real.r += lastc - '0';
			}
			while (frpt--)
				real.r /= base;
			expv = real.i;
		}
		peekc = lastc;
		/*  lp--; */
		return(1);
	}
	else 
		return(0);
}
   
static void readsym()
{
	char *p = isymbol;

	do { 
		if (p < &isymbol[BUFSIZ])
			*p++ = lastc;
	    (void) readchar();
	} while (symchar(1));
	if (p < &isymbol[BUFSIZ])
		*p = 0;
}

static int hexdigit(c)
	char c;
{ 
	return((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'));
}

static int convdig(c)
	char c;
{
	if (isdigit(c)) 
		return(c - '0');
	else if (hexdigit(c))
		return(c - 'a' + 10);
	else
		return(17);
}

static int symchar(dig) /* TRUE if last character read can occur
						   in a symbol in position dig */
{
	if (lastc == '\\') { 
		(void) readchar(); 
		return(TRUE); 
	}
	return(isalpha(lastc) || lastc == '_' || dig && isdigit(lastc));
}

int varchk(name)
{
	if (isdigit(name))
		return(name - '0');
	if (isalpha(name)) 
		return((name & 037) - 1 + 10);
	return(-1);
}


static int
eqsym( s1, s2, c )	/* TRUE if s1 and s2 contain equivalent symbol names */
	STRING s1;
	STRING s2;
	char   c;
{
	if( eqstr( s1, s2 ) )
	    return( TRUE );
	else if ( *s1 == c )
	{ 
		char s3[BUFSIZ];
		int  i;
   
		s3[0] = c;
		for (i = 1; *s2; i++)
	        	s3[i] = *s2++; 
		s3[i] = '\0';
   
	    return( eqstr( s1, s3 ) );
	}
	return(FALSE);
}

calcap( frame, word )
int frame;
int word;
{
	int argp;
	word &= 0xfff;
	argp=frame+20+((word>>14)&3);
	while (word)
	{
		if(word&1)
			argp+=4;
		word >>= 1;
	}
	return(argp);
}
q /   ,   $cmd/adb/vax/extern.c  /*	@(#)extern.c	1.3	*/
#include "defs.h"

SCCSID(@(#)extern.c	1.3);

int trace = FALSE;             /* TRUE for debugging printout */

MSG ADWRAP   = "address wrap around";
MSG BADCOM   = "bad command";
MSG BADDAT   = "data address not found";
MSG BADEQ    = "unexpected `='";
MSG BADFIL   = "bad file format";
MSG BADKET   = "unexpected ')'";
MSG BADLOC   = "automatic variable not found";
MSG BADMAGIC = "bad core magic number";
MSG BADMOD   = "bad modifier";
MSG BADNAM   = "not enough space for symbols";
MSG BADRAD   = "must have 2<= radix <= 16";
MSG BADSYM   = "symbol not found";
MSG BADSYN   = "syntax error";
MSG BADTXT   = "text address not found";
MSG BADVAR   = "bad variable";
MSG B      ADWAIT  = "wait error: process disappeared!";
MSG ENDPCS   = "process terminated";
MSG EXBKPT   = "too many breakpoints";
MSG LONGFIL  = "filename too long";
MSG NOADR    = "address expected";
MSG NOBKPT   = "no breakpoint set";
MSG NOCFN    = "c routine not found";
MSG NOEOR    = "newline expected";
MSG NOFORK   = "try again";
MSG NOMATCH  = "cannot locate value";
MSG NOPCS    = "no process";
MSG NOTOPEN  = "cannot open";
MSG SZBKPT   = "bkpt: command too long";

int      adrflg;              /* User specified an address */
int      adrval;              /* TRUE if user specified an address */
int      argcount;            /* Number of supplied files */
BKPTR    bkpthead;            /* Boints to start of bkpt linked list */
int      callpc;              /* PC from one of the stack frames */
int      cntflg;              /* User specified an count */
int      cntval;              /* TRUE if user specified an count */
STRING   corfil = "core";     /* Name of the core file being used */
int      datsiz;              /* Size of data segment; default from core */
int      ditto;               /* Dot when command was entered */
int      dot;                 /* Current address */
int      dotinc;              /* Value by which dot is incremented */
int      entrypt;             /* Entry point for object file */
int      eof;                 /* Result of last read from < input */
STRING   errflg;              /* Error message */
int      executing;           /* TRUE when command is ":" */
int      expv;                /* Result of evaluating an expression */
int      fcor;                /* Core file file descriptor */
int      fsym;                /* a.out file descriptor */
int      infile;              /* File descriptor for redirected input */
char     lastc = EOR;         /* Result of last read */
int      lastcom = '=';       /* Type of last command */
int      localval;            /* Address of a local variable */
int	locadr;
int	numlocs;
int      locval;
int      loopcnt;             /* Process execution counter */
STRING   lp;                  /* Points at current char in input line */
short    magic;               /* Magic number for object file */
int      maxfile = 1<<24;     /* Maximum length of object file */
int      maxoff;              /* Max offset for symbolic addresses */
int      maxpos;              /* Maximum print width on output */
unsigned maxstor = 1<<31;     /* Maximum storage address */
int      mkfault;             /* Counts interrupts */
int      outfile = 1;         /* File descriptor for user output file */
char     peekc;
int      pid;                 /* Processid of user program */
MAP      qstmap;              /* ? map */
int      radix = DEFRADIX;    /* Current output radix */
REGLIST  reglist[] = {        /* Register description information */
	"ps",  PS,
	"pc",  PC,
	"sp",  SP,
	"fp",  FP,
	"ap",  AP,
	"r11", R11,
	"r10", R10,
	"r9",  R9,
	"r8",  R8,
	"r7",  R7,
	"r6",  R6,
	"r5",  R5,
	"r4",  R4,
	"r3",  R3,
	"r2",  R2,
	"r1",  R1,
	"r0",  R0,
};
SIGunion sigint;              /* Current interrupt handling routine */
int      signo;               /* Signal that caused process halt */
SIGunion sigqit;              /* Current quit handling routine */
MAP      slshmap;             /* / map */
int      stksiz;              /* Size of stack from core file */
int      txtsiz;              /* Size of text segment; default from core */
int      symbas;              /* A.out file address of symbol table */
SYMTAB   symbol;              /* I/O buffer for a.out symbols */
STRING   symfil = "a.out";    /* Name of the object file being used */
int      symnum;              /* Number of symbols in symbol table */
SYMSLAVE *symvec;             /* Beginning of slave array */
int      var[VARNO];          /* Holds values of adb variables */
int      wtflag;              /* TRUE if user gave -w flag */

union Uuniontag Uunion;       /* User block in core file */
q    aX,   cmd/adb/vax/extern.h  /*	@(#)extern.h	1.2	*/
/*
 *  External data declarations
 */

extern MSG      ADWRAP;
extern MSG      BADCOM;
extern MSG      BADDAT;
extern MSG      BADEQ;
extern MSG      BADFIL;
extern MSG      BADKET;
extern MSG      BADLOC;
extern MSG      BADMAGIC;
extern MSG      BADMOD;
extern MSG      BADNAM;
extern MSG      BADRAD;
extern MSG      BADSYM;
extern MSG      BADSYN;
extern MSG      BADTXT;
extern MSG      BADVAR;
extern MSG      BADWAIT;
extern MSG      ENDPCS;
extern MSG      EXBKPT;
extern MSG      LONGFIL;
extern MSG      NOADR;
extern MSG      NOBKPT;
extern MSG      NOCFN;
extern MSG      NOEOR;
extern MSG      NOFORK;
extern MSG      NOMATCH;
extern MSG      NOPCS;
extern MSG      NOTOPEN;
extern MSG      SZBKPT;

extern int      adrflg;
extern int      adrval;
extern int      argcount;
extern BKPTR    bkpthead;
extern int      callpc;
extern int      cntflg;
extern int      cntval;
extern STRING   corfil;
extern int      datsiz;
extern int      ditto;
extern int      dot;
extern int      dotinc;
extern int      entrypt;
extern int      eof;
extern STRING   errflg;
extern int      executing;
ext      ern int      expv;
extern int      fcor;
extern int      fsym;
extern int      infile;
extern char     lastc;
extern int      lastcom;
extern int      localval;
extern int      locval;
extern int      loopcnt;
extern STRING   lp;
extern short    magic;
extern int      maxfile;
extern int      maxoff;
extern int      maxpos;
extern unsigned maxstor;
extern int      mkfault;
extern int      outfile;
extern char     peekc;
extern int      pid;
extern MAP      qstmap;
extern int      radix;
extern REGLIST  reglist[];
extern SIGunion sigint;
extern int      signo;
extern SIGunion sigqit;
extern MAP      slshmap;
extern int      stksiz;
extern int      symbas;
extern SYMTAB   symbol;
extern STRING   symfil;
extern int      symnum;
extern SYMSLAVE *symvec;
extern int      trace;
extern int      txtsiz;
extern int      var[];
extern int      wtflag;
extern int locadr;
extern int numlocs;
eq #   yY,   9cmd/adb/vax/format.c  /*	@(#)format.c	1.2	*/
#include "defs.h"

SCCSID(@(#)format.c	1.2);

static STRING fphack;
static void   printesc();

static char rdfp()
{
    return(lastc = *fphack++);
}

void scanform(icount, ifp, itype, ptype)
    int    icount;
    STRING ifp;
    int    itype;
    int    ptype;
{
    STRING fp;
    int    fcount;
    int    init = TRUE;
    int    savdot;
    BOOL   exact;

    while (icount) {  
        exact = (findsym(dot, ptype) == 0);
        if ((! init) && exact && maxoff) 
            adbpr("\n%s:%16t", symbol.n_nptr);

        fp = ifp;
        savdot = dot; 
        init = FALSE;

        /*now loop over format*/
        while (*fp && errflg == NULL) {  
            fphack = fp;
            (void) rdfp();
            if (getnum(rdfp) && lastc == '*') { 
                fcount = expv;
                fp = fphack;
                peekc = 0;
            }
            else
                fcount = 1;

            if (*fp == 0) 
                break;
            if (exact && dot == savdot && itype == ISP && 
				symbol.n_nptr[0] == '_' && *fp == 'i') { 
                (void) exform(1, "x", itype, ptype); 
                fp++; 
                printc(EOR); /* entry mask */
            }
            else
                fp = exform(fcount, fp, itype, ptype);
        }
        dotinc = dot - savdot;
        dot = savdot;

        if (errflg != NULL) { 
            if (icount < 0) { 
                errflg = NULL;
                break;
            }
            else
                error(errflg);
        }
        if (--icount)
            dot = inkdot(dotinc);
        if (mkfault) 
            error((STRING) NULL);
    }
}

STRING exform(fcount, ifp, itype, ptype)
	int    fcount;
	STRING ifp;
	int    itype;
	int    ptype;
{
    /* execute single format item `fcount' times
     * sets `dotinc' and moves `dot'
     * returns address of next format item
     */
    unsigned w;
    int      savdot;
    int      wx;
    STRING   fp;
    char     c;
    char     modifier;
    char     longpr;
    struct {
        int   sa;
        short sb;
        short sc;
    } fw;

    while (fcount > 0) {
		fp = ifp;
		c = *fp;
        longpr = (c >= 'A') & (c <= 'Z') | (c == 'f') | (c == '4') | (c == 'p');
        if (itype == NSP || *fp == 'a') {
			wx = dot;
			w = dot;
        } 
		else {
			w = get(dot, itype);
            wx = w;
        }
        if (c == 'F') {
			fw.sb = get(inkdot(4), itype);
            fw.sc = get(inkdot(6), itype);
        }
        if (errflg != NULL)
			return(fp);
        if (mkfault)
			error((STRING) NULL);
        var[0] = wx;
        modifier = *fp++;
        dotinc = (longpr ? 4 : 2);

        if (charpos() == 0 && modifier != 'a' )
			adbpr("%16m");

        switch(modifier) {

            case SPACE:
			case TB:
				break;

            case 't':
			case 'T':
				adbpr("%T",fcount);
				return(fp);

            case 'r':
			case 'R':
				adbpr("%M", fcount);
				return(fp);

            case 'a':
				psymoff(dot, ptype, ":%16t");
				dotinc = 0;
				break;

            case 'p':
				psymoff(var[0], ptype, "%16t");
				break;

            case 'u':
				adbpr("%-8u", w);
				break;

            case 'U':
				adbpr("%-16U", wx);
				break;

            case 'c':
			case 'C':
				if (modifier == 'C')
					printesc(w);
				else
					printc((char) (w & LOBYTE));
				dotinc = 1;
				break;

            case 'b':
			case 'B':
				adbpr("%-8o", w&LOBYTE);
				dotinc = 1;
				break;

            case '1':
				adbpr("%-8r", w&LOBYTE);
				dotinc = 1;
				break;

            case '2':
            case 'w':
				adbpr("%-8r", w);
				break;

            case '4':
            case 'W':
				adbpr("%-16R", wx);
				break;

            case 's':
			case 'S':
				savdot = dot;
				dotinc = 1;
				while ((c = get(dot, itype)&LOBYTE) && errflg == NULL) {
					dot = inkdot(1);
				    if (modifier == 'S') 
						printesc((unsigned) c);
				    else
						printc(c);
				    endline();
				}
				dotinc = dot - savdot + 1;
				dot = savdot;
				break;

			case 'x':
				adbpr("%-8x", w);
				break;

            case 'X':
				adbpr("%-16X", wx);
				break;

            case 'Y':
				adbpr("%-24Y      ", wx);
				break;

            case 'q':
				adbpr("%-8q", w);
				break;

            case 'Q':
				adbpr("%-16Q", wx);
				break;

            case 'o':
				adbpr("%-8o", w);
				break;

            case 'O':
				adbpr("%-16O", wx);
				break;

            case 'i':
				printins(itype, (int) w, 1);
				printc(EOR);
				break;

            case 'd':
				adbpr("%-8d", w);
				break;

            case 'D':
				adbpr("%-16D", wx);
				break;

            case 'f':
				fw.sa = fw.sb = fw.sc = 0;
				fw.sa = wx;
				adbpr("%-16.9f", fw);
				dotinc = 4;
				break;

            case 'F':
				fw.sa = wx;
				adbpr("%-32.18F", fw);
				dotinc = 8;
				break;

            case 'n':
			case 'N':
				printc('\n');
				dotinc = 0;
				break;

            case '"':
				dotinc = 0;
				while (*fp != '"' && *fp)
					printc(*fp++);
				if (*fp)
					fp++;
				break;

            case '^':
				dot = inkdot(-dotinc * fcount);
				return(fp);

            case '+':
				dot = inkdot(fcount);
				return(fp);

            case '-':
				dot = inkdot(-fcount);
				return(fp);

            default: 
				error(BADMOD);
        }
        if (itype != NSP)
			dot = inkdot(dotinc);
        fcount--;
        endline();
    }

    return(fp);
}

void shell()
{
    int    rc;
    int    status;
    int    unixpid;
    STRING argp = lp;

    while (lastc != EOR)
		(void) rdc();
    if ((unixpid = fork()) == 0) {
		if (-1 == (int) signal(SIGINT, sigint.siFUN))
			perror("shell");
        if (-1 == (int) signal(SIGQUIT, sigqit.siFUN))
			perror("shell");
        *lp=0;
		if (-1 == execl("/bin/sh", "sh", "-c", argp, 0))
			perror("shell");
		(void) exit(16);
    }
    else if (unixpid == -1)
		error(NOFORK);
    else {
		if (-1 == (int) signal(SIGINT, SIG_IGN))
			perror("shell");
        while ((rc = wait(&status)) != unixpid && rc != -1 )
			;
        if (-1 == (int) signal(SIGINT, sigint.siFUN))
			perror("shell");
        prints("!");
		lp--;
    }
}

static void printesc(c)
    unsigned c;
{
    c &= STRIP;
    if (c < SPACE || c > '~' || c == '@') 
        adbpr("@%c", (c == '@' ? '@' : c ^ 0140));
    else 
        printc((char) c);
}

int inkdot(incr)
{
    int newdot;

    newdot = dot + incr;
    if ((dot ^ newdot) >> 24 )
		error(ADWRAP);
    return(newdot);
}
 q    ",   cmd/adb/vax/functs.h  /*	@(#)functs.h	1.2	*/
/* 
 *  Result type declarations 
 */

/* access.c */

unsigned int bchkget();
unsigned int chkget();
unsigned int get();
void         put();

/* command.c */

void command();

/* expr.c */

int  expr();
int  getnum();
int  varchk();

/* format.c */

STRING exform();
int    inkdot();
void   shell();
void   scanform();

/* input.c */

int  eocmd();
void getformat();
int  nextchar();
char quotchar();
char rdc();
char readchar();

/* main.c */

void chkerr();
void done();
void error();
int  round();

/* opcode.c */

void mkioptab();
void printins();

/* output.c */

void adbpr();
void endline();
int  eqstr();
void flushbuf();
void iclose();
void newline();
void oclose();
void printc();
void prints();

/* pcs.c */

void subpcs();

/* print.c */

struct grres getreg();
void         printpc();
void         dollar();
void         sigprint();

/* runpcs.c */

void  delbp();
void  endpcs();
int   getsig();
int   runpcs();
BKPTR scanbkpt();
void  setup();

/* setup.c */

void setsym();
void setcor();

/* sym.c */

unsigned int findsym();
void          localsym();
void         psymoff();
SYMPTR       symget();
void         symset();
void         valpr();
rq    aY,   scmd/adb/vax/input.c /*	@(#)input.c	1.2	*/
/*
 *  Input routines 
 */

#include "defs.h"

SCCSID(@(#)input.c	1.2);

static char line[LINSIZ];

int eocmd(c)            /* TRUE if end of command has been reached */
    char c;
{
    return(c == EOR || c == ';');
}

char rdc()
{
	char c;

    do 
        c = readchar();
    while (c == SPACE || c == TB);

    return(c);
}

char readchar()
{
    if (eof)
        lastc = EOF;
    else {
        if (lp == 0) {
            lp = line;
            do {
                eof = (0 == read(infile, lp, 1));
                if (mkfault)
                    error((STRING) NULL);
            } while (( ! eof) && *lp++ != EOR);
            *lp = 0; 
            lp = line;
        }
        if (lastc = peekc)
            peekc = 0;
        else if (lastc = *lp) 
            lp++;
    }
    return(lastc);
}

int nextchar()
{
    if (eocmd(rdc())) {
        lp--; 
        return(0);
    }
    else 
        return(lastc);
}

char quotchar()
{
    if (readchar() == '\\')
        return(readchar());
    else if (lastc == '\'')
        return('\0');
    else 
        return(lastc);
}

void getformat(deformat)
    STRING deformat;
{
    STRING fptr = deformat; 
    int quote = FALSE;

    while (quote ? readchar() != EOR : ! eocmd(readchar()))
        if ((*fptr++ = lastc) == '"')
            quote = ~quote;
    lp--;
    if (fptr != deformat)
        *fptr++ = '\0';
}
Rq    X,   3cmd/adb/vax/instrs.h  /*	@(#)instrs.h	1.2	*/
OP("acbb",0x9d,4,ACCR+TYPB,ACCR+TYPB,ACCM+TYPB,ACCB+TYPW,0,0),
OP("acbd",0x6f,4,ACCR+TYPD,ACC      R+TYPD,ACCM+TYPD,ACCB+TYPW,0,0),
OP("acbf",0x4f,4,ACCR+TYPF,ACCR+TYPF,ACCM+TYPF,ACCB+TYPW,0,0),
OP("acbl",0xf1,4,ACCR+TYPL,ACCR+TYPL,ACCM+TYPL,ACCB+TYPW,0,0),
OP("acbw",0x3d,4,ACCR+TYPW,ACCR+TYPW,ACCM+TYPW,ACCB+TYPW,0,0),
OP("adawi",0x58,2,ACCR+TYPW,ACCM+TYPW,0,0,0,0),
OP("addb2",0x80,2,ACCR+TYPB,ACCM+TYPB,0,0,0,0),
OP("addb3",0x81,3,ACCR+TYPB,ACCR+TYPB,ACCW+TYPB,0,0,0),
OP("addd2",0x60,2,ACCR+TYPD,ACCM+TYPD,0,0,0,0),
OP("addd3",0x61,3,ACCR+TYPD,ACCR+TYPD,ACCW+TYPD,0,0,0),
OP("addf2",0x40,2,ACCR+TYPF,ACCM+TYPF,0,0,0,0),
OP("addf3",0x41,3,ACCR+TYPF,ACCR+TYPF,ACCW+TYPF,0,0,0),
OP("addl2",0xc0,2,ACCR+TYPL,ACCM+TYPL,0,0,0,0),
OP("addl3",0xc1,3,ACCR+TYPL,ACCR+TYPL,ACCW+TYPL,0,0,0),
OP("addp4",0x20,4,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,0,0),
OP("addp6",0x21,6,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB),
OP("addw2",0xa0,2,ACCR+TYPW,ACCM+TYPW,0,0,0,0),
OP("addw3",0xa1,3,ACCR+TYPW,ACCR+TYPW,ACCW+TYPW,0,0,0),
OP("adwc",0xd8,2,ACCR+TYPL,ACCM+TYPL,0,0,0,0),
OP("aobleq",0xf3,3,ACCR+TYPL,ACCM+TYPL,ACCB+TYPB,0,0,0),
OP("aoblss",0xf2,3,ACCR+TYPL,ACCM+TYPL,ACCB+TYPB,0,0,0),
OP("ashl",0x78,3,ACCR+TYPB,ACCR+TYPL,ACCW+TYPL,0,0,0),
OP("ashp",0xf8,6,ACCR+TYPB,ACCR+TYPW,ACCA+TYPB,ACCR+TYPB,ACCR+TYPW,ACCA+TYPB),
OP("ashq",0x79,3,ACCR+TYPB,ACCR+TYPQ,ACCW+TYPQ,0,0,0),
OP("bbc",0xe1,3,ACCR+TYPL,ACCR+TYPB,ACCB+TYPB,0,0,0),
OP("bbcc",0xe5,3,ACCR+TYPL,ACCR+TYPB,ACCB+TYPB,0,0,0),
OP("bbcci",0xe7,3,ACCR+TYPL,ACCR+TYPB,ACCB+TYPB,0,0,0),
OP("bbcs",0xe3,3,ACCR+TYPL,ACCR+TYPB,ACCB+TYPB,0,0,0),
OP("bbs",0xe0,3,ACCR+TYPL,ACCR+TYPB,ACCB+TYPB,0,0,0),
OP("bbsc",0xe4,3,ACCR+TYPL,ACCR+TYPB,ACCB+TYPB,0,0,0),
OP("bbss",0xe2,3,ACCR+TYPL,ACCR+TYPB,ACCB+TYPB,0,0,0),
OP("bbssi",0xe6,3,ACCR+TYPL,ACCR+TYPB,ACCB+TYPB,0,0,0),
OP("bcc",0x1e,1,ACCB+TYPB,0,0,0,0,0),
OP("bcs",0x1f,1,ACCB+TYPB,0,0,0,0,0),
OP("beql",0x13,1,ACCB+TYPB,0,0,0,0,0),
OP("beqlu",0x13,1,ACCB+TYPB,0,0,0,0,0),
OP("bgeq",0x18,1,ACCB+TYPB,0,0,0,0,0),
OP("bgequ",0x1e,1,ACCB+TYPB,0,0,0,0,0),
OP("bgtr",0x14,1,ACCB+TYPB,0,0,0,0,0),
OP("bgtru",0x1a,1,ACCB+TYPB,0,0,0,0,0),
OP("bicb2",0x8a,2,ACCR+TYPB,ACCM+TYPB,0,0,0,0),
OP("bicb3",0x8b,3,ACCR+TYPB,ACCR+TYPB,ACCW+TYPB,0,0,0),
OP("bicl2",0xca,2,ACCR+TYPL,ACCM+TYPL,0,0,0,0),
OP("bicl3",0xcb,3,ACCR+TYPL,ACCR+TYPL,ACCW+TYPL,0,0,0),
OP("bicpsw",0xb9,1,ACCR+TYPW,0,0,0,0,0),
OP("bicw2",0xaa,2,ACCR+TYPW,ACCM+TYPW,0,0,0,0),
OP("bicw3",0xab,3,ACCR+TYPW,ACCR+TYPW,ACCW+TYPW,0,0,0),
OP("bisb2",0x88,2,ACCR+TYPB,ACCM+TYPB,0,0,0,0),
OP("bisb3",0x89,3,ACCR+TYPB,ACCR+TYPB,ACCW+TYPB,0,0,0),
OP("bisl2",0xc8,2,ACCR+TYPL,ACCM+TYPL,0,0,0,0),
OP("bisl3",0xc9,3,ACCR+TYPL,ACCR+TYPL,ACCW+TYPL,0,0,0),
OP("bispsw",0xb8,1,ACCR+TYPW,0,0,0,0,0),
OP("bisw2",0xa8,2,ACCR+TYPW,ACCM+TYPW,0,0,0,0),
OP("bisw3",0xa9,3,ACCR+TYPW,ACCR+TYPW,ACCW+TYPW,0,0,0),
OP("bitb",0x93,2,ACCR+TYPB,ACCR+TYPB,0,0,0,0),
OP("bitl",0xd3,2,ACCR+TYPL,ACCR+TYPL,0,0,0,0),
OP("bitw",0xb3,2,ACCR+TYPW,ACCR+TYPW,0,0,0,0),
OP("blbs",0xe8,2,ACCR+TYPL,ACCB+TYPB,0,0,0,0),
OP("blbc",0xe9,2,ACCR+TYPL,ACCB+TYPB,0,0,0,0),
OP("bleq",0x15,1,ACCB+TYPB,0,0,0,0,0),
OP("blequ",0x1b,1,ACCB+TYPB,0,0,0,0,0),
OP("blss",0x19,1,ACCB+TYPB,0,0,0,0,0),
OP("blssu",0x1f,1,ACCB+TYPB,0,0,0,0,0),
OP("bneq",0x12,1,ACCB+TYPB,0,0,0,0,0),
OP("bnequ",0x12,1,ACCB+TYPB,0,0,0,0,0),
OP("bpt",0x03,0,0,0,0,0,0,0),
OP("brb",0x11,1,ACCB+TYPB,0,0,0,0,0),
OP("brw",0x31,1,ACCB+TYPW,0,0,0,0,0),
OP("bsbb",0x10,1,ACCB+TYPB,0,0,0,0,0),
OP("bsbw",0x30,1,ACCB+TYPW,0,0,0,0,0),
OP("bvc",0x1c,1,ACCB+TYPB,0,0,0,0,0),
OP("bvs",0x1d,1,ACCB+TYPB,0,0,0,0,0),
OP("callg",0xfa,2,ACCA+TYPB,ACCA+TYPB,0,0,0,0),
OP("calls",0xfb,2,ACCR+TYPL,ACCA+TYPB,0,0,0,0),
OP("caseb",0x8f,3,ACCR+TYPB,ACCR+TYPB,ACCR+TYPB,0,0,0),
OP("casel",0xcf,3,ACCR+TYPL,ACCR+TYPL,ACCR+TYPL,0,0,0),
OP("casew",0xaf,3,ACCR+TYPW,ACCR+TYPW,ACCR+TYPW,0,0,0),
OP("chme",0xbd,1,ACCR+TYPW,0,0,0,0,0),
OP("chmk",0xbc,1,ACCR+TYPW,0,0,0,0,0),
OP("chms",0xbe,1,ACCR+TYPW,0,0,0,0,0),
OP("chmu",0xbf,1,ACCR+TYPW,0,0,0,0,0),
OP("clrb",0x94,1,ACCW+TYPB,0,0,0,0,0),
OP("clrd",0x7c,1,ACCW+TYPD,0,0,0,0,0),
OP("clrf",0xd4,1,ACCW+TYPF,0,0,0,0,0),
OP("clrl",0xd4,1,ACCW+TYPL,0,0,0,0,0),
OP("clrq",0x7c,1,ACCW+TYPQ,0,0,0,0,0),
OP("clrw",0xb4,1,ACCW+TYPW,0,0,0,0,0),
OP("cmpb",0x91,2,ACCR+TYPB,ACCR+TYPB,0,0,0,0),
OP("cmpc3",0x29,3,ACCR+TYPW,ACCA+TYPB,ACCA+TYPB,0,0,0),
OP("cmpc5",0x2d,5,ACCR+TYPW,ACCA+TYPB,ACCR+TYPB,ACCR+TYPW,ACCA+TYPB,0),
OP("cmpd",0x71,2,ACCR+TYPD,ACCR+TYPD,0,0,0,0),
OP("cmpf",0x51,2,ACCR+TYPF,ACCR+TYPF,0,0,0,0),
OP("cmpl",0xd1,2,ACCR+TYPL,ACCR+TYPL,0,0,0,0),
OP("cmpp3",0x35,3,ACCR+TYPW,ACCA+TYPB,ACCA+TYPB,0,0,0),
OP("cmpp4",0x37,4,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,0,0),
OP("cmpv",0xec,4,ACCR+TYPL,ACCR+TYPB,ACCR+TYPB,ACCR+TYPL,0,0),
OP("cmpw",0xb1,2,ACCR+TYPW,ACCR+TYPW,0,0,0,0),
OP("cmpzv",0xed,4,ACCR+TYPL,ACCR+TYPB,ACCR+TYPB,ACCR+TYPL,0,0),
OP("crc",0x0b,4,ACCA+TYPB,ACCR+TYPL,ACCR+TYPW,ACCA+TYPB,0,0),
OP("cvtbd",0x6c,2,ACCR+TYPB,ACCW+TYPD,0,0,0,0),
OP("cvtbf",0x4c,2,ACCR+TYPB,ACCW+TYPB,0,0,0,0),
OP("cvtbl",0x98,2,ACCR+TYPB,ACCW+TYPL,0,0,0,0),
OP("cvtbw",0x99,2,ACCR+TYPB,ACCW+TYPW,0,0,0,0),
OP("cvtdb",0x68,2,ACCR+TYPD,ACCW+TYPB,0,0,0,0),
OP("cvtdf",0x76,2,ACCR+TYPD,ACCW+TYPF,0,0,0,0),
OP("cvtdl",0x6a,2,ACCR+TYPD,ACC      W+TYPL,0,0,0,0),
OP("cvtdw",0x69,2,ACCR+TYPD,ACCW+TYPW,0,0,0,0),
OP("cvtfb",0x48,2,ACCR+TYPF,ACCW+TYPB,0,0,0,0),
OP("cvtfd",0x56,2,ACCR+TYPF,ACCW+TYPD,0,0,0,0),
OP("cvtfl",0x4a,2,ACCR+TYPF,ACCW+TYPL,0,0,0,0),
OP("cvtfw",0x49,2,ACCR+TYPF,ACCW+TYPW,0,0,0,0),
OP("cvtlb",0xf6,2,ACCR+TYPL,ACCW+TYPB,0,0,0,0),
OP("cvtld",0x6e,2,ACCR+TYPL,ACCW+TYPD,0,0,0,0),
OP("cvtlf",0x4e,2,ACCR+TYPL,ACCW+TYPF,0,0,0,0),
OP("cvtlp",0xf9,3,ACCR+TYPL,ACCR+TYPW,ACCA+TYPB,0,0,0),
OP("cvtlw",0xf7,2,ACCR+TYPL,ACCW+TYPW,0,0,0,0),
OP("cvtpl",0x36,3,ACCR+TYPW,ACCA+TYPB,ACCW+TYPL,0,0,0),
OP("cvttp",0x26,5,ACCR+TYPW,ACCA+TYPB,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,0),
OP("cvtpt",0x24,5,ACCR+TYPW,ACCA+TYPB,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,0),
OP("cvtps",0x08,4,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,0,0),
OP("cvtrdl",0x6b,2,ACCR+TYPD,ACCW+TYPL,0,0,0,0),
OP("cvtrfl",0x4b,2,ACCR+TYPF,ACCW+TYPL,0,0,0,0),
OP("cvtsp",0x09,4,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,0,0),
OP("cvtwb",0x33,2,ACCR+TYPW,ACCW+TYPB,0,0,0,0),
OP("cvtwd",0x6d,2,ACCR+TYPW,ACCW+TYPD,0,0,0,0),
OP("cvtwf",0x4d,2,ACCR+TYPW,ACCW+TYPF,0,0,0,0),
OP("cvtwl",0x32,2,ACCR+TYPW,ACCW+TYPL,0,0,0,0),
OP("decb",0x97,1,ACCM+TYPB,0,0,0,0,0),
OP("decl",0xd7,1,ACCM+TYPL,0,0,0,0,0),
OP("decw",0xb7,1,ACCM+TYPW,0,0,0,0,0),
OP("divb2",0x86,2,ACCR+TYPB,ACCM+TYPB,0,0,0,0),
OP("divb3",0x87,3,ACCR+TYPB,ACCR+TYPB,ACCW+TYPB,0,0,0),
OP("divd2",0x66,2,ACCR+TYPD,ACCM+TYPD,0,0,0,0),
OP("divd3",0x67,3,ACCR+TYPD,ACCR+TYPD,ACCR+TYPD,0,0,0),
OP("divf2",0x46,2,ACCR+TYPF,ACCM+TYPF,0,0,0,0),
OP("divf3",0x47,3,ACCR+TYPF,ACCR+TYPF,ACCW+TYPF,0,0,0),
OP("divl2",0xc6,2,ACCR+TYPL,ACCM+TYPL,0,0,0,0),
OP("divl3",0xc7,3,ACCR+TYPL,ACCR+TYPL,ACCW+TYPL,0,0,0),
OP("divp",0x27,6,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB),
OP("divw2",0xa6,2,ACCR+TYPW,ACCM+TYPW,0,0,0,0),
OP("divw3",0xa7,3,ACCR+TYPW,ACCR+TYPW,ACCW+TYPW,0,0,0),
OP("editpc",0x38,4,ACCR+TYPW,ACCA+TYPB,ACCA+TYPB,ACCA+TYPB,0,0),
OP("ediv",0x7b,4,ACCR+TYPL,ACCR+TYPQ,ACCW+TYPL,ACCW+TYPL,0,0),
OP("emodd",0x74,5,ACCR+TYPD,ACCR+TYPB,ACCR+TYPD,ACCW+TYPL,ACCW+TYPD,0),
OP("emodf",0x54,5,ACCR+TYPF,ACCR+TYPB,ACCR+TYPF,ACCW+TYPL,ACCW+TYPF,0),
OP("emul",0x7a,4,ACCR+TYPL,ACCR+TYPL,ACCR+TYPL,ACCW+TYPQ,0,0),
OP("extv",0xee,4,ACCR+TYPL,ACCR+TYPB,ACCR+TYPB,ACCW+TYPL,0,0),
OP("extzv",0xef,4,ACCR+TYPL,ACCR+TYPB,ACCR+TYPB,ACCW+TYPL,0,0),
OP("ffc",0xeb,4,ACCR+TYPL,ACCR+TYPB,ACCR+TYPB,ACCW+TYPL,0,0),
OP("ffs",0xea,4,ACCR+TYPL,ACCR+TYPB,ACCR+TYPB,ACCW+TYPL,0,0),
OP("halt",0x00,0,0,0,0,0,0,0),
OP("incb",0x96,1,ACCM+TYPB,0,0,0,0,0),
OP("incl",0xd6,1,ACCM+TYPL,0,0,0,0,0),
OP("incw",0xb6,1,ACCM+TYPW,0,0,0,0,0),
OP("index",0x0a,6,ACCR+TYPL,ACCR+TYPL,ACCR+TYPL,ACCR+TYPL,ACCR+TYPL,ACCW+TYPL),
OP("insqhi",0x5c,2,ACCA+TYPB,ACCA+TYPQ,0,0,0,0),
OP("insqti",0x5d,2,ACCA+TYPB,ACCA+TYPQ,0,0,0,0),
OP("insque",0x0e,2,ACCA+TYPB,ACCA+TYPB,0,0,0,0),
OP("insv",0xf0,4,ACCR+TYPL,ACCR+TYPL,ACCR+TYPB,ACCW+TYPB,0,0),
OP("jmp",0x17,1,ACCA+TYPB,0,0,0,0,0),
OP("jsb",0x16,1,ACCA+TYPB,0,0,0,0,0),
OP("ldpctx",0x06,0,0,0,0,0,0,0),
OP("locc",0x3a,3,ACCR+TYPB,ACCR+TYPW,ACCA+TYPB,0,0,0),
OP("matchc",0x39,4,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,0,0),
OP("mcomb",0x92,2,ACCR+TYPB,ACCW+TYPB,0,0,0,0),
OP("mcoml",0xd2,2,ACCR+TYPL,ACCW+TYPL,0,0,0,0),
OP("mcomw",0xb2,2,ACCR+TYPW,ACCW+TYPW,0,0,0,0),
OP("mfpr",0xdb,2,ACCR+TYPL,ACCW+TYPL,0,0,0,0),
OP("mnegb",0x8e,2,ACCR+TYPB,ACCW+TYPB,0,0,0,0),
OP("mnegd",0x72,2,ACCR+TYPD,ACCW+TYPD,0,0,0,0),
OP("mnegf",0x52,2,ACCR+TYPF,ACCW+TYPF,0,0,0,0),
OP("mnegl",0xce,2,ACCR+TYPL,ACCW+TYPL,0,0,0,0),
OP("mnegw",0xae,2,ACCR+TYPW,ACCW+TYPL,0,0,0,0),
OP("movab",0x9e,2,ACCA+TYPB,ACCW+TYPL,0,0,0,0),
OP("movad",0x7e,2,ACCA+TYPD,ACCW+TYPL,0,0,0,0),
OP("movaf",0xde,2,ACCA+TYPF,ACCW+TYPL,0,0,0,0),
OP("moval",0xde,2,ACCA+TYPL,ACCW+TYPL,0,0,0,0),
OP("movaq",0x7e,2,ACCA+TYPQ,ACCW+TYPL,0,0,0,0),
OP("movaw",0x3e,2,ACCA+TYPW,ACCW+TYPL,0,0,0,0),
OP("movb",0x90,2,ACCR+TYPB,ACCW+TYPB,0,0,0,0),
OP("movc3",0x28,3,ACCR+TYPW,ACCA+TYPB,ACCA+TYPB,0,0,0),
OP("movc5",0x2c,5,ACCR+TYPW,ACCA+TYPB,ACCR+TYPB,ACCR+TYPW,ACCA+TYPB,0),
OP("movd",0x70,2,ACCR+TYPD,ACCW+TYPD,0,0,0,0),
OP("movf",0x50,2,ACCR+TYPF,ACCW+TYPF,0,0,0,0),
OP("movl",0xd0,2,ACCR+TYPL,ACCW+TYPL,0,0,0,0),
OP("movp",0x34,3,ACCR+TYPW,ACCA+TYPB,ACCA+TYPB,0,0,0),
OP("movpsl",0xdc,1,ACCW+TYPL,0,0,0,0,0),
OP("movq",0x7d,2,ACCR+TYPQ,ACCW+TYPQ,0,0,0,0),
OP("movtc",0x2e,6,ACCR+TYPW,ACCA+TYPB,ACCR+TYPB,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB),
OP("movtuc",0x2f,6,ACCR+TYPW,ACCA+TYPB,ACCR+TYPB,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB),
OP("movw",0xb0,2,ACCR+TYPW,ACCW+TYPW,0,0,0,0),
OP("movzbl",0x9a,2,ACCR+TYPB,ACCW+TYPL,0,0,0,0),
OP("movzbw",0x9b,2,ACCR+TYPB,ACCW+TYPW,0,0,0,0),
OP("movzwl",0x3c,2,ACCR+TYPW,ACCW+TYPL,0,0,0,0),
OP("mtpr",0xda,2,ACCR+TYPL,ACCR+TYPL,0,0,0,0),
OP("mulb2",0x84,2,ACCR+TYPB,ACCM+TYPB,0,0,0,0),
OP("mulb3",0x85,3,ACCR+TYPB,ACCR+TYPB,ACCW+TYPB,0,0,0),
OP("muld2",0x64,2,ACCR+TYPD,ACCM+TYPD,0,0,0,0),
OP("muld3",0x65,3,ACCR+TYPD,ACCR+TYPD,ACCW+TYPD,0,0,0),
OP("mulf2",0x44,2,ACCR+TYPF,ACCM+TYPF,0,0,0,0),
OP("mulf3",0x45,3,ACCR+TYPF,ACCR+TYPF,ACCW+TYPF,0,0,0),
OP("mull2",0xc4,2,ACCR+TYPL,ACCM+TYPL,0,0,0,0),
OP("mull3",0xc5,3,ACCR+TYPL,ACCR+TYPL,ACCW+TYPL,0,0,0),
OP("mulp",0x25,6,ACCR+TYPW,ACCA+      TYPB,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB),
OP("mulw2",0xa4,2,ACCR+TYPW,ACCM+TYPW,0,0,0,0),
OP("mulw3",0xa5,3,ACCR+TYPW,ACCR+TYPW,ACCW+TYPW,0,0,0),
OP("nop",0x01,0,0,0,0,0,0,0),
OP("polyd",0x75,3,ACCR+TYPD,ACCR+TYPW,ACCA+TYPB,0,0,0),
OP("polyf",0x55,3,ACCR+TYPF,ACCR+TYPW,ACCA+TYPB,0,0,0),
OP("popr",0xba,1,ACCR+TYPW,0,0,0,0,0),
OP("prober",0x0c,3,ACCR+TYPB,ACCR+TYPW,ACCA+TYPB,0,0,0),
OP("probew",0x0d,3,ACCR+TYPB,ACCR+TYPW,ACCA+TYPB,0,0,0),
OP("pushab",0x9f,1,ACCA+TYPB,0,0,0,0,0),
OP("pushad",0x7f,1,ACCA+TYPD,0,0,0,0,0),
OP("pushaf",0xdf,1,ACCA+TYPF,0,0,0,0,0),
OP("pushal",0xdf,1,ACCA+TYPL,0,0,0,0,0),
OP("pushaq",0x7f,1,ACCA+TYPQ,0,0,0,0,0),
OP("pushaw",0x3f,1,ACCA+TYPW,0,0,0,0,0),
OP("pushl",0xdd,1,ACCR+TYPL,0,0,0,0,0),
OP("pushr",0xbb,1,ACCR+TYPW,0,0,0,0,0),
OP("rei",0x02,0,0,0,0,0,0,0),
OP("remqhi",0x5e,2,ACCA+TYPQ,ACCW+TYPL,0,0,0,0),
OP("remqti",0x5f,2,ACCA+TYPQ,ACCW+TYPL,0,0,0,0),
OP("remque",0x0f,2,ACCA+TYPB,ACCW+TYPL,0,0,0,0),
OP("ret",0x04,0,0,0,0,0,0,0),
OP("rotl",0x9c,3,ACCR+TYPB,ACCR+TYPL,ACCW+TYPL,0,0,0),
OP("rsb",0x05,0,0,0,0,0,0,0),
OP("sbwc",0xd9,2,ACCR+TYPL,ACCM+TYPL,0,0,0,0),
OP("scanc",0x2a,4,ACCR+TYPW,ACCA+TYPB,ACCA+TYPB,ACCR+TYPB,0,0),
OP("skpc",0x3b,3,ACCR+TYPB,ACCR+TYPW,ACCA+TYPB,0,0,0),
OP("sobgeq",0xf4,2,ACCM+TYPL,ACCB+TYPB,0,0,0,0),
OP("sobgtr",0xf5,2,ACCM+TYPL,ACCB+TYPB,0,0,0,0),
OP("spanc",0x2b,4,ACCR+TYPW,ACCA+TYPB,ACCA+TYPB,ACCR+TYPB,0,0),
OP("subb2",0x82,2,ACCR+TYPB,ACCM+TYPB,0,0,0,0),
OP("subb3",0x83,3,ACCR+TYPB,ACCR+TYPB,ACCW+TYPB,0,0,0),
OP("subd2",0x62,2,ACCR+TYPD,ACCM+TYPD,0,0,0,0),
OP("subd3",0x63,3,ACCR+TYPD,ACCR+TYPD,ACCW+TYPD,0,0,0),
OP("subf2",0x42,2,ACCR+TYPF,ACCM+TYPF,0,0,0,0),
OP("subf3",0x43,3,ACCR+TYPF,ACCR+TYPF,ACCW+TYPF,0,0,0),
OP("subl2",0xc2,2,ACCR+TYPL,ACCM+TYPL,0,0,0,0),
OP("subl3",0xc3,3,ACCR+TYPL,ACCR+TYPL,ACCW+TYPL,0,0,0),
OP("subp4",0x22,4,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,0,0),
OP("subp6",0x23,6,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB,ACCR+TYPW,ACCA+TYPB),
OP("subw2",0xa2,2,ACCR+TYPW,ACCM+TYPW,0,0,0,0),
OP("subw3",0xa3,3,ACCR+TYPW,ACCR+TYPW,ACCW+TYPW,0,0,0),
OP("svpctx",0x07,0,0,0,0,0,0,0),
OP("tstb",0x95,1,ACCR+TYPB,0,0,0,0,0),
OP("tstd",0x73,1,ACCR+TYPD,0,0,0,0,0),
OP("tstf",0x53,1,ACCR+TYPF,0,0,0,0,0),
OP("tstl",0xd5,1,ACCR+TYPL,0,0,0,0,0),
OP("tstw",0xb5,1,ACCR+TYPW,0,0,0,0,0),
OP("xfc",0xfc,1,ACCI+TYPB,0,0,0,0,0),
OP("xorb2",0x8c,2,ACCR+TYPB,ACCM+TYPB,0,0,0,0),
OP("xorb3",0x8d,3,ACCR+TYPB,ACCR+TYPB,ACCW+TYPB,0,0,0),
OP("xorl2",0xcc,2,ACCR+TYPL,ACCM+TYPL,0,0,0,0),
OP("xorl3",0xcd,3,ACCR+TYPL,ACCR+TYPL,ACCW+TYPL,0,0,0),
OP("xorw2",0xac,2,ACCR+TYPW,ACCM+TYPW,0,0,0,0),
OP("xorw3",0xad,3,ACCR+TYPW,ACCR+TYPW,ACCW+TYPW,0,0,0),
OP("escd",0xfd,0,0,0,0,0,0,0),
OP("esce",0xfe,0,0,0,0,0,0,0),
OP("escf",0xff,0,0,0,0,0,0,0),
Lq    ,   cmd/adb/vax/lib.h /*	@(#)lib.h	1.2	*/
/*
 *  Library call external declarations
 */

extern STRING environ;
extern int    errno;

extern char *ctime();
extern int  exect();
extern int  fprintf();
extern void longjmp();
extern void perror();
extern int  setjmp();
extern int  sprintf();
q    ",   cmd/adb/vax/mac.h /*	@(#)mac.h	1.2	*/
#
/*
 *	UNIX debugger
 */

#define TYPE	typedef
#define STRUCT	struct
#define UNION	union
#define REG	register

#define BEGIN	{
#define END	}

#define IF	if(
#define THEN	){
#define ELSE	} else {
#define ELIF	} else if (
#define FI	}

#define FOR	for(
#define WHILE	while(
#define DO	){
#define OD	}
#define REP	do{
#define PER	}while(
#define DONE	);
#define LOOP	for(;;){
#define POOL	}

#define SKIP	;
#define DIV	/
#define REM	%
#define NEQ	^
#define ANDF	&&
#define ORF	||

#define TRUE	 (-1)
#define FALSE	0
#define LOBYTE	0377
#define HIBYTE	0177400
#define STRIP	0177
#define HEXMSK	017

#define SP	' '
#define TB	'\t'
#define NL	'\n'
#define EOF	0

#define SCCSID(arg) static char Sccsid[] = "arg"
0q    4,   cmd/adb/vax/machine.h /*	@(#)machine.h	1.3	*/
/* 
 * VAX UNIX parameters 
 */

/* User block in core file */

#define ADDR_U ((unsigned) 0x7FFFF800)
#define ADRREG ((unsigned) 0x7B8)
union  Uuniontag {
    struct user strpart;
    char chrpart[ctob(USIZE)];
};

extern union Uuniontag Uunion;

/*  Note - the following define must appear after the above
 *  definition else the preprocessor will use the wrong u
 *  in the expansion of USIZE.
*/
#define u Uunion.strpart

/*
 *  Core layout for vax adb under unix 4.0
 *
 *                                TOP
 *             ---------------------------------------------
 *             |                                           |
 *             |               System Space                |
 *             |                                           |
 * 0x8000 0000 |-------------------------------------------|       -------
 * 0x7FFF FFFF |  (+0x7b8) registers (<- ksp)              |          ^
 *             |                  ^   System               |          |
 *             |            ar0 --|   Space                |          |
 *             |            pcb    (U-BLOCK)               |          |
 *             |-------------------------------------------| /e2      |
 * 0x7FFF F800 |               USP (core)                        |      u.u-ssize
 *             |                   |                       |          |
 *             |                   |                       |          |
 *             |                   v                       |          |
 *             |             (extended via                 |          |
 *             |             function call)                |          v
 *             |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| /b2   -------
 *             |                                           |
 *             |               NOT AVAILABLE               |
 *             |                                           |
 *             |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| /e1
 *             |                    ^                      |
 *             |      .bss + brk    | (extended via brk)   |
 *             |    a.out and core  | (extended via brk)   |
 *             |                    |                      |
 *             |-------------------------------------------| ?e2
 *             |                                           |
 *             |               DATA SPACE                  |
 *             |             a.out and core                |
 *             |                 .data                     |
 *             |                                           |
 * ((etext+511)|-------------------------------------------| ?b2 == /b1
 *  /512)*512  |                  padding                  |
 *      etext  |-------------------------------------------| ?e1
 *             |                                           |
 *             |                   TEXT                    |
 *             |                  (a.out)                  |
 *             |                                           |
 * 0x0000 0000 --------------------------------------------- ?b1
 *                                 BOTTOM
 */

/*
					Layout of a Core File

File Address    			    	  Source (Memory Address)
		-------------------------------
       0        >                             |            &u
		|    User block at time of    |
                |          core dump          |
                |                             |
                |-----------------------------|
  ctob(USIZE)   >                             | b1    ctob(u.u_tsize)
                |      User Data Segment      |
                |                             | e1
                |-----------------------------|
 ctob(USIZE) +  >                             | b2  0x80000000 - ctob(u.u_ssize)
ctob(u.u_dsize) |     User Stack Segment      |
                |                             |
                |-----------------------------| e2
ctob(USIZE) +   >
ctob(u.u_dsize) +
ctob(u.u_ssize - USIZE)
*/
q 	   Y,   %cmd/adb/vax/main.c ./*	@(#)main.c	1.2	*/
/*
 *  Main calling routine
 */

#include "defs.h"

SCCSID(@(#)main.c	1.2);

static jmp_buf env;
static int exitflg;
static int fault();
static int nocore();

struct termio usrtermio ;	/* Terminial state from user process */
struct termio adbtermio ;	/* Sane adb terminal state during breakpoint */

int usrfcntl ;
int adbfcntl ;

/* Set up files and initial address mappings */

main(argc, argv)
    STRING  *argv;
    int     argc;
{
/*	Initialize usrtermio and save the terminal state for use during	*/
/*	breakpoints.							*/

    ioctl(0,TCGETA,&usrtermio) ;
    ioctl(0,TCGETA,&adbtermio) ;
    adbfcntl = usrfcntl = fcntl(0,F_GETFL,0) ;

    mkioptab();

    while (argc > 1) {
        if (eqstr("-w", argv[1])) {
            wtflag = O_RDWR;
            argc--;
            argv++;
        }
        else
            break;
    }

    if (argc > 1)
        symfil = argv[1];
    if (argc > 2)
        corfil = argv[2];
    argcount = argc;

    setsym(); 
    setcor();

    /* Set up variables for user */
    maxoff = MAXOFF;
    maxpos = MAXPOS;
    var[VARB] = slshmap.b1 ? slshmap.b1 : qstmap.b1;
    var[VARD] = datsiz;
    var[VARE] = entrypt;
	var[VARF] = qstmap.f1;
    var[VARM] = magic;
    var[VARS] = stksiz;
    var[VART] = txtsiz;

    if ((sigint.siFUN = signal(SIGINT, SIG_IGN)) != SIG_IGN) { 
        sigint.siFUN = fault;
        if (-1 == (int) signal(SIGINT, fault))
			perror("main");
    }
    sigqit.siFUN = signal(SIGQUIT, SIG_IGN);
	if (-1 == (int) signal(SIGILL, nocore))
		perror("main");
	if (-1 == (int) signal(SIGIOT, nocore))
		perror("main");
	if (-1 == (int) signal(SIGEMT, nocore))
		perror("main");
	if (-1 == (int) signal(SIGFPE, nocore))
		perror("main");
	if (-1 == (int) signal(SIGBUS, nocore))
		perror("main");
	if (-1 == (int) signal(SIGSEGV, nocore))
		perror("main");
	if (-1 == (int) signal(SIGSYS, nocore))
		perror("main");

    (void) setjmp(env);

    if (executing && pid != 0)
        delbp();
    executing = FALSE;

    for ( ; ; ) {
        TRPRINT("* ");
        flushbuf();
        if (errflg != NULL) { 
            adbpr("%s\n", errflg);
            exitflg = (errflg != NULL); 
            errflg = NULL;
        }
        if (mkfault) {
            mkfault = FALSE; 
            printc(EOR); 
            prints(DBNAME);
        }
              lp = 0; 
        (void) rdc(); 
        lp--;
        if (eof) {
            if (infile) {
                iclose(); 
                eof = 0; 
                (void) longjmp(env, 0);
            }
            else
                done();
        }
        else
            exitflg = 0;

        command((STRING) NULL, lastcom);
        if (lp && lastc != EOR)
            error(NOEOR);
    }
}

int round(a, b)
    int a;
    int b;
{
    int w;

    w = (a / b) * b;
    w += (a != w) ? b : 0;
    return(w);
}

/* error handling */

void chkerr()
{
    if (errflg != NULL || mkfault)
        error(errflg);
}

void error(n)
    STRING n;
{
    errflg = n;
    iclose();
    oclose();
    (void) longjmp(env, 0);
}

static int fault(a)
{
    if (-1 == (int) signal(a, fault))
		perror("fault");
    if (-1 == lseek(infile, 0L, 2))
        perror("fault");
    mkfault = TRUE;
}

static int nocore()
{
	fprintf(stderr, "adb system failure -- exiting\n");
    (void) exit(1);
}

void done()
{
    endpcs();
    (void) exit(exitflg);
}
 q    X,   cmd/adb/vax/mode.h ./*	@(#)mode.h	1.2	*/
#include "machine.h"

typedef	char	 	    BOOL;
typedef	char		    *STRING;
typedef	char		    *MSG;
typedef	struct map	    MAP;
typedef	MAP		        *MAPPTR;
typedef	struct syment		SYMTAB;
typedef	SYMTAB			*SYMPTR;
typedef	struct symslave SYMSLAVE;
typedef	struct bkpt	    BKPT;
typedef	BKPT		    *BKPTR;

/* file address maps */
struct map {
	unsigned b1;
	unsigned e1;
	unsigned f1;
	unsigned b2;
	unsigned e2;
	unsigned f2;
	int      ufd;
};

/* slave table for symbols */
struct symslave {
	unsigned valslave;
	int  	 typslave;
};

#define MAXCOM 64
struct bkpt {
	int  loc;
	int  ins;
	int	 count;
	int	 initcnt;
	int  flag;
	char comm[MAXCOM];
	BKPT *nxtbkpt;
};

typedef	struct reglist REGLIST;
typedef	REGLIST		   *REGPTR;
struct reglist {
	STRING	rname;
	int  	roffs;
};

typedef union {
    int  siADDR;
    int (* siFUN)();
} SIGunion;

struct grres {				/* Returned by getreg */
	int sf;				/* Success/fail indicator */
	int roff;			/* Register offset on success */
} ;
 q    X,   4cmd/adb/vax/opcode.c  /*	@(#)opcode.c	1.3	*/
#include "defs.h"

SCCSID(@(#)opcode.c	1.3);

/*
 * Argument access types
 */
#define ACCA (8<<3) /* address only */
#define ACCR (1<<3) /* read */
#define ACCW (2<<3) /* write */
#define ACCM (3<<3) /* modify */
#define ACCB (4<<3) /* branch displacement */
#define ACCI (5<<3) /* XFC code */

/*
 * Argument data types
 */
#define TYPB 0 /* byte */
#define TYPW 1 /* word */
#define TYPL 2 /* long */
#define TYPQ 3 /* quad */
#define TYPF 4 /* floating */
#define TYPD 5 /* double floating */

#define ARPC (&reglist[1].rname)

typedef struct optab *OPTAB;
static struct optab {
    char *iname;
    char val;
    char nargs;
    char argtype[6];
} optab[] = {
#define OP(a,b,c,d,e,f,g,h,i) {a,b,c,d,e,f,g,h,i}
#include "instrs.h"
0};

static STRING fltimm[] = {
    "0.5",    "0.5625", "0.625", "0.6875", "0.75",  "0.8125", "0.875", 
    "0.9375", "1.0",    "1.125", "1.25",   "1.375", "1.5",    "1.625", 
	"1.75",   "1.875",  "2.0",   "2.25",   "2.5",   "2.75",   "3.0",
	"3.25",   "3.5",    "3.75",  "4.0",    "4.5",   "5.0",    "5.5", 
	"6.0",    "6.5",    "7.0",   "7.5",    "8.0",   "9.0",    "10.0",  
	"11.0",   "12.0",   "13.0",  "14.0",   "15.0",  "16.0",   "18.0",   
	"20.0",   "22.0",   "24.0",  "26.0",   "28.0",  "30.0",   "32.0",
	"36.0",   "40.0",   "44.0",  "48.0",   "52.0",  "56.0",   "60.0",
    "64.0",   "72.0",   "80.0",  "88.0",   "96.0",  "104.0",  "112.0",
	"120.0"
};

static int incp;
static int ioptab[256]; /* index by opcode to optab */
static void printfloating();
static void printquad();

void mkioptab()                 /* set up ioptab */
{
    OPTAB p;

    for (p = optab; p->iname; p++)
        ioptab[p->val & LOBYTE] = p - optab;
}

void printins(idsp, ins, pflag)
	int idsp;
	int ins;
	int pflag;
{
	int   argno;              /* argument index */
	int   mode;               /* mode */
	char  **r;                /* register name */
	int   d;                  /* assembled byte, word, long or float */
	char  *ap;
	OPTAB ip;

	ins &= LOBYTE;
	ip = optab + ioptab[ins];
	if(pflag) adbpr("%s%8t", ip->iname);
	incp = 1;
	ap = ip->argtype;
	for (argno = 0; argno < ip->nargs; argno++, ap++) {
		var[argno] = 0x80000000;
		if (argno != 0) 
		{
			if(pflag) printc(',');
		}
top:
		if (*ap & ACCB)
			mode = 0xAF + ((*ap & 07) << 5);
			/* branch displacement */
		else {
			mode = bchkget(inkdot(incp), idsp);
			++incp;
		}
		if (mode & 0300) {          /* not short literal */
			r = &reglist[(MAXREGS - 1) - (mode & 0xF)].rname;
			mode >>= 4;

			switch (mode) {
				case 4:           /* [r] */
					if(pflag) adbpr("[%s]", *r);
					goto top;

				case 5:           /* r */
					if(pflag) adbpr("%s", *r);
					break;

				case 6:           /* (r) */
					if(pflag) adbpr("(%s)", *r);
					break;

				case 7:           /* -(r) */
					if(pflag) adbpr("-(%s)", *r);
					break;

				case 9:           /* *(r)+ */
					if(pflag) printc('*');
				case 8:           /* (r)+ */
					if (r == ARPC) {
						if(pflag) print      c('$');
						/* PC absolute, always 4 bytes */
						if (mode == 9) {
							d = snarf(4, idsp);
							goto disp;
						}
						switch(*ap & 7) {

							case TYPB:
								d = snarf(1, idsp);
								goto disp;

							case TYPW:
								d = snarf(2, idsp);
								goto disp;

							case TYPL:
								d = snarf(4, idsp);
								goto disp;

							case TYPQ:
								d = snarf(4, idsp);
								if(pflag) printquad(d, snarf(4, idsp));
								break;

							case TYPF:
								if(pflag) printfloating(snarf(4, idsp), 0);
								break;

							case TYPD:
								d = snarf(4, idsp);
								if(pflag) printfloating(d, snarf(4, idsp));
								break;
						} /* End of type switch */
						/*
						 * Here only for TYPQ, TYPf, TYPD
						 * others went to disp
						*/
					}
					else        /* It's not PC immediate or abs */
						if(pflag) adbpr("(%s)+", *r);
					break;

				case 0xB:           /* byte displacement defferred */
					if(pflag) printc('*');
				case 0xA:           /* byte displacement */
					d = snarf(1, idsp);
					goto disp;

				case 0xD:           /* word displacement deferred */
					if(pflag) printc('*');
				case 0xC:           /* word displacement */
					d = snarf(2, idsp);
					goto disp;

				case 0xF:           /* long displacement deferred */
					if(pflag) printc('*');
				case 0xE:           /* long displacement */
					d = snarf(4, idsp);
					goto disp;
disp:
				var[argno] = d;
				if ((r == ARPC) && mode >= 0xA) {
					/* PC offset addressing */
					var[argno] += dot + incp;
					if(pflag) psymoff(var[argno], ISYM, "");
				}
				else
					if(pflag) psymoff(var[argno], DSYM, "");
				if (r != ARPC)
					if(pflag) adbpr("(%s)", *r);
				break;
			} /* end of the mode switch */
		} 
		else {   /* short literal */
			var[argno] = mode;
			if ((*ap & 07) == TYPF || (*ap & 07) == TYPD)
			{
				if(pflag) adbpr("$%s", fltimm[mode]);
			}
			else
				if(pflag) adbpr("$%r", mode);
		}
	}
	if (ins == 0xCF || ins == 0xAF || ins == 0x8F) { /* CASEx instr */
		for (argno = 0; argno <= var[2]; ++argno) {
			if(pflag) printc(EOR);
			if(pflag) adbpr("    %R:  ", argno + var[1]);
			d = get(inkdot(incp + argno + argno), idsp) & 0xFFFF;
			if (d & 0x8000) 
				d -= 0x10000;
			if(pflag) psymoff(((int) (inkdot(incp) + d)), DSYM, "");
		}
		incp += var[2] + var[2] + 2;
	}
	dotinc = incp;
}

/*
 * magic_masks check the sign bit
 * magic_compl is used to perform sign extension on bytes and
 * words when moved into a long
 */

                           /* 0   1      2       3  4 */
static long magic_masks[5] = {0, 0x80,  0x8000,  0, 0};
static long magic_compl[5] = {0, 0x100, 0x10000, 0, 0};

static int snarf(nbytes, idsp)
	int nbytes;
	int idsp;
{
	int byteindex;
	union {
		char int_bytes[4];
		int int_value;
	} d;

	d.int_value = 0; 
	for (byteindex = 0; byteindex < nbytes; byteindex++) {
		d.int_bytes[byteindex] = bchkget(inkdot(incp), idsp);
		++incp;
	}
	if (d.int_value & magic_masks[nbytes])
	d.int_value -= magic_compl[nbytes];
	return(d.int_value);
}

static void printfloating(word_first, word_last)
	int word_first;
	int word_last;
{
	union {
		struct {
			int word_first;
			int word_last;
		} composite;
		double dvalue;
	} reconstructed;

	reconstructed.composite.word_first = word_first;
	reconstructed.composite.word_last = word_last;
	adbpr ("%f", reconstructed.dvalue);
}

static void printquad(word_first, word_last)
	int word_first;
	int word_last;
{
	union {
		char quad_bytes[8];
		int  quad_int[2];
	} reconstructed;
	int leading_zero = 1;
	int byteindex;
	int nibbleindex;
	int ch;

	reconstructed.quad_int[0] = word_first;
	reconstructed.quad_int[1] = word_last;
	for (byteindex = 7; byteindex >= 0; --byteindex)
		for (nibbleindex = 4; nibbleindex >= 0; nibbleindex -= 4) {
			ch = (reconstructed.quad_bytes[byteindex] >> 
				  nibbleindex) & 0x0F;
			if ( ! (leading_zero &= (ch == 0))) {
				if (ch <= 0x09)
					printc(ch + '0');
				else
					printc(ch - 0x0A + 'a');
			}
		}
}
q    X,   cmd/adb/vax/output.c  /*	@(#)output.c	1.2	*/
#include "defs.h"

SCCSID(@(#)output.c	1.2);

static char printbuf[MAXLIN];
static char *printptr = printbuf;
static char *digitptr;
static void printdate();
static void printoct();
static void printnum();
static void printdbl();

int eqstr(s1, s2)
    STRING s1;
    STRING s2;
{
	return (!strcmp(s1,s2));
}

void printc(c)
    char c;
{
    char   d;
    STRING q;
    short  posn;
    short  tabs;
    short  p;

    if (mkfault)
		return; 
    else if ((*printptr = c) == EOR) {
        tabs = 0;
		posn = 0;
		q = printbuf;
		for (p = 0; p < printptr - printbuf; p++) {
			d = printbuf[p];
			if ((p & 07) == 0 && posn) {
				tabs++;
				posn = 0; 
			}
			if (d == SPACE)
				posn++; 
			else {
				while (tabs > 0 ) {
					*q++ = TB;
					tabs--; 
				}
				while (posn > 0 ) {
					*q++ = SPACE;
					posn--; 
				}
				*q++ = d;
			}
		}
		*q++ = EOR;
		if (-1 == write(outfile, printbuf, (unsigned) (q - printbuf)))
			perror("printc");
		printptr = printbuf;
	}
    else if (c == TB) {
		*printptr++ = SPACE;
        while ((printptr - printbuf) & 07)
			*prin      tptr++ = SPACE; 
    } 
    else if (c)
		printptr++;
}

charpos()
{
	return(printptr - printbuf);
}

void flushbuf()
{
	if (printptr != printbuf) 
		printc(EOR);
}

/*VARARGS1*/
void adbpr(fmat, a1)
    STRING fmat;
    STRING *a1;
{
    STRING  fptr;
    STRING  s;
    short   *vptr;
    int     *dptr;
    double  *rptr;
    short   width;
    short   prec;
    char    c;
    char    adj;
    short   x;
    short   n;
    int     lx;
    char    digits[64];

    fptr = fmat;
    vptr = (short *) &a1;
    dptr = (int *) vptr;

    while (c = *fptr++) {
		if (c != '%')
			printc(c);
		else {
			if (*fptr == '-' ) { 
				adj = 'l';
				fptr++;
			}
			else
				adj = 'r';
			width = convert(&fptr);
			if (*fptr == '.') {
				fptr++; 
				prec = convert(&fptr); 
			}
			else 
				prec = -1;
			digitptr = digits;
			rptr = (double *) dptr;
			x = shorten(lx = *dptr++);
		    s = 0;
		    switch (c = *fptr++) {

				case 'd':
                case 'u':
                    printnum(x, c, 10);
					break;

                case 'o':
					printoct((unsigned short)x, 0);
					break;
					
                case 'q':
					lx = x;
					printoct(lx, -1);
					break;

                case 'x':
                    printdbl(x, 16);
					break;

                case 'r':
                    printdbl(lx = x, radix);
					break;

                case 'R':
                    printdbl(lx, radix);
					vptr++;
					break;

                case 'Y':
                    printdate((long) lx);
					vptr++;
					break;

                case 'D':
                case 'U':
                    printdbl(lx, 10);
					vptr++;
					break;

                case 'O':
                    printoct(lx, 0);
					vptr++; 
					break;

                case 'Q':
                    printoct(lx, -1);
					vptr++;
					break;

                case 'X':
                    printdbl(lx, 16);
					vptr++;
					break;

                case 'c':
                    printc(x);
					break;

                case 's':
                    s = (char *) lx;
                    break;

                case 'f':
                case 'F':
                    dptr++;
                    (void) sprintf(s = digits, "%+.16e", *rptr, 
						*(rptr + 4)); 
                    prec = -1; 
                    break;

                case 'm':
                    vptr--;
					break;

                case 'M':
                    width = x;
					break;

                case 'T':
                case 't':
                    if (c == 'T')
						width = x;
                    else
						dptr--;
                    if (width)
						width -= charpos() % width;
                    break;

                default:
                    printc(c);
					dptr--;
			}

            if (s == 0) {
				*digitptr = 0;
				s = digits;
            }
            n = strlen(s);
            n = (prec < n && prec >= 0 ? prec : n);
            width -= n;
            if (adj == 'r') { 
				while (width-- > 0)
					printc(SPACE);
            }
            while (n--)
				printc(*s++);
            while (width-- > 0 )
				printc(SPACE);
            digitptr = digits;
		}
	}
}

static void printdate(tvec)
 	long tvec;
{
 	int    i;
 	STRING timeptr;

 	timeptr = ctime(&tvec);
 	for (i = 20; i < 24; i++) 
		*digitptr++ = *(timeptr + i);
 	for (i = 3; i < 19; i++) 
		*digitptr++ = *(timeptr + i);
}

void prints(s)
	char *s;
{
	adbpr("%s", s);
}

void newline()
{
    printc(EOR);
}

static int convert(cp)
	STRING *cp;
{
	char c;
    int  n;

	n = 0;
	while (((c = *(*cp)++) >= '0') && (c <= '9')) 
		n = n * 10 + c - '0';
	(*cp)--;
	return(n);
}

static void printnum(n, fmat, base)
    int n;
{
	char k;
	int  *dptr;
	int  digs[15];

	dptr = digs;
	if (n < 0 && fmat == 'd') {
		n = -n;
		*digitptr++ = '-'; 
	}
	while (n) {
		*dptr++ = ((unsigned) n) % base;
		 n = ((unsigned) n) / base;
	}
	if (dptr == digs) 
		*dptr++ = 0;
	while (dptr != digs) {  
		k = *--dptr;
		*digitptr++ = (k + (k <= 9 ? '0' : 'a' - 10));
	}
}

static void printoct(po, s)
    int po;
    int s;
{
    int  i;
    char digs[12];

    if (s) 
		if (po < 0) { 
			po = -po;
			*digitptr++ = '-';
        }
		else
			if (s > 0) 
				*digitptr++ = '+';
    for (i = 0; i <= 11; i++) { 
		digs[i] = po & 07;
		po >>= 3; 
	}
    digs[10] &= 03;
	digs[11] = 0;
    for (i = 11; i >= 0; i--)
		if (digs[i]) 
			break;
    for (i++; i >= 0; i--) 
		*digitptr++ = digs[i] + '0';
}

static void printdbl(lxy, base)
	int lxy;
	int base;
{ 
	char digs[35 * sizeof(int)];
	char *cp1;

    cp1 = digs; 
    if ((lxy & 0xFFFF0000L) == 0xFFFF0000L) {
        *cp1++ = '-'; 
        lxy = -lxy;
	}
	(void) sprintf(cp1, base==16 ? "%lx" : "%ld", lxy);
	cp1 = digs;
	while (*digitptr++ = *cp1++)
		;
	--digitptr;
}

void iclose()
{
    if (infile) {
		if (-1 == close(infile))
            perror("iclose");
	infile = 0;
    }
}

void oclose()
{
    if (outfile != 1) {
		flushbuf();
		if (-1 == close(outfile))
            perror("oclode");
		outfile = 1;
    }
}

void endline()
{
    if (maxpos <= charpos()) 
		adbpr("\n");
}
q    [,   tcmd/adb/vax/pcs.c /*	@(#)pcs.c	1.2	*/
/*       
 *  Subprocess control 
 */

#include "defs.h"

SCCSID(@(#)pcs.c	1.2);

void subpcs(modif)
    char modif;
{
    int    check;
    int    execsig;
    int    runmode;
    int    oldflag;
    BKPTR  bkptr;
    STRING comptr;
    
    execsig = 0;
    loopcnt = cntval;
    
    switch (modif) {
    
        case 'd':
        case 'D':                     /* delete breakpoint */
            if (bkptr = scanbkpt(dot)) {
                bkptr->flag=0;
                return;
            } 
            else
                error(NOBKPT);
    
        case 'b':
        case 'B':           /* set breakpoint */
            oldflag = 0;
            if (bkptr = scanbkpt(dot)) { 
                if (bkptr->flag == BKPTEXEC) 
                    oldflag = 1;
                    bkptr->flag = 0;
            }
            for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt)
                if (bkptr->flag == 0) 
                    break;
            if (bkptr == 0)
                if (((int) (bkptr = (BKPTR) sbrk(sizeof *bkptr))) == -1) 
                    error(SZBKPT);
                else { 
                    bkptr->nxtbkpt = bkpthead;
                    bkpthead = bkptr;
                }
            bkptr->loc = (findsym(dot, ISYM) == 0) ? dot+2 : dot;
            bkptr->initcnt = bkptr->count = cntval;
            bkptr->flag = oldflag ? BKPTEXEC : BKPTSET;
            check = MAXCOM - 11;
            comptr = bkptr->comm;
            (void) rdc();
            lp--;
            do { 
                *comptr++ = readchar();
            } while (check-- && lastc != EOR);
                *comptr = 0;
            lp--;
            if (check)
                return;
            else
                error(EXBKPT);
    
        case 'k':
        case 'K':             /* exit */
            if (pid) { 
                adbpr("%d: killed", pid);
                endpcs();
                return;
            }
            else
                error(NOPCS);
    
        case 'r':
        case 'R':                    /* run program */
            endpcs();
            setup();
            runmode = CONTIN;
            break;
    
        case 's': 
        case 'S':                         /* single step */
            if (pid) {
                runmode = SINGLE;
                execsig = getsig(signo);
            }
            else { 
                setup();
                loopcnt--;
            }
            break;
    
        case 'c': 
        case 'C': 
        case 0:          /* continue with optional signal */
            if (pid == 0) 
                error(NOPCS);
            runmode = CONTIN;
            execsig = getsig(signo);
            break;
    
        default:
            error(BADMOD);
    }
    
    if (loopcnt > 0 && runpcs(runmode,execsig)) 
        adbpr("breakpoint%16t");
    else
        adbpr("stopped at%16t");
    delbp();
    printpc();
}
q    a,   cmd/adb/vax/print.c /*	@(#)print.c	1.2	*/
/* 
 *  General printing routines
 */

#include "defs.h"

SCCSID(@(#)print.c	1.2);

static STRING signals[] = {
"",
"hangup",
"interrupt",
"quit",
"illegal instruction",
"trace/BPT",
"IOT",
"EMT",
"floating exception",
"killed",
"bus error",
"memory fault",
"bad system call",
"broken pipe",
"alarm call",
"terminated",
"user defined - 1",
"user defined - 2",
"death of a child",
"power fail",
};

static void printregs();
static void printmap();

void dollar(modif)
int modif;
{
short  narg;
short  i;
BKPTR  bkptr;
int    word;
STRING comptr;
int    argp;
int    frame;
int    oldframe;
SYMPTR symp;
int newest;
int j;

if (cntflg == FALSE)
	cntval = -1;

switch (modif) {

	case '<':
	case '>': {
		char  userfile[64];
		short index;

		index = 0;
		if (modif == '<')
			iclose();
		else
			oclose();
		if (rdc() != EOR) {
			do { 
				userfile[index++] = lastc;
				if (index >= 63)
						error(LONGFIL);
			} while (readchar() != EOR);
			userfile[index] = 0;
			if (modif == '<') { 
				infile = open(userfile, 0);
				if (infile < 0) {
						infile = 0; 
						error(NOTOPEN);
				}
			}
			else { 
				outfile = open(userfile, 1);
				if (outfile < 0)
						outfile = creat(userfile, 0644);
				else 
						if (-1L == lseek(outfile, 0L, 2))
						    perror("dollar");
			}
		}
		lp--;
		}
		break;

	case 'd':
		if (adrflg) {
			if (adrval < 2 || adrval > 16)
				error(BADRAD);
			radix = adrval;
		}
			else
				radix = DEFRADIX;
		break;

	case 'o':
	   radix = 8;
	   break;

	case 'q': 
	case 'Q': 
	case '%':
		done();

	case 'w':
	case 'W':
		maxpos = (adrflg ? adrval : MAXPOS);
		break;

	case 's': 
	case 'S':
		maxoff = (adrflg ? adrval : MAXOFF);
		break;

	case 'v': 
	case 'V':
		prints("variables\n");
		for (i = 0; i < VARNO; i++)
			if (var[i]) {
				printc((i <= 9 ? '0' : 'a' - 10) + i);
				adbpr(" = %R\n",var[i]);
			}
		break;

	case 'm': 
	case 'M':
		printmap("? map", &qstmap);
		printmap("/ map", &slshmap);
		break;

	case   0: 
	case '?':
		if (pid)
			adbpr("pcs id = %d\n", pid);
		else
			prints("no process\n");
		sigprint();
		flushbuf();

	case 'r':
	case 'R':
		printregs();
		return;

	case 'c':
      	case 'C':
		if (adrflg)
		{
			frame = adrval;
			callpc = get(frame+16, DSP);
			callpc += get(callpc-4, ISP);
			word = get(adrval + 6, DSP) & 0xFFFF;
			if (word & 0x2000) /* 'calls', can figure out argp */
			{
				argp = adrval + 20 + ((word >> 14) & 3); 
				word &= 0xFFF;
				while (word) 
				{
					if (word & 1)
						    argp += 4;
						word >>= 1; 
				}
			}
			else     /* 'callg', can't tell where argp is */ 
				argp = frame;
		}
		else
		{
			argp = ADBREG(AP);
			frame = ADBREG(FP);
			callpc = ADBREG(PC);
		}
		newest = 1;
		while (cntval--) {
			chkerr();
			adbpr("%s(", findsym(callpc, ISYM) == 
						   0x7fffffffL ? "?" : symbol.n_nptr);
			narg = get(argp, DSP);
			if (narg & ~0xFF)
				narg = 0;
			for ( ; ; ) { 
				if (narg == 0)
					break;
				adbpr("%R", get(argp += 4, DSP));
				if (--narg != 0)
					printc(',');
			}
			prints(")\n");

			if (modif == 'C') 
			{
				j=get((newest?frame:oldframe)+6,DSP)&0xffff;
				if(j&0x2000)
					argp=calcap(newest?frame:oldframe,j);
				else
					argp=0;
				localsym(newest?frame:oldframe,argp,newest);
				newest = 0;
				for(j=0;(j<numlocs)&&argp;j++)
				{
					localval=expv=locadr-(4*j);
					word=get(localval,DSP);
					adbpr("%8t%s.%X% = ", symbol.n_nptr,j);
					if (errflg != NULL) {
						prints("?\n"); 
						errflg = NULL; 
					}
					else 
						adbpr("%R\n", word); 
				}
			}
			callpc = get(frame+16, DSP);
			argp = get(frame+8, DSP);
			oldframe = frame;
			frame = get(frame+12, DSP) & EVEN;
			if (frame == 0 || frame <= oldframe)
				break;
		}
		break;

	case 'e': 
	case 'E':            /* Print externals */
		symset();
		while (symp = symget()) {
			chkerr();
			if (((symp->n_scnum == 3 || symp->n_scnum == 2) &&
				symp->n_sclass == C_EXT) ||
				(symp->n_scnum == 0 &&
				symp->n_sclass == C_EXT && symp->n_value != 0))
			{
				adbpr("%s:%12t%R\n", symp->n_nptr,
						get((int) symp->n_value, DSP));
			}
			skip_aux(symp);
		}
		break;

	case 'b':           /* print breakpoints */
	case 'B':           /* set default c frame */
		adbpr("breakpoints\ncount%8tbkpt%24tcommand\n");
		for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt) {
			if (bkptr->flag) {
				adbpr("%-8.8d", bkptr->count);
				psymoff(bkptr->loc, ISYM, "%24t");
				comptr = bkptr->comm;
				while (*comptr)
						printc(*comptr++);
			}
			}
		break;

	case 't':
		trace = ! trace;
		break;

	default: 
		error(BADMOD);
}
}

static void printmap(s, amap)
STRING s;
MAP    *amap;
{
int fid;

fid = amap->ufd;
adbpr("%s%12t`%s'\n", s, (fid < 0 ? "-" : 
		(fid == fcor ? corfil : symfil)));
adbpr("b1 = %-16R", amap->b1);
adbpr("e1 = %-16R", amap->e1);
adbpr("f1 = %-16R", amap->f1);
adbpr("\nb2 = %-16R", amap->b2);
adbpr("e2 = %-16R", amap->e2);
adbpr("f2 = %-16R", amap->f2);
printc(EOR);
}
   
static void printregs()
{
REGPTR p;
int    v;

for (p = reglist; p < &reglist[MAXREGS]; p++) { 
	v = ADBREG(p->roffs);
	adbpr("%s%6t%R %16t", p->rname, v);
	valpr(v, (p->roffs == PC ? ISYM : DSYM));
	printc(EOR);
}
printpc();
}

struct grres getreg(regnam)
int regnam;
{
REGPTR p;
STRING regptr;
char   *olp;
	struct grres result;

	result.sf = 0;
	result.roff = 0;

olp = lp;
for (p = reglist; p < &reglist[MAXREGS]; p++) { 
	regptr = p->rname;
	if (regnam == *regptr++) {
		while (*regptr) { 
			if (readchar() != *regptr++) { 
				--regptr;
				break;
			}
		}
		if (*regptr)
			lp = olp;
		else {
				result.sf = 1;
			result.roff = p->roffs;
				return(result);
			}
	}
}
lp = olp;
return(result);
}

void printpc()
{
dot = ADBREG(PC);
psymoff(dot, ISYM, ":%16t"); 
printins(ISP, (int) chkget(dot, ISP), 1);
printc(EOR);
}

void sigprint()
{
if ((signo >= 0) && (signo <= NSIG))
prints(signals[signo]);
}
Aq    KW,   =cmd/adb/vax/runpcs.c  /*	@(#)runpcs.c	1.2	*/
/* 
 *  Service routines for subprocess control 
 */

#include "defs.h"

SCCSID(@(#)runpcs.c	1.2);

#define BPOUT 0
#define BPIN 1

static int  bpstate = BPOUT;
static int  userpc = 1;
static void doexec();
static void setbp();
static void bpwait();
static void readregs();

int getsig(sig)
    int sig;
{
    return(expr(0) ? expv : sig);
}

int runpcs(runmode,execsig)
    int runmode;
    int execsig;
{
    int   rc;
    BKPTR bkpt;
    extern int usrfcntl ;

    if (adrflg) {
        if (bkpt = scanbkpt(userpc))
			bkpt->flag = BKPTSET; 
        userpc = dot;
    }
    adbpr("%s: running\n", symfil);

    setbp();
    while (--loopcnt >= 0) {
        if ((bkpt = scanbkpt(userpc)) && (bkpt->flag == BKPTEXEC)) {
            dot = bkpt->loc;
            execbkpt(bkpt, execsig);
            execsig = 0;
            if (runmode == CONTIN) { 
		fcntl(0,F_SETFL,usrfcntl) ;
                if (-1 == ptrace(runmode, pid, userpc, execsig))
                    perror("runpcs");
                bpwait();
				chkerr();
				execsig = 0;
				readregs();
            }
        }
		else {
            if (-1 == ptrace(runmode, pid, userpc, execsig))
                perror("runpcs");
            bpwait();
			chkerr();
			execsig = 0;
			readregs();
        }

        if ((signo == 0) && (bkpt = scanbkpt(userpc))) {
            bkpt->flag = BKPTEX      EC;
            --bkpt->count;
            command(bkpt->comm, ':');
            if ((bkpt->count == 0)) { 
				bkpt->count = bkpt->initcnt;
				rc = 1;
				loopcnt = 0;
            }
			else
                if (runmode == CONTIN)
					loopcnt++;
        } 
		else { 
			execsig = signo;
			rc = 0;
        }
    }
    return(rc);
}

void endpcs()
{
    BKPTR bkptr;

    if (pid) {
		(void) ptrace(EXIT, pid, 0, 0);
		pid = 0;
		userpc = 1;
        for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt)
			if (bkptr->flag) 
				bkptr->flag = BKPTSET;
    }
    bpstate = BPOUT;
}

void setup()
{
    if (-1 == close(fsym))
        perror("setup");
    fsym = -1;
    if ((pid = fork()) == 0) { 
		(void) ptrace(SETTRC, 0, 0, 0);
        if (-1 == (int) signal(SIGINT, sigint.siFUN))
			perror("setup");
		if (-1 == (int) signal(SIGQUIT, sigqit.siFUN))
			perror("setup");
        doexec(); 
		(void) exit(0);
    } 
    else if (pid == -1) 
		error(NOFORK);
    else { 
		bpwait();
		errno = 0;
		if ((-1 == (int) (u.u_ar0 = (int *) ptrace(RUREGS, 
			pid, (int) (((char *) &u.u_ar0) - ((int) &u)), 0))) && 
			(errno != 0))
			perror("setup");
        u.u_ar0 = (int *) (((char *) u.u_ar0) - ADDR_U);
        u.u_ar0 = (int *) (((char *) u.u_ar0) + (int) &u);
		readregs();
		lp[0] = EOR;
		lp[1] = 0;
        if (-1 == (fsym = open(symfil, wtflag)))
            perror("setup");
        if (errflg != NULL) { 
			(void) fprintf(stderr, "%s: cannot execute\n", symfil);
            endpcs();
			error((STRING) NULL);
        }
    }
    bpstate=BPOUT;
}

static execbkpt(bkptr, execsig)
    BKPTR bkptr;
    int execsig;
{
    extern struct termio usrtermio ;
    extern int usrfcntl ;

    delbp();
    ioctl(0,TCSETAF,&usrtermio) ;
    fcntl(0,F_SETFL,usrfcntl) ;
    (void) ptrace(SINGLE, pid, bkptr->loc, execsig);
    bkptr->flag = BKPTSET;
    bpwait(); 
    chkerr(); 
    readregs();
    setbp();
}


static void doexec()
{
    STRING argl[MAXARG];
    char   args[LINSIZ];
    STRING p = args;
    STRING *ap = argl;
    STRING filnam;

    *ap++ = symfil;
    do { 
		if (rdc() == EOR) 
			break;
        *ap = p;
        while (lastc != EOR && lastc != SPACE && lastc != TB) { 
			*p++ = lastc;
			(void) readchar(); 
		}
        *p++ = 0;
		filnam = *ap + 1;
        if (**ap == '<') {
			if (-1 == close(0))
                perror("doexec");
            if (open(filnam, 0) == -1) { 
				perror("doexec");
                (void) exit(0);
            }
        } 
		else if (**ap == '>') {
			if (-1 == close(1))
                perror("doexec - close 2");
            if (creat(filnam, 0666) == -1) { 
				perror("doexec - creat");
                (void) exit(0);
            }
        }
		else 
			ap++;
    } while (lastc != EOR);
    *ap++ = 0;
    if (-1 == exect(symfil, argl, environ))
        perror("doexec - exect");
}

BKPTR scanbkpt(adr)
    int adr;
{
    BKPTR bkptr;

    for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt)
		if (bkptr->flag && bkptr->loc == adr)
			break;

    return(bkptr);
}

void delbp()
{
    int   a;
    BKPTR bkptr;
    int   ptrres;

    if (bpstate != BPOUT) {
        for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt) {  
			if (bkptr->flag) { 
				a = bkptr->loc;
				errno = 0;
                if ((-1 == (ptrres = ptrace(RIUSER, pid, a, 0))) && 
					(errno != 0))
                    perror("delbp");
				errno = 0;
                if ((-1 == ptrace(WIUSER, pid, a, 
					(bkptr->ins & 0xFF) | (ptrres & ~0xFF))))
                    perror("delbp");
            }
        }
        bpstate = BPOUT;
    }
}

static void setbp()
{
    int   a;
    BKPTR bkptr;

    if (bpstate != BPIN) {
        for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt) { 
			if (bkptr->flag) { 
				a = bkptr->loc;
				errno = 0;
                bkptr->ins = ptrace(RIUSER, pid, a, 0);
                if ((errno != 0) && (-1 == bkptr->ins))
                    perror("setbp");
				errno = 0;
                if ((-1 == ptrace(WIUSER, pid, a, BPT | 
					(bkptr->ins&~0xFF)))) { 
					prints("cannot set breakpoint: ");
                    psymoff(bkptr->loc, ISYM, "\n");
                }
            }
        }
		bpstate = BPIN;
    }
}

static void bpwait()
{
    int w;
    int stat;
    extern struct termio adbtermio,usrtermio ;
    extern int adbfcntl,usrfcntl ;

    if (-1 == (int) signal(SIGINT, SIG_IGN))
		perror("bpwait");
    while ((w = wait(&stat)) != pid && w != -1 )
		;
    if (-1 == (int) signal(SIGINT, sigint.siFUN))
		perror("bpwait");

/*	Save the terminal state that the process had and restore a	*/
/*	state that can be used for talking to adb.			*/

    ioctl(0,TCGETA,&usrtermio) ;
    ioctl(0,TCSETAF,&adbtermio) ;
    usrfcntl = fcntl(0,F_GETFL,0) ;
    fcntl(0,F_SETFL,adbfcntl) ;

    if (w == -1) { 
		pid = 0;
        errflg = BADWAIT;
    }
    else if ((stat & 0177) != 0177) { 
		if (signo = stat & 0177)
			sigprint();
        if (stat & 0200) { 
			prints(" - core dumped");
            if (-1 == close(fcor))
                perror("bpwait");
            setcor();
        }
        pid = 0;
        errflg = ENDPCS;
    }
          else { 
		signo = stat >> 8;
        if (signo != SIGTRAP)
			sigprint();
        else 
			signo = 0;
        flushbuf();
    }
}

static void readregs()      /* Get register values from child */
{
    int i;
    int ptrres;

    for (i = 0; i < MAXREGS; i++) { 
		errno = 0;
		if ((-1 == (ptrres = ptrace(RUREGS, pid,
		    SYSREG(reglist[i].roffs), 0))) && (errno != 0))
            perror("readregs");
        ADBREG(reglist[i].roffs) = ptrres;
    }
    userpc = ADBREG(PC);
}
Tq    WW,   Rcmd/adb/vax/setup.c /*	@(#)setup.c	1.2	*/
#include "defs.h"

SCCSID(@(#)setup.c	1.2);

#define TXTRNDSIZ 512


void setsym()
{
	SYMSLAVE    *symptr;
	char numaux;
	SYMPTR      symp;
	AOUTHDR aouthdr;
	FILHDR filehdr;
	SCNHDR scnhdr;

	qstmap.ufd = fsym = getfile(symfil, 1);
	if((read(fsym,(char *) &filehdr,FILHSZ) == FILHSZ) && filehdr.f_opthdr)
	{
		read(fsym, (char *) &aouthdr, filehdr.f_opthdr);
		magic = aouthdr.magic;
		txtsiz = (aouthdr.tsize & ~0x80000000) ;
		datsiz = (aouthdr.dsize & ~0x80000000) ;
		entrypt = aouthdr.entry;
	}
	symbas = filehdr.f_symptr;
	symnum = filehdr.f_nsyms;
#ifdef DEBUG
	printf("symnum=%x\n",symnum);
#endif
	read(fsym, (char *) &scnhdr, SCNHSZ);
	qstmap.b1 = 0;
	qstmap.e1 = txtsiz;
	qstmap.f1 = scnhdr.s_scnptr;
	read(fsym, (char *) &scnhdr, SCNHSZ);
	qstmap.b2 = (magic == 0410 ? round(txtsiz, TXTRNDSIZ) : txtsiz);
	qstmap.e2 = qstmap.b2 + datsiz;
	qstmap.f2 = scnhdr.s_scnptr;
#ifdef DEBUG
	printf("symbas=%x\n", symbas);
#endif

	symvec = (SYMSLAVE *) sbrk((1 + symnum) * sizeof (SYMSLAVE));
	if (((int) (symptr = symvec)) == -1) 
	{
		(void) fprintf(stderr, "%s\n", BADNAM);
		symptr = symvec = (SYMSLAVE *) sbrk(sizeof (SYMSLAVE));
		if (-1 == (int) symvec)
	            perror("setsym");
	}
	else 
	{
		readstrtbl( fsym, filehdr );
	        symset();
	        while ((symp = symget()) && errflg == NULL) 
		{
			if(symp->n_sclass<C_NULL||symp->n_sclass>=C_BLOCK||
				eqstr(symp->n_nptr, ".text")||
				eqstr(symp->n_nptr, ".data")||
				eqstr(symp->n_nptr, ".bss"))
			{
				symptr->typslave = N_DEBUG;
				symptr->valslave = 0;
				symptr++;
			}
			else
			{
				symptr->typslave = typesym( symp->n_scnum);
				symptr->valslave = symp->n_value;
				symptr++;
		        }
			/* get rid of auxilliary entries */
			skip_aux(symp);
			numaux = symp->n_numaux;
			while(numaux)
			{
				symptr->typslave = N_DEBUG;
				symptr->valslave = 0;
				symptr++;
				numaux--;
			}
		}
	    }
	symptr->typslave = ENDSYMS;
	if (magic == 0)
	qstmap.e1 = maxfile;
}

void setcor()
{
    slshmap.ufd = fcor = getfile(corfil, 2);
    if (read(fcor, (char *) &u, ctob(USIZE)) == ctob(USIZE) && 
	((unsigned) u.u_pcb.pcb_ksp) >= ADDR_U && 
	((unsigned) u.u_pcb.pcb_ksp) < maxstor && 
	((unsigned) u.u_pcb.pcb_usp) < maxstor) { 

	/* u.u_ar0 is an address relative to the incore UBLOCK
	   currently 0x7FFF FFB8.  It must be transformed to be
	   relative to u, a variable in adb's data space.   */

	u.u_ar0 = (int *) (((char *) u.u_ar0) - ADDR_U);
	u.u_ar0 = (int *) (((char *) u.u_ar0) + (int) &u);

	txtsiz = ctob(u.u_tsize);
	datsiz = ctob(u.u_dsize);
	stksiz = ctob(u.u_ssize);
	slshmap.b1 = ((magic == 0410 || magic == 0411) ? txtsiz : 0);
	slshmap.e1 = (magic == 0407 ? txtsiz : slshmap.b1) + datsiz;
	slshmap.f1 = ctob(USIZE);
	slshmap.b2 = maxstor - stksiz;
	slshmap.e2 = maxstor - ctob(USIZE);
	slshmap.f2 = ctob(USIZE) + ((magic==0410 || magic==0411) ?
			datsiz : slshmap.e1);
	signo = u.u_arg[0] & 017;
	if (magic && magic != u.u_exdata.ux_mag)
	    (void) fprintf(stderr, "%s\n", BADMAGIC);
    }
    else
		u.u_ar0 = (int *) (((int) &u) + ADRREG);
}

static int create(f)
    STRING f;
{
    int fd;

    if ((fd = creat(f, 0644)) != -1) { 
	if (-1 == close(fd))
	    perror("create");
	return(open(f, wtflag));
    }
    else 
	return(-1);
}

static int getfile(filnam, cnt)
    STRING filnam;
{
    int symfid;

    if ( ! eqstr("-", filnam)) { 
	symfid = open(filnam, wtflag);
	if (symfid == -1 && argcount > cnt) { 
	    if (wtflag == O_RDWR)
	        symfid = create(filnam);
	    if (symfid == -1)
	        (void) fprintf(stderr, "Cannot open `%s'\n", filnam);
	}
    }
    else
	symfid = -1;
    return(symfid);
}

static int typesym(sflag) /* Returns the space to look in for value */
    short sflag;
{
	if(sflag == N_DEBUG)
		return(EXTRASYM);
    switch (sflag) {
	
	case SECT1:
	    return(ISYM);

	case SECT2:
	case SECT3:
	    return(DSYM);

	default:
	    return(NSYM);
    }
}
q    ]W,   cmd/adb/vax/sym.c /*	@(#)sym.c	1.3	*/
/* 
 *  Symbol table and file handling service routines
 */

#include "defs.h"

SCCSID(@(#)sym.c	1.3);

#define	ERROR	(-1)		/* Signifies something is wrong */
static int     symcnt;
static int     symrqd = TRUE;
static SYMTAB  symbuf;     	/* Room for 1 symbol */
static	long curoffs = (ERROR -1);
static	char	*strtab;	/* String for string table. */
struct	sh_name{
	char	name[ 9 ];
};
static	struct	sh_name	*shstrtab;	/* Space for all names contained */
					/* in symbol table. */
static	long	strtablen;


void valpr(v, idsp)
    int v;
    int idsp;
{
    unsigned d = findsym(v, idsp);

    if (d < max      off) {
		adbpr("%s", symbol.n_nptr);
        if (d)
			adbpr(OFFMODE, d);
    }
}

/*ARGSUSED*/
void localsym(cframe,cargp,newest)
	int cframe;
	int cargp;
	int newest;
{
	int word;
	if(!newest)
	{
		word = cargp + (get(cargp, DSP)+1)*4;
		locadr = (get(cframe+12,DSP)-4);
		numlocs = ((locadr - word)/4)+1;
	}
	else
	{
		numlocs = (cframe - ADBREG(SP))/4;
		locadr = cframe;
	}
}

void psymoff(v, symtype, s) /* Prints symbol, offset, and suffix */
	int  v;
	int  symtype;
	char *s;                       /* Suffix for print line */
{
    unsigned w;

    if (v != 0) 
		w = findsym(v, symtype);
    if (v == 0 || w >= maxoff)     /* || (v>=0 && v<maxoff && w!=0) */
		adbpr(LPRMODE, v);
    else { 
		adbpr("%s", symbol.n_nptr);
        if (w)
			adbpr(OFFMODE, w);
    }
    adbpr(s);
}

/* added long rdsym( offset, symep )
 *	Stores symbol in location pointed to by symep.
 *	Returns offset for next syment
 *	Seeks done here if necessary; removed from other symt.c code
 *	for COFF, always just 0 or 1 auxiliary entries
 */

long
rdsym( offset, symep )
long offset;
register SYMENT *symep;
{
	register int numaux;

	if(offset <= 0 || offset >= symbas + symnum * SYMESZ)
		return(ERROR);
	lseek( fsym, offset, 0 );
	curoffs = offset;
	if ( read( fsym, (char *)symep, SYMESZ) < SYMESZ)
	{
		curoffs = ERROR -1;
		return(ERROR);
	}
#ifdef FLEXNAMES
	if( symep->n_zeroes == 0 )
	{
		if (symep->n_offset < 4 || symep->n_offset > strtablen)
		{
			printf("Bad string table offset @ 0x%lx\n",
				curoffs - SYMESZ);
			return (ERROR);
		}
		symep->n_nptr = &strtab[ symep->n_offset ];
	}
	else
#endif
	{
		long	i = offset - symbas;
		i /= SYMESZ;
		strncpy( shstrtab[ i ].name, symep->n_name, SYMNMLEN );
		shstrtab[ i ].name[ 8 ] = '\0';
		symep->n_zeroes = 0;
		symep->n_offset = 0;
		symep->n_nptr = shstrtab[ i ].name;
	}
/*
**	printf("Found name `%s'\n", symep->n_nptr);
*/
	curoffs += SYMESZ;
	return(curoffs);
}

/*	skip_aux - skip auxilliary entries

	input - symp = symbol just read
*/
long
skip_aux( symp )
register SYMENT *symp;
{
	register int numaux = symp->n_numaux;

	curoffs += numaux * AUXESZ;
	return(curoffs);
}

unsigned findsym(value, symtype) /* Linear search through slave array */
    int value;
    int symtype;
{
/* 
 *  Linear search through slave array; finds the symbol closest
 *  above value
 */
    int      diff;
    int      symval;
    int      offset;
    int      slvtype;
    SYMSLAVE *symptr;
    SYMSLAVE *symsav;

    diff = 0x7fffffffL;
    symsav = 0;
    if (symtype != NSYM && (symptr = symvec)) { 
		while (diff && (slvtype = symptr->typslave) != ENDSYMS) {  
			if (((slvtype == symtype) || ((symtype == IDSYM) &&
				((slvtype == DSYM) || (slvtype == ISYM)))) &&
				(slvtype != EXTRASYM)) {
				symval = symptr->valslave;
                if (value - symval < diff && value >= symval) {
					diff = value - symval;
                    symsav = symptr;
                }
            }
            symptr++;
        }
        if (symsav) {      /* Best entry */
	    int ret;
            offset = symsav - symvec;
            symcnt = symnum - offset;
	    ret = rdsym((long)(symbas + offset * SYMBOLSIZE), &symbol);
	    if (ret == ERROR)
                perror("findsym");
        }
    }
    return(diff);
}

/*		---------UNUSED----------
*static int nextsym()
*{
*    if (--symcnt < 0)
*		return(FALSE);
*    else {
*	    if ( rdsym( (long) (symbas + (symnum -symcnt) * SYMBOLSIZE),
*	    		&symbol ) == ERROR )
*	    {
*			return(FALSE);
*	    }
*	    return( TRUE );
*    }
*}
*/

/* sequential search through file */
void symset()
{
	if (-1L == lseek(fsym, (long) symbas, 0))
		perror("symset");
	curoffs = (long) symbas;
	(void) symread();
	curoffs = (long) symbas;
} 

SYMPTR symget()
{
	if (curoffs >= symbas + symnum * SYMESZ)
		return ((SYMPTR)NULL);
	if (symread())
		return (&symbuf);
	else
	{
		errflg = BADFIL;
		return ((SYMPTR)NULL);
	}
}
/*
	Note to future maintainers: this code used to be
	buffered in symbuf, but no longer is.  There is
	much remaining extraneous code.
*/

static int symread()
{
    if (rdsym(curoffs, &symbuf) == ERROR)
    {
	perror("symread");
	return (FALSE);
    }
    else
        return (TRUE);
}
int
readstrtbl( fd, filehdr)
int  fd;
FILHDR filehdr;
{
	extern char *sbrk();
	long home;
	register int i;

	home = lseek( fd, 0L, 1 );
	if ( lseek( fd, symbas, 0 ) == -1 )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	i = (((filehdr.f_nsyms + 1) * sizeof(struct sh_name)) + 3) & ~3;
	if ((shstrtab = (struct sh_name *)sbrk(i)) == (struct sh_name *)(-1))
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if ( lseek( fd, filehdr.f_nsyms * SYMESZ + filehdr.f_symptr, 0 ) == -1 )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if( read( fd, (char *) &strtablen, sizeof( long ) ) != sizeof( long ) )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if ((strtab = sbrk((strtablen + 3 ) & ~3)) == (char *)(-1))
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if ( read( fd, &strtab[ sizeof( long ) ], strtablen - sizeof( long ) )
		!= strtablen - sizeof( long ) )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if ( strtab[ strtablen -       1 ] != '\0' )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	lseek( fd, home, 0 );
	/*
	**	Used for debugging the reading in of string table for FLEXNAMES.
	**	printf("STRING TABLE\n");
	**	for (i = 4; i < strtablen; i++)
	**	{
	**		if (strtab[i] == '\0')
	**			printf("^@\n");
	**		else if (strtab[i] < ' ')
	**			printf("^%c", strtab[i]|0100);
	**		else if (strtab[i] == '\177')
	**			printf("^?");
	**		else if (strtab[i] > '~')
	**			printf("M-%c", strtab[i]&0177);
	**		else
	**			printf("%c", strtab[i]);
	**	}
	*/
	return;
}
q    ,   kcmd/adb/vax/sys.h /*	@(#)sys.h	1.2	*/
/*
 *  External declarations for system call library routines
 */

extern int  close();
extern int  creat();
extern int  execl();
extern int  exit();
extern int  fork();
extern long lseek();
extern int  open();
extern int  ptrace();
extern int  read();
extern char *sbrk();
extern int  (* signal())();
extern int  wait();
extern int  write();
(q }A   WXd     cmd/adb/ns32000 q y   3X~   cmd/adb/ns32000/adb.mk  #	@(#)adb.mk	1.4
#
.SUFFIXES:
.SUFFIXES: .o .c .e .r .f .y .yr .ry .ey .ye .l .s

ROOT=
PFX=
CC = $(PFX)cc
CFLAGS = -O
AS = $(PFX)as -

TESTDIR = .
INS = /etc/install -i -n $(ROOT)/bin 
INSDIR =

BIN = /bin
USRBIN = /usr/bin
LIBA = lib/lib$(PFX)a
LIBM = lib/lib$(PFX)m
LIBC = lib/lib$(PFX)c
LIBS = lib/lib$(PFX)S
INCRT = /usr/$(PFX)include

FRC =


all:	$(TESTDIR)/adb

$(TESTDIR)/adb:\
	access.o\
	command.o\
	expr.o\
	extern.o\
	format.o\
	input.o\
	main.o\
	opcode.o\
	output.o\
	pcs.o\
	print.o\
	runpcs.o\
	setup.o\
	sym.o\
	/$(LIBC).a\
	$(INCRT)/time.h\
	$(INCRT)/mon.h\
	$(INCRT)/stdio.h\
	$(INCRT)/varargs.h\
	$(INCRT)/ctype.h\
	$(INCRT)/values.h\
	$(INCRT)/errno.h\
	$(INCRT)/termio.h\
	$(FRC)
		$(CC) $(CFLAGS) $(LDFLAGS) -o $(TESTDIR)/adb *.o

access.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


command.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


expr.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


extern.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


format.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


input.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


main.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/u      ser.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


opcode.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


output.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


pcs.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


print.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


runpcs.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


setup.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)


sym.o:\
	defs.h\
	$(INCRT)/sys/param.h\
	$(INCRT)/signal.h\
	$(INCRT)/sys/types.h\
	$(INCRT)/sys/sysmacros.h\
	$(INCRT)/a.out.h\
	$(INCRT)/setjmp.h\
	$(INCRT)/sys/text.h\
	$(INCRT)/fcntl.h\
	$(INCRT)/sys/dir.h\
	$(INCRT)/sys/file.h\
	$(INCRT)/sys/proc.h\
	$(INCRT)/sys/tty.h\
	$(INCRT)/sys/termio.h\
	$(INCRT)/sys/inode.h\
	$(INCRT)/sys/user.h\
	$(INCRT)/sys/errno.h\
	$(INCRT)/sys/reg.h\
	$(INCRT)/stdio.h\
	$(INCRT)/ctype.h\
	mode.h\
	functs.h\
	extern.h\
	sys.h\
	lib.h\
	machine.h\
	$(FRC)
	$(CC) $(CFLAGS) -DFLEXNAMES -c sym.c


FRC:

install:	all
		$(INS) $(TESTDIR)/adb $(INSDIR)
clean:
		-rm -f *.o

clobber:	clean
		-rm -f $(TESTDIR)/adb
q v   <X]E   cmd/adb/ns32000/command.c /*	@(#)command.c	1.2	*/
/*
 *  Command decoding 
 */

#include "defs.h"

SCCSID(@(#)command.c	1.2);

static char eqformat[128] = "z";
static char stformat[128] = "X\"= \"^i";
static int  locmsk;

void command(buf, defcom)
    STRING  buf;
    char    defcom;
{
    int    itype;
    int    ptype;
    int    modifier;
    int    regptr;
    int    longpr;
    int    eqcom;
    char   wformat[1];
    char   savc;
    int    w;
    int    savdot;
    STRING savlp = lp;

    if (buf) { 
        if (*buf == EOR)
            return;
        else 
            lp = buf;
    }

    do {
        if (adrflg = expr(0))
            ditto = dot = expv;
        adrval = dot;

        TR1PRINT("Adrflg = %s, ", (adrflg ? "TRUE" : "FALSE"));
        TR1PRINT("adrval = %#x\n", adrval);

        if (rdc() == ',' && expr(0)) {
            cntflg = TRUE;
            cntval = expv;
        }
        else {
            cntflg = FALSE;
            cntval = 1;
            lp--;
        }

        TR1PRINT("Cntflg = %s, ", (cntflg ? "TRUE" : "FALSE"));
        TR1PRINT("cntval = %d\n", cntval);
   
        if ( ! eocmd(rdc()))
            lastcom = lastc;
        else { 
            if (adrflg == 0)
                dot = inkdot(dotinc);
            lp--;
            lastcom = defco      m;
        }
   
        TR1PRINT("Type of command: %c\n", lastcom & STRIP);

        switch(lastcom & STRIP) {
   
            case '/':
                itype = DSP;
                ptype = DSYM;
                goto trystar;
   
            case '=':
                itype = NSP;
                ptype = NSYM;
                goto trypr;
   
            case '?':
                itype = ISP;
                ptype = ISYM;
                goto trystar;
   
trystar:
                if (rdc() == '*') {
                    lastcom |= QUOTE; 
                    itype |= STAR;
                }
                else
                    lp--;
   
trypr:
                longpr = FALSE;
                eqcom = lastcom == '=';

                switch (rdc()) {
   
                    case 'm': 
			{ /* Reset map data */
			short  fcount;
			MAP    *smap;
			union {
				MAP *m;
				int *mp;
			} amap;

			if (eqcom)
				error(BADEQ);
			smap = (itype & DSP ? &slshmap : &qstmap);
			amap.m = smap;
			fcount = 3;
			if (itype & STAR)
				amap.mp += 3;
			while (fcount-- && expr(0))
				*(amap.mp)++ = expv;
			if (rdc() == '?')
				smap->ufd = fsym;
			else if (lastc == '/')
				smap->ufd = fcor;
			else
				lp--;
		}
		break;


                case 'l': /* Search for exp */
                    if (eqcom) 
                        error(BADEQ);
                    savdot = dot;
		    expr(0);
                    locval = expv;
		    switch (rdc())
			{
				case 'b':
					locmsk = 0xff;
					dotinc = 1;
					break;
				case 'w':
					locmsk = 0xffff;
					dotinc = 2;
					break;
				case 'l':
					locmsk = -1L;
					dotinc = 4;
					break;
				case 'o':
					locmsk = 0xff;
					for(;;)
					{
						w=get(dot,itype);
						if(errflg||mkfault||locval==
							(w&locmsk))
							break;
						printins(itype,w,0);
						dot=inkdot(dotinc);
					}
					psymoff(dot,ptype,"");
					goto out;
				default:
					lp--;
					if(expr(0))
						locmsk = expv;
					else
						locmsk = -1L;
					dotinc = 1;
					break;
			}
			if(expr(0))
				dotinc = expv;
                        for ( ; ; ) {
                            w = get(dot, itype);
                            if (errflg != NULL || mkfault || 
                                (w & locmsk) == locval) 
                                break; 
                            dot = inkdot(dotinc);
                        }
                        if (errflg != NULL) {
                            dot = savdot;
                            errflg = NOMATCH;
                        }
                        psymoff(dot, ptype, "");
                        break;

                    case 'W':
                        longpr = TRUE;

                    case 'w':
                        if (eqcom)
                            error(BADEQ);
                        wformat[0] = lastc;
                        (void) expr(1);
                        do {
                            savdot = dot; 
                            psymoff(dot, ptype, ":%16t"); 
                            (void) exform(1, wformat, itype, ptype);
                            errflg = NULL;
                            dot = savdot;
                            put(dot, itype, expv);
                            savdot = dot;
                            adbpr("=%8t");
                            (void) exform(1, wformat, itype, ptype);
                            newline();
                        } while (expr(0) && errflg == NULL);
                        dot = savdot;
                        chkerr();
                        break;

                    default:
                        lp--;
                        getformat(eqcom ? eqformat : stformat);
                        if ( ! eqcom)
                            psymoff(dot, IDSYM, ":%16t");
                        scanform(cntval, (eqcom ? eqformat : stformat),
                            itype, ptype);
                }
                break;

            case '>':
                lastcom = 0;
                savc = rdc();
		{
			struct grres res;
			res = getreg(savc);
			if (res.sf) {
				regptr = res.roff;
				ADBREG(regptr) = dot;
				(void) ptrace(WUREGS, pid, 
				SYSREG(regptr), 
				ADBREG(regptr));
			}
			else if ((modifier = varchk(savc))!=-1)
				var[modifier] = dot;
			else 
				error(BADVAR);
		}
                break;

            case '!':
                lastcom = 0;
                shell();
                break;

            case '$':
                lastcom = 0;
                dollar(nextchar());
                break;

            case ':':
                if ( ! executing) { 
                    executing = TRUE;
                    subpcs(nextchar());
                    executing = FALSE;
                    lastcom = 0;
                }
                break;

            case 0:
                prints(DBNAME);
                break;

            default:
                error(BADCOM);
        }

out:        flushbuf();
    } while (rdc() == ';');
    if (buf)
        lp = savlp; 
    else
        lp--; 
}
 q    Xf   cmd/adb/ns32000/defs.h ./*	@      (#)defs.h	1.4	*/
/*
 *  Common definitions
 */

#include	<sys/param.h>
#include	<signal.h>
#include	<sys/types.h>
#include	<sys/sysmacros.h>
#include	"a.out.h"
#include	<setjmp.h>
#include	<sys/text.h>
#include	<fcntl.h>
#include	<sys/dir.h>
#include	<sys/file.h>
#include	<sys/proc.h>
#include	<sys/tty.h>
#include	<sys/termio.h>
#include	<sys/inode.h>
#include	<sys/user.h>
#include	<sys/errno.h>
#include	<sys/reg.h>
#include	<sys/stat.h>
#include	<stdio.h>
#include	<ctype.h>
#include	"mode.h"
#include	"functs.h"
#include	"extern.h"
#include	"sys.h"
#include	"lib.h"
#include	"storclass.h"

#define VARNO 36
#define VARB  11
#define VARD  13
#define VARE  14
#define VARF 15
#define VARM  22
#define VARS  28
#define VART  29

#define RD 0
#define WT 1

#define NSP      0
#define ISP      1
#define DSP      2
#define NSYM     0
#define ISYM     4
#define DSYM     8
#define IDSYM    12
#define ENDSYMS  (-1)
#define EXTRASYM (-2)

#define BPT      0xf2
#define BKPTSET  1
#define BKPTEXEC 2

/*
 *  Ptrace mode defines
 */
#define SETTRC 0
#define RIUSER 1
#define RDUSER 2
#define RUREGS 3
#define WIUSER 4
#define WDUSER 5
#define WUREGS 6
#define CONTIN 7
#define EXIT   8
#define SINGLE 9

#define MAXREGS   12
#define MAXFREGS   9
#define ADBREG(A) (u.u_ar0[A])
#define SYSREG(A) ((int) (((char *) (&ADBREG(A))) - ((char *) &u)))

#define EOR    '\n'
#define SPACE  ' '
#define TB     '\t'

#define DBNAME  "adb\n"

#define LPRMODE "%R"
#define OFFMODE "+%R"

/* Symbol table in a.out file */
#define SYMBOLSIZE  (20)

#define DEFRADIX  16
#define MAXARG	  32
#define LINSIZ	1024
#define STAR       4
#define MAXOFF   255
#define MAXPOS    80
#define MAXLIN   128
#define QUOTE   0200
#define STRIP   0177
#define LOBYTE  0377
#define EVEN      -2

#define TRUE   (-1)
#define FALSE  0

#define shorten(a) ((short)(a))

#define SCCSID(A) static char Sccsid[] = "A"

#define TRPRINT(S) if (trace) (void) fprintf(stderr, S)
#define TR1PRINT(S, V) if (trace) (void) fprintf(stderr, S, V)

#define SECT1 1
#define SECT2 2
#define SECT3 3
q 	   [   )cmd/adb/ns32000/expr.c ./*	@(#)expr.c	1.2	*/
#include "defs.h"

SCCSID(@(#)expr.c	1.2);

static int  savframe;
static int  savpc;
static char isymbol[BUFSIZ];
static void readsym();
static void chkloc();

static SYMPTR lookupsym(symstr)
	STRING symstr;
{
	SYMPTR symp;

	symset();
	while ( symp = symget() )
	{
		skip_aux(symp);
		if( symp->n_scnum == N_DEBUG )
			continue;
		if( eqsym( symp->n_nptr, symstr, '_' ) ) 
			return(symp);
	}
	return(0);
}

int expr(a)                       /* term | term dyadic expr |  */
{ 
	short rc;
	int   lhs;

	(void) rdc(); 
	lp--; 
	rc = term(a);

	while (rc) {  
		lhs = expv;

	    switch (readchar()) {

	        case '+':
	            (void) term(a|1); 
				expv += lhs; 
				break;

	        case '-':
	            (void) term(a|1); 
				expv = lhs - expv;
				break;

	        case '#':
	            (void) term(a|1);
				expv = round(lhs, expv);
				break;

	        case '*':
	            (void) term(a|1);
				expv *= lhs;
				break;

	        case '%':
	            (void) term(a|1);
				expv = lhs / expv;
				break;
	        
	        case '&':
	            (void) term(a|1);
				expv &= lhs;
				break;

	        case '|':
	            (void) term(a|1);
				expv |= lhs;
				break;
	  
	        case ')':
				if ((a&2) == 0)
					error(BADKET);

	        default:
	            lp--;
	            return(rc);
	    }
	}
	return(rc);
}

static term(a)              /* item | monadic item | (expr) | */
{
	switch (readchar()) {

	    case '*':
	        (void) term(a|1);
			expv = chkget(expv, DSP);
			return(1);

	    case '@':
	        (void) term(a|1);
			expv = chkget(expv, ISP);
			return(1);

	    case '-':
	        (void) term(a|1);
			expv = -expv;
			return(1);

	    case '~':
	        (void) term(a|1);
			expv = ~expv;
			return(1);

	    case '(':
	        (void) expr(2);
	        if (*lp!=')')
				error(BADSYN);
	        else { 
				lp++;
				return(1);
	        }

	    default:
	        lp--;
	        return(item(a));
	}
}

static item(a) /* name [ . local ] | number | . | ^ | 
	              <var | <REG | 'x | | */
	int a;
{
	short  base;
	short  d;
	short  regptr;
	char   savc;
	int    frame;
	int oldframe;
	SYMPTR symp;
	int autonum;
	int argp;
	int word;

	(void) readchar();
	if (symchar(0)) 
	{
		readsym();
		if (lastc == '.') 
		{
			frame = ADBREG(FP);
			callpc = ADBREG(PC);
			while (errflg == NULL)  
			{
				savpc = callpc;
				(void) findsym(callpc, ISYM);
				if( eqsym( symbol.n_nptr, isymbol, '_' ) )
				{
					break;
				}
				callpc = get(frame+4, DSP);
				oldframe = frame; /* for possible adjustment */
				frame = get(frame, DSP) & EVEN;
				if (frame == 0)
					error(NOCFN);
			}
			if(frame!=ADBREG(FP))
				frame = oldframe;
			savframe = frame;
			(void) readchar();
			if(getnum(readchar))
			{
				(void)readchar();
				autonum = expv;
				localsym(frame,frame!=oldframe);
				localval = expv = locadr -(4 * autonum);
				adbpr("%8t%s.%X%  =  ", symbol.n_nptr, autonum);
				adbpr("%R\n",get(localval,DSP));
			} 
			else
				error(BADSYM);      
		}
		else if ((symp = lookupsym(isymbol)) == 0)
			error(BADSYM);
		else 
			expv = symp->n_value;
		lp--;

	} 
	else if (getnum(readchar)) 
		;
	else if (lastc == '.') 
	{
		(void)readchar();
		if(getnum(readchar))
		{
			(void)readchar();
			autonum = expv;
			localsym(ADBREG(FP),1);
			localval = expv = locadr - (4*(autonum+1));
			adbpr("%8t%s.%X%  =  ",symbol.n_nptr,autonum);
			adbpr("%R\n",get(localval, DSP));
		}
		else 
			expv = dot;
	    lp--;

	} 
	else if (lastc == '"')
		expv = ditto;

	else if (lastc == '+') 
		expv = inkdot(dotinc);

	else if (lastc == '^')
		expv = inkdot(-dotinc);

	else if (lastc == '<') { 
		savc = rdc();
		{
			struct grres res;
			res = getreg(savc);
			if (res.sf)
				expv = ADBREG(res.roff);
			else if ((base = varchk(savc)) != -1)
				expv = var[base];
			else 
				error(BADVAR);
		}
	} 
	else if (lastc == '\'') { 
	    d = 4; 
	    expv = 0;
	    while (quotchar() != '\0') {  
	        if (d--) { 
				if (d == 1)
	                expv <<= 16; 
	            expv |= ((d&1) ? lastc : lastc << 8);
	        }
			else
				error(BADSYN);
	    }

	} 
	else if (a)
	    error(NOADR);
	else { 
	    lp--; 
	    return(0);
	}
	return(1);
}

/* Service routines for expression reading */
int getnum(rdf) 
	char (*rdf)();
{
	int  base;
	int  d;
	int  frpt;
	BOOL hex = FALSE;
	union {
		float r; 
		int   i;
	} real;

	if (isdigit(lastc) || (hex = TRUE, lastc == '#' &&
	                     hexdigit((*rdf)()))) { 
		expv = 0;
	    	base = (hex ? 16 : radix);
		while ((base > 10 ? hexdigit(lastc) : isdigit(lastc))) {  
			expv *= base;
			if ((d = convdig(lastc)) >= base)
				error(BADSYN);
			expv += d;
			(*rdf)();
			if (expv == 0) { 
				if ((lastc == 'x' || lastc == 'X')) { 
					hex = TRUE;
					base = 16;
					(*rdf)();
				} 
				else if ((lastc == 't' || lastc=='T')) { 
					hex = FALSE; 
					base=10; 
					(*rdf)();
				} 
				else if ((lastc == 'o' || lastc=='O')) { 
					hex = FALSE; 
					base = 8; 
					(*rdf)();
				}
			}
		}
		if (lastc == '.' && (base == 10 || expv == 0) && !hex) { 
			real.r = expv;
			frpt = 0;
			base = 10;
			while (isdigit((*rdf)())) { 
				real.r *= base;
				frpt++;
				real.r += lastc - '0';
			}
			while (frpt--)
				real.r /= base;
			expv = real.i;
		}
		peekc = lastc;
		/*  lp--; */
		return(1);
	}
	else 
		return(0);
}
   
static void readsym()
{
	char *p = isymbol;

	do { 
		if (p < &isymbol[BUFSIZ])
			*p++ = lastc;
	    (void) readchar();
	} while (symchar(1));
	if (p < &isymbol[BUFSIZ])
		*p = 0;
}

static int hexdigit(c)
	char c;
{ 
	return((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'));
}

static int convdig(c)
	char c;
{
	if (isdigit(c)) 
		return(c - '0');
	else if (hexdigit(c))
		return(c - 'a' + 10);
	else
		return(17);
}

static int symchar(dig) /* TRUE if last character read can occur
						   in a symbol in position dig */
{
	if (lastc == '\\') { 
		(void) readchar(); 
		return(TRUE); 
	}
	return(isalpha(lastc) || lastc == '_' || dig && isdigit(lastc));
}

int varchk(name)
{
	if (isdigit(name))
		return(name - '0');
	if (isalpha(name)) 
		return((name & 037) - 1 + 10);
	return(-1);
}


static int
eqsym( s1, s2, c )	/* TRUE if s1 and s2 contain equivalent symbol names */
	STRING s1;
	STRING s2;
	char   c;
{
	if( eqstr( s1, s2 ) )
	    return( TRUE );
	else if ( *s1 == c )
	{ 
		char s3[BUFSIZ];
		int  i;
   
		s3[0] = c;
		for (i = 1; *s2; i++)
	        	s3[i] = *s2++; 
		s3[i] = '\0';
   
	    return( eqstr( s1, s3 ) );
	}
	return(FALSE);
}

calcap( frame, word )
int frame;
int word;
{
	int argp;
	word &= 0xfff;
	argp=frame+20+((word>>14)&3);
	while (word)
	{
		if(word&1)
			argp+=4;
		word >>= 1;
	}
	return(argp);
}
 q q   W   cmd/adb/ns32000/extern.c  /*	@(#)extern.c	1.3	*/
#include "defs.h"

SCCSID(@(#)extern.c	1.3);

int trace = FALSE;             /* TRUE for debugging printout */

MSG ADWRAP   = "address wrap around";
MSG BADCOM   = "bad command";
MSG BADDAT   = "data address not found";
MSG BADEQ    = "unexpected `='";
MSG BADFIL   = "bad file format";
MSG BADKET   = "unexpected ')'";
MSG BADLOC   = "automatic variable not found";
MSG BADMAGIC = "bad core magic number";
MSG BADMOD   = "bad modifier";
MSG BADNAM   = "not enough space for symbols";
MSG BADRAD   = "must have 2<= radix <= 16";
MSG BADSYM   = "symbol not found";
MSG BADSYN   = "syntax error";
MSG BADTXT   = "text address not found";
MSG BADVAR   = "bad variable";
MSG BADWAIT  = "wait error: process disappeared!";
MSG ENDPCS   = "process terminated";
MSG EXBKPT   = "too many breakpoints";
MSG LONGFIL  = "filename too long";
MSG NOADR    = "address expected";
MSG NOBKPT   = "no breakpoint set";
MSG NOCFN    = "c routine not found";
MSG NOEOR    = "newline expected";
MSG NOFORK   = "try again";
MSG NOMATCH  = "cannot locate value";
MSG NOPCS    = "no process";
MSG NOTOPEN  = "cannot open";
MSG SZBKPT   = "bkpt: command too long";

int      adrflg;              /* User specified an address */
int      adrval;              /* TRUE if user specified an address */
int      argcount;            /* Number of supplied files */
BKPTR    bkpthead;            /* Boi      nts to start of bkpt linked list */
int      callpc;              /* PC from one of the stack frames */
int      cntflg;              /* User specified an count */
int      cntval;              /* TRUE if user specified an count */
STRING   corfil = "core";     /* Name of the core file being used */
int      datsiz;              /* Size of data segment; default from core */
int      ditto;               /* Dot when command was entered */
int      dot;                 /* Current address */
int      dotinc;              /* Value by which dot is incremented */
int      entrypt;             /* Entry point for object file */
int      eof;                 /* Result of last read from < input */
STRING   errflg;              /* Error message */
int      executing;           /* TRUE when command is ":" */
int      expv;                /* Result of evaluating an expression */
int      fcor;                /* Core file file descriptor */
int      fsym;                /* a.out file descriptor */
int      infile;              /* File descriptor for redirected input */
char     lastc = EOR;         /* Result of last read */
int      lastcom = '=';       /* Type of last command */
int      localval;            /* Address of a local variable */
int	locadr;
int	numlocs;
int      locval;
int      loopcnt;             /* Process execution counter */
STRING   lp;                  /* Points at current char in input line */
short    magic;               /* Magic number for object file */
int      maxfile = 1<<24;     /* Maximum length of object file */
int      maxoff;              /* Max offset for symbolic addresses */
int      maxpos;              /* Maximum print width on output */
unsigned maxstor = 1<<24;     /* Maximum storage address */
int      mkfault;             /* Counts interrupts */
int      outfile = 1;         /* File descriptor for user output file */
char     peekc;
int      pid;                 /* Processid of user program */
MAP      qstmap;              /* ? map */
int      radix = DEFRADIX;    /* Current output radix */
REGLIST  reglist[] = {        /* Register description information */
	"psr_mod",  PSR_MOD,
	"pc",  PC,
	"sp",  SP,
	"fp",  FP,
	"r7",  R7,
	"r6",  R6,
	"r5",  R5,
	"r4",  R4,
	"r3",  R3,
	"r2",  R2,
	"r1",  R1,
	"r0",  R0,
};
REGLIST  freglist[] = {		/* floating register description information */
	"fsr", (-0x17a),	/* these offsets are from u.u_ar0	*/
	"f7",  (-0x172),
	"f6",  (-0x173),
	"f5",  (-0x174),
	"f4",  (-0x175),
	"f3",  (-0x176),
	"f2",  (-0x177),
	"f1",  (-0x178),
	"f0",  (-0x179),
};
SIGunion sigint;              /* Current interrupt handling routine */
int      signo;               /* Signal that caused process halt */
SIGunion sigqit;              /* Current quit handling routine */
MAP      slshmap;             /* / map */
int      stksiz;              /* Size of stack from core file */
int      txtsiz;              /* Size of text segment; default from core */
int      symbas;              /* A.out file address of symbol table */
SYMTAB   symbol;              /* I/O buffer for a.out symbols */
STRING   symfil = "a.out";    /* Name of the object file being used */
int      symnum;              /* Number of symbols in symbol table */
SYMSLAVE *symvec;             /* Beginning of slave array */
int      var[VARNO];          /* Holds values of adb variables */
int      wtflag;              /* TRUE if user gave -w flag */

union Uuniontag Uunion;       /* User block in core file */
nq p   7\   cmd/adb/ns32000/extern.h  /*	@(#)extern.h	1.2	*/
/*
 *  External data declarations
 */

extern MSG      ADWRAP;
extern MSG      BADCOM;
extern MSG      BADDAT;
extern MSG      BADEQ;
extern MSG      BADFIL;
extern MSG      BADKET;
extern MSG      BADLOC;
extern MSG      BADMAGIC;
extern MSG      BADMOD;
extern MSG      BADNAM;
extern MSG      BADRAD;
extern MSG      BADSYM;
extern MSG      BADSYN;
extern MSG      BADTXT;
extern MSG      BADVAR;
extern MSG      BADWAIT;
extern MSG      ENDPCS;
extern MSG      EXBKPT;
extern MSG      LONGFIL;
extern MSG      NOADR;
extern MSG      NOBKPT;
extern MSG      NOCFN;
extern MSG      NOEOR;
extern MSG      NOFORK;
extern MSG      NOMATCH;
extern MSG      NOPCS;
extern MSG      NOTOPEN;
extern MSG      SZBKPT;

extern int      adrflg;
extern int      adrval;
extern int      argcount;
extern BKPTR    bkpthead;
extern int      callpc;
extern int      cntflg;
extern int      cntval;
extern STRING   corfil;
extern int      datsiz;
extern int      ditto;
extern int      dot;
extern int      dotinc;
extern int      entrypt;
extern int      eof;
extern STRING   errflg;
extern int      executing;
extern int      expv;
extern int      fcor;
extern int      fsym;
extern int      infile;
extern char     lastc;
extern int      lastcom;
extern int      localval;
extern int      locval;
extern int      loopcnt;
extern STRING   lp;
extern short    magic;
extern int      maxfile;
extern int      maxoff;
extern int      maxpos;
extern unsigned maxstor;
extern int      mkfault;
extern int      outfile;
extern char     peekc;
extern int      pid;
extern MAP      qstmap;
e      xtern int      radix;
extern REGLIST  reglist[];
extern REGLIST  freglist[];
extern SIGunion sigint;
extern int      signo;
extern SIGunion sigqit;
extern MAP      slshmap;
extern int      stksiz;
extern int      symbas;
extern SYMTAB   symbol;
extern STRING   symfil;
extern int      symnum;
extern SYMSLAVE *symvec;
extern int      trace;
extern int      txtsiz;
extern int      var[];
extern int      wtflag;
extern int locadr;
extern int numlocs;
 q o   b   cmd/adb/ns32000/format.c  /*	@(#)format.c	1.2	*/
#include "defs.h"

SCCSID(@(#)format.c	1.2);

static STRING fphack;
static void   printesc();

static char rdfp()
{
    return(lastc = *fphack++);
}

void scanform(icount, ifp, itype, ptype)
    int    icount;
    STRING ifp;
    int    itype;
    int    ptype;
{
    STRING fp;
    int    fcount;
    int    init = TRUE;
    int    savdot;
    BOOL   exact;

    while (icount) {  
        exact = (findsym(dot, ptype) == 0);
        if ((! init) && exact && maxoff) 
            adbpr("\n%s:%16t", symbol.n_nptr);

        fp = ifp;
        savdot = dot; 
        init = FALSE;

        /*now loop over format*/
        while (*fp && errflg == NULL) {  
            fphack = fp;
            (void) rdfp();
            if (getnum(rdfp) && lastc == '*') { 
                fcount = expv;
                fp = fphack;
                peekc = 0;
            }
            else
                fcount = 1;

            if (*fp == 0) 
                break;
            fp = exform(fcount, fp, itype, ptype);
        }
        dotinc = dot - savdot;
        dot = savdot;

        if (errflg != NULL) { 
            if (icount < 0) { 
                errflg = NULL;
                break;
            }
            else
                error(errflg);
        }
        if (--icount)
            dot = inkdot(dotinc);
        if (mkfault) 
            error((STRING) NULL);
    }
}

STRING exform(fcount, ifp, itype, ptype)
	int    fcount;
	STRING ifp;
	int    itype;
	int    ptype;
{
    /* execute single format item `fcount' times
     * sets `dotinc' and moves `dot'
     * returns address of next format item
     */
    unsigned w;
    int      savdot;
    int      wx;
    STRING   fp;
    char     c;
    char     modifier;
    char     longpr;
    struct {
        int   sa;
        short sb;
        short sc;
    } fw;

    while (fcount > 0) {
	fp = ifp;
	c = *fp;
        longpr = (c >= 'A') & (c <= 'Z') | (c == 'f') | (c == '4') | (c == 'p');
        if (itype == NSP || *fp == 'a')
		wx = w = dot;
        else
		wx = w = get(dot, itype);
        if (c == 'F') {
		fw.sb = get(inkdot(4), itype);
		fw.sc = get(inkdot(6), itype);
        }
        if (errflg != NULL)
		return(fp);
        if (mkfault)
		error((STRING) NULL);
        var[0] = wx;
        modifier = *fp++;
        dotinc = (longpr ? 4 : 2);

        if (charpos() == 0 && modifier != 'a' )
		adbpr("%16m");

        switch(modifier) {

            case SPACE:
			case TB:
				break;

            case 't':
			case 'T':
				adbpr("%T",fcount);
				return(fp);

            case 'r':
			case 'R':
				adbpr("%M", fcount);
				return(fp);

            case 'a':
				psymoff(dot, ptype, ":%16t");
				dotinc = 0;
				break;

            case 'p':
				psymoff(var[0], ptype, "%16t");
				break;

            case 'u':
				adbpr("%-8u", w);
				break;

            case 'U':
				adbpr("%-16U", wx);
				break;

            case 'c':
			case 'C':
				if (modifier == 'C')
					printesc(w);
				else
					printc((char) (w & LOBYTE));
				dotinc = 1;
				break;

            case 'b':
			case 'B':
				adbpr("%-8o", w&LOBYTE);
				dotinc = 1;
				break;

            case '1':
				adbpr("%-8r", w&LOBYTE);
				dotinc = 1;
				break;

            case '2':
            case 'w':
				adbpr("%-8r", w);
				break;

            case '4':
            case 'W':
				adbpr("%-16R", wx);
				break;

            case 's':
			case 'S':
				savdot = dot;
				dotinc = 1;
				while ((c = get(dot, itype)&LOBYTE) && errflg == NULL) {
					dot = inkdot(1);
				    if (modifier == 'S') 
						printesc((unsigned) c);
				    else
						printc(c);
				    endline();
				}
				dotinc = dot - savdot + 1;
				dot = savdot;
				break;

	    case 'x':
				adbpr("%-8x", w);
				break;

            case 'X':
				adbpr("%-16X", wx);
				break;

            case 'Y':
				adbpr("%-24Y", wx);
				break;

            case 'q':
				adbpr("%-8q", w);
				break;

            case 'Q':
				adbpr("%-16Q", wx);
				break;

            case 'o':
				adbpr("%-8o", w);
				break;

            case 'O':
				adbpr("%-16O", wx);
				break;

            case 'i':
				printins(itype, (int) w, 1);
				printc(EOR);
				break;

            case 'd':
				adbpr("%-8d", w);
				break;

            case 'D':
				adbpr("%-16D", wx);
				break;

            case 'f':
				fw.sa = wx;
				fw.sb = fw.sc = 0;
				if ((fw.sa & 0x7f800000) == 0x7f800000)
					adbpr("INFINITY %X", fw.sa);
				else if (((fw.sa & 0x7f800000) == 0) &&
					      (fw.sa & 0x7fffff))
					adbpr("DENORMALIZED %X", fw.sa);
				else
					adbpr("%-16.9f", fw);
				dotinc = 4;
				break      ;

            case 'F':
				fw.sa = wx;
				if ((fw.sc & 0x7ff0) == 0x7ff0)
					adbpr("INFINITY %X %x %x", fw.sc, fw.sb,
						fw.sa);
				else if (((fw.sc & 0x7ff0) == 0) &&
					      ((fw.sc & 0xf) || fw.sb || fw.sa))
					adbpr("DENORMALIZED %X %x %x", fw.sc, 
						fw.sb, fw.sa);
				else
					adbpr("%-32.18F", fw);
				dotinc = 8;
				break;

            case 'n':
			case 'N':
				printc('\n');
				dotinc = 0;
				break;

            case '"':
				dotinc = 0;
				while (*fp != '"' && *fp)
					printc(*fp++);
				if (*fp)
					fp++;
				break;

            case '^':
				dot = inkdot(-dotinc * fcount);
				return(fp);

            case '+':
				dot = inkdot(fcount);
				return(fp);

            case '-':
				dot = inkdot(-fcount);
				return(fp);

            default: 
				error(BADMOD);
        }
        if (itype != NSP)
			dot = inkdot(dotinc);
        fcount--;
        endline();
    }

    return(fp);
}

void shell()
{
    int    rc;
    int    status;
    int    unixpid;
    STRING argp = lp;

    while (lastc != EOR)
		(void) rdc();
    if ((unixpid = fork()) == 0) {
		if (-1 == (int) signal(SIGINT, sigint.siFUN))
			perror("shell");
        if (-1 == (int) signal(SIGQUIT, sigqit.siFUN))
			perror("shell");
        *lp=0;
		if (-1 == execl("/bin/sh", "sh", "-c", argp, 0))
			perror("shell");
		(void) exit(16);
    }
    else if (unixpid == -1)
		error(NOFORK);
    else {
		if (-1 == (int) signal(SIGINT, SIG_IGN))
			perror("shell");
        while ((rc = wait(&status)) != unixpid && rc != -1 )
			;
        if (-1 == (int) signal(SIGINT, sigint.siFUN))
			perror("shell");
        prints("!");
		lp--;
    }
}

static void printesc(c)
    unsigned c;
{
    c &= STRIP;
    if (c < SPACE || c > '~' || c == '@') 
        adbpr("@%c", (c == '@' ? '@' : c ^ 0140));
    else 
        printc((char) c);
}

int inkdot(incr)
{
    int newdot;

    newdot = dot + incr;
    if ((dot ^ newdot) >> 24 )
		error(ADWRAP);
    return(newdot);
}
q    Z̺   cmd/adb/ns32000/functs.h  /*	@(#)functs.h	1.2	*/
/* 
 *  Result type declarations 
 */

/* access.c */

unsigned int bchkget();
unsigned int chkget();
unsigned int get();
void         put();

/* command.c */

void command();

/* expr.c */

int  expr();
int  getnum();
int  varchk();

/* format.c */

STRING exform();
int    inkdot();
void   shell();
void   scanform();

/* input.c */

int  eocmd();
void getformat();
int  nextchar();
char quotchar();
char rdc();
char readchar();

/* main.c */

void chkerr();
void done();
void error();
int  round();

/* opcode.c */

void mkioptab();
void printins();

/* output.c */

void adbpr();
void endline();
int  eqstr();
void flushbuf();
void iclose();
void newline();
void oclose();
void printc();
void prints();

/* pcs.c */

void subpcs();

/* print.c */

struct grres getreg();
void         printpc();
void         sigprint();

/* runpcs.c */

void  delbp();
void  endpcs();
int   getsig();
int   runpcs();
BKPTR scanbkpt();
void  setup();

/* setup.c */

void setsym();
void setcor();

/* sym.c */

unsigned int findsym();
void         localsym();
void         psymoff();
SYMPTR       symget();
void         symset();
void         valpr();
 q 	   &Tcq   lcmd/adb/ns32000/access.c  /*	@(#)access.c	1.2	*/
#include "defs.h"

SCCSID(@(#)access.c	1.2);

static unsigned accfile(mode, adr, sptype, value)
    int mode;
    int adr;
    int sptype;
    int value;
{
    short pmode;
    short rd;
    int   curfile;
    int w;

    if (sptype == NSP)
        return(0);

    rd = (mode == RD);

    if (pid) {      /* Does a process exist? */
         pmode = (sptype & DSP ? (rd ? RDUSER : WDUSER) : 
                               (rd ? RIUSER : WIUSER));
		 errno = 0;
         w = ptrace(pmode, pid, adr, value);
         if (w == -1 && errno != 0)
             errflg = (sptype & DSP ? BADDAT : BADTXT);
         return(w);
    }
    w = 0;
    if (mode == WT && wtflag == O_RDONLY)
        error("not in write mode");

    if ( ! chkmap(&adr ,sptype))
        return(0);

    curfile = (sptype & DSP ? slshmap.ufd : qstmap.ufd);
    if (lseek(curfile, (long) adr&0x7fffffff, 0) == -1L ||
       (rd ? read(curfile, (char *) &w, sizeof(w)) : 
	    write(curfile, (char *) &value, sizeof(w))) == -1)
			errflg = (sptype&DSP ? BADDAT : BADTXT);
    return(w);
}

/* file handling and access routines */

void put(adr, sptype, value)
    int adr;
    int sptype;
    int value;
{
    (void) accfile(WT, adr, sptype, value);
}

unsigned get(adr, sptype)
    int adr;
    int sptype;
{
    return(accfile(RD, adr, sptype, 0));
}

unsigned chkget(n, sptype)
    int n;
    int sptype;
{
    unsigned w;

    w = get(n, sptype);
    chkerr();
    return(w);
}

unsigned bchkget(n, sptype) 
    int n;
    int sptype;
{
    return(chkget(n, sptype) & LOBYTE);
}

static int chkmap(adr, sptype)
    int *adr;
    short sptype;
{
    MAPPTR amap;

    amap = (sptype & DSP ? &slshmap : &qstmap);
    if (sptype&STAR || !within(*adr, amap->b1, amap->e1)) { 
        if (within(*adr, amap->b2, amap->e2))
            *adr += (amap->f2) - (amap->b2);
        else { 
                  errflg = (sptype&DSP ? BADDAT : BADTXT); 
            return(0);
        }
    }
    else
        *adr += (amap->f1) - (amap->b1);
    return(1);
}

static int within(adr, lbd, ubd)
    int adr;
    unsigned lbd;
    unsigned ubd;
{
    return(adr >= lbd && adr < ubd);
}
q 	   ITfq   scmd/adb/ns32000/input.c /*	@(#)input.c	1.2	*/
/*
 *  Input routines 
 */

#include "defs.h"

SCCSID(@(#)input.c	1.2);

static char line[LINSIZ];

int eocmd(c)            /* TRUE if end of command has been reached */
    char c;
{
    return(c == EOR || c == ';');
}

char rdc()
{
	char c;

    do 
        c = readchar();
    while (c == SPACE || c == TB);

    return(c);
}

char readchar()
{
    if (eof)
        lastc = EOF;
    else {
        if (lp == 0) {
            lp = line;
            do {
                eof = (0 == read(infile, lp, 1));
                if (mkfault)
                    error((STRING) NULL);
            } while (( ! eof) && *lp++ != EOR);
            *lp = 0; 
            lp = line;
        }
        if (lastc = peekc)
            peekc = 0;
        else if (lastc = *lp) 
            lp++;
    }
    return(lastc);
}

int nextchar()
{
    if (eocmd(rdc())) {
        lp--; 
        return(0);
    }
    else 
        return(lastc);
}

char quotchar()
{
    if (readchar() == '\\')
        return(readchar());
    else if (lastc == '\'')
        return('\0');
    else 
        return(lastc);
}

void getformat(deformat)
    STRING deformat;
{
    STRING fptr = deformat; 
    int quote = FALSE;

    while (quote ? readchar() != EOR : ! eocmd(readchar()))
        if ((*fptr++ = lastc) == '"')
            quote = ~quote;
    lp--;
    if (fptr != deformat)
        *fptr++ = '\0';
}
;q    /YTr    cmd/adb/ns32000/lib.h /*	@(#)lib.h	1.2	*/
/*
 *  Library call external declarations
 */

extern STRING environ;
extern int    errno;

extern char *ctime();
extern int  exect();
extern int  fprintf();
extern void perror();
extern int  setjmp();
extern int  sprintf();
aq     X   cmd/adb/ns32000/machine.h /*	@(#)machine.h	1.3	*/
/* 
 * NS32000 UNIX parameters 
 */

/* User block in core file */

#define ADDR_U ((unsigned) UDOT)
#define ADRREG ((unsigned) 0x1C4)
#define ADRFREG ((unsigned) 0x208)
union  Uuniontag {
    struct user strpart;
    char chrpart[ctob(USIZE)];
};

extern union Uuniontag Uunion;

/*  Note - the following define must appear after the above
 *  definition else the preprocessor will use the wrong u
 *  in the expansion of USIZE.
*/
#define u Uunion.strpart
q UV   7]ĩ   &cmd/adb/ns32000/main.c ./*	@(#)main.c	1.2	*/
/*
 *  Main calling routine
 */

#include "defs.h"

SCCSID(@(#)main.c	1.2);

static jmp_buf env;
static int exitflg;
static int fault();
static int nocore();

struct termio usrtermio ;	/* Terminial state from user process */
struct termio adbtermio ;	/* Sane adb terminal state during breakpoint */

int usrfcntl ;
int adbfcntl ;

/* Set up files and initial address mappings */

main(argc, argv)
    STRING  *argv;
    int     argc;
{
/*	Initialize usrtermio and save the terminal state for use during	*/
/*	breakpoints.							*/

    ioctl(0,TCGETA,&usrtermio) ;
    ioctl(0,TCGETA,&adbtermio) ;
    adbfcntl = usrfcntl = fcntl(0,F_GETFL,0) ;

    while (argc > 1) {
        if (eqstr("-w", argv[1])) {
            wtflag = O_RDWR;
            argc--;
            argv++;
        }
        else
            break;
    }

    if (argc > 1)
        symfil = argv[1];
    if (argc > 2)
        corfil = argv[2];
    argcount = argc;

    setsym(); 
    setcor();

    /* Set up variables for user */
    maxoff = MAXOFF;
    maxpos = MAXPOS;
    var[VARB] = slshmap.b1 ? slshmap.b1 : qstmap.b1;
    var[VARD] = datsiz;
    var[VARE] = entrypt;
	var[VARF] = qstmap.f1;
    var[VARM] = magic;
    var[VARS] = stksiz;
    var[VART] = txtsiz;

    if ((sigint.siFUN = signal(SIGINT, SIG_IGN)) != SIG_IGN) { 
        sigint.siFUN = fault;
        if (-1 == (int) signal(SIGINT, fault))
			perror("main");
    }
    sigqit.siFUN = signal(SIGQUIT, SIG_IGN);
	if (-1 == (int) signal(SIGILL, nocore))
		perror("main");
	if (-1 == (int) signal(SIGIOT, nocore))
		perror("main");
	if (-1 == (int) signal(SIGEMT, nocore))
		perror("main");
	if (-1 == (int) signal(SIGFPE, nocore))
		perror("main");
	if (-1 == (int) signal(SIGBUS, nocore))
		perror("main");
	if (-1 == (int) signal(SIGSEGV, nocore))
		perror("main");
	if (-1 == (int) signal(SIGSYS, nocore))
		perror("main");

    (void) setjmp(env);

    if (executing && pid != 0)
        delbp();
    executing = FALSE;

    for ( ; ; ) {
        TRPRINT("* ");
        flushbuf();
        if (errflg != NULL) { 
            adbpr("%s\n", errflg);
            exitflg = (errflg != NULL); 
            errflg = NULL;
        }
        if (mkfault) {
            mkfault = FALSE; 
            printc(EOR); 
            prints(DBNAME);
        }
        lp = 0; 
        (void) rdc(); 
        lp--;
        if (eof) {
            if (infile) {
                iclose(); 
                eof = 0; 
                (void) longjmp(env, 0);
            }
            e      lse
                done();
        }
        else
            exitflg = 0;

        command((STRING) NULL, lastcom);
        if (lp && lastc != EOR)
            error(NOEOR);
    }
}

int round(a, b)
    int a;
    int b;
{
    int w;

    w = (a / b) * b;
    w += (a != w) ? b : 0;
    return(w);
}

/* error handling */

void chkerr()
{
    if (errflg != NULL || mkfault)
        error(errflg);
}

void error(n)
    STRING n;
{
    errflg = n;
    iclose();
    oclose();
    (void) longjmp(env, 0);
}

static int fault(a)
{
    if (-1 == (int) signal(a, fault))
		perror("fault");
    if (-1 == lseek(infile, 0L, 2))
        perror("fault");
    mkfault = TRUE;
}

static int nocore(s)
{
    fprintf(stderr, "adb system failure (signal %d) -- exiting\n",s);
    (void) exit(1);
}

void done()
{
    endpcs();
    (void) exit(exitflg);
}
q TV   =d    cmd/adb/ns32000/mode.h ./*	@(#)mode.h	1.2	*/
#include "machine.h"

typedef	char	 	    BOOL;
typedef	char		   *STRING;
typedef	char		   *MSG;
typedef	struct map	    MAP;
typedef	MAP		   *MAPPTR;
typedef	struct syment	    SYMTAB;
typedef	SYMTAB		   *SYMPTR;
typedef	struct symslave     SYMSLAVE;
typedef	struct bkpt	    BKPT;
typedef	BKPT		   *BKPTR;

/* file address maps */
struct map {
	unsigned b1;
	unsigned e1;
	unsigned f1;
	unsigned b2;
	unsigned e2;
	unsigned f2;
	int      ufd;
};

/* slave table for symbols */
struct symslave {
	unsigned valslave;
	int  	 typslave;
};

#define MAXCOM 64
struct bkpt {
	int  loc;
	int  ins;
	int  count;
	int  initcnt;
	int  flag;
	char comm[MAXCOM];
	BKPT *nxtbkpt;
};

typedef	struct reglist REGLIST;
typedef	REGLIST       *REGPTR;
struct reglist {
	STRING	rname;
	int  	roffs;
};

typedef union {
    int  siADDR;
    int (* siFUN)();
} SIGunion;

struct grres {				/* Returned by getreg */
	int sf;				/* Success/fail indicator */
	int roff;			/* Register offset on success */
} ;
q QV   Wb)   3cmd/adb/ns32000/opcode.c  #include "defs.h"

struct o1 {
	char *name;
	short val;
	char extra;
} ops1[] = {
	{"beq",     0x0a, 16},
	{"bne",     0x1a, 16},
	{"bcs",     0x2a, 16},
	{"bcc",     0x3a, 16},
	{"bhi",     0x4a, 16},
	{"bls",     0x5a, 16},
	{"bgt",     0x6a, 16},
	{"ble",     0x7a, 16},
	{"bfs",     0x8a, 16},
	{"bfc",     0x9a, 16},
	{"blo",     0xaa, 16},
	{"bhs",     0xba, 16},
	{"blt",     0xca, 16},
	{"bge",     0xda, 16},
	{"bpt",     0xf2, 0},
	{"br",      0xea, 16},
	{"bsr",     0x02, 16},
	{"cxp",     0x22, 2},
	{"dia",     0xc2, 0},
	{"enter",   0x82, 10},
	{"exit",    0x92, 1},
	{"flag",    0xd2, 0},
	{"nop",     0xa2, 0},
	{"restore", 0x72, 1},
	{"ret",     0x12, 2},
	{"reti",    0x52, 0},
	{"rett",    0x42, 2},
	{"rxp",     0x32, 2},
	{"save",    0x62, 8},
	{"svc",     0xe2, 0},
	{"wait",    0xb2, 0},
	{0, 0, 0}
};

struct o2 {
	short val, mask;
	char *name;
	char allow, type;
	char extra;
} ops2[] = {
	{0x13,  0x1f,  "acb",   0, 1, 16},
	{0x00,  0x0f,  "add",   0, 0, 0},
	{0x04,  0x0f,  "addc",  0, 0, 0},
	{0x03,  0x1f,  "addq",  0, 1, 0},
	{0x09,  0x0f,  "addr",  2, 0, 0},
	{0x15f, 0x1ff, "adjsp", 0, 2, 0},
	{0x0a,  0x0f,  "and",   0, 0, 0},
	{0x02,  0x0f,  "bic",   0, 0, 0},
	{0x5f,  0x1ff, "bicpsr",1, 2, 0},
	{0xdf,  0x1ff, "bispsr",1, 2, 0},
	{0x1df, 0x1ff, "case",  0, 2, 0},
	{0x01,  0x0f,  "cmp",   0, 0, 0},
	{0x07,  0x1f,  "cmpq",  0, 1, 0},
	{0x1f,  0x1ff, "cxpd",  2, 2, 0},
	{0x19f, 0x1ff, "jsr",   2, 2, 0},
	{0x9f,  0x1ff, "jump",  2, 2, 0},
	{0x1b,  0x1f,  "lpr",   0, 3, 0},
	{0x05,  0x0f,  "mov",   0, 0, 0},
	{0x17,  0x1f,  "movq",  0, 1, 0},
	{0x06,  0x0f,  "or",    0, 0, 0},
	{0x0f,  0x1ff, "seq",   0, 2, 0},
	{0x2f,  0x1ff, "sne",   0, 2, 0},
	{0x4f,  0x1ff, "scs",   0, 2, 0},
	{0x6f,  0x1ff, "scc",   0, 2, 0},
	{0x8f,  0x1ff, "shi",   0, 2, 0},
	{0xaf,  0x1ff, "sls",   0, 2, 0},
	{0xcf,  0x1ff, "sgt",   0, 2, 0},
	{0xef,  0x1ff, "sle",   0, 2, 0},
	{0x10f, 0x1ff, "sfs",   0, 2, 0},
	{0x12f, 0x1ff, "sfc",   0, 2, 0},
	{0x14f, 0x1ff, "slo",   0, 2, 0},
	{0x16f, 0x1ff, "shs",   0, 2, 0},
	{0x18f, 0x1ff, "slt",   0, 2, 0},
	{0x1af, 0x1ff, "sge",   0, 2, 0},
	{0x0b,  0x1f,  "spr",   0, 3, 0},
	{0x08,  0x0f,  "sub",   0, 0, 0},
	{0x0c,  0x0f,  "subc",  0, 0, 0},
	{0x0d,  0x0f,  "tbit",  0, 0, 0},
	{0x0e,  0x0f,  "xor",   0, 0, 0},
	{-1,0,0,0,0,0}
};

struct o3 {
	short val, mask;
	char *name;
	char f1, f2, regf, typef;
	char extra;
} ops3[] = {
	{0x697,  0x7df,  "abs",    0, 0, 1, 1, 0},
	{0x609,  0x79f,  "abs",    0, 0, 1, 0, 0},
	{0x17,   0x7df,  "add",    0, 0, 1, 1, 0},
	{0x789,  0x79f,  "addp",   0, 0, 1, 0, 0},
	{0x89,   0x79f,  "ash",    4, 0, 1, 0, 0},
	{0x109,  0x79f,  "cbit",   0, 0, 1, 0, 0},
	{0x189,  0x79f,  "cbiti",  0, 0, 1, 0, 0},
	{0x1d,   0x9f,   "check",  0, 0, 0, 0, 0},
	{0x117,  0x7df,  "cmp",    0, 0, 1, 1, 0},
	{0x99,   0x79f,  "cmpm",   0, 0, 1, 0, 2},
	{0x81,   0x1f9f, "cmps",   1, 1, 1, 0, 0},
	{0x1081, 0x1fff, "cmpst",  1, 1, 1, 4, 0},
	{0x689,  0x79f,  "com",    0, 0, 1, 0, 0},
	{0x6d,   0xff,   "cvtp",   0, 0, 0, 4, 0},
	{0x599,  0x79f,  "dei",    0, 0, 1, 0, 0},
	{0x417,  0x7df,  "div",    0, 0, 1, 1, 0},
	{0x799,  0x79f,  "div",    0, 0, 1, 0, 0},
	{0x05,   0x9f,   "ext",          0, 0, 0, 0, 2},
	{0x199,  0x79f,  "exts",   0, 0, 1, 0, 4},
	{0x8d,   0x79f,  "ffs",    0, 4, 1, 0, 0},
	{0x707,  0x71f,  "floor",  0, 0, 1, 2, 0},
	{0x709,  0x79f,  "ibit",   0, 0, 1, 0, 0},
	{0x85,   0x9f,   "index",  0, 0, 0, 0, 0},
	{0x15,   0x9f,   "ins",    0, 0, 0, 0, 2},
	{0x119,  0x79f,  "inss",   0, 0, 1, 0, 4},
	{0x1e7,  0xffff, "lfsr",   0, 4, 1, 4, 0},
	{0x163,  0xfff,  "lmr",    0, 3, 1, 4, 0},
	{0x289,  0x79f,  "lsh",    4, 0, 1, 0, 0},
	{0x499,  0x79f,  "mei",    0, 0, 1, 0, 0},
	{0x719,  0x79f,  "mod",    0, 0, 1, 0, 0},
	{0x97,   0x7df,  "mov",    0, 0, 1, 1, 0},
	{0x07,   0x71f,  "mov",    0, 0, 1, 3, 0},
	{0x367,  0x7ff,  "movfl",  0, 0, 1, 6, 0},
	{0x2c7,  0x7ff,  "movlf",  0, 0, 1, 5, 0},
	{0x19,   0x79f,  "movm",   0, 0, 1, 0, 2},
	{0x01,   0x1f9f, "movs",   1, 1, 1, 0, 0},
	{0x1001, 0x1fff, "movst",  1, 1, 1, 4, 0},
	{0x195,  0x79f,  "movsu",  0, 0, 1, 0, 0},
	{0x395,  0x79f,  "movus",  0, 0, 1, 0, 0},
	{0x399,  0x7ff,  "movxbd", 4, 7, 1, 4, 0},
	{0x3b9,  0x7ff,  "movxwd", 5, 7, 1, 4, 0},
	{0x219,  0x7ff,  "movxbw", 4, 5, 1, 4, 0},
	{0x319,  0x7ff,  "movzbd", 4, 7, 1, 4, 0},
	{0x339,  0x7ff,  "movzwd", 5, 7, 1, 4, 0},
	{0x299,  0x7ff,  "movzbw", 4, 5, 1, 4, 0},
	{0x617,  0x7df,  "mul",    0, 0, 1, 1, 0},
	{0x419,  0x79f,  "mul",    0, 0, 1, 0, 0},
	{0x297,  0x7df,  "neg",    0, 0, 1, 1, 0},
	{0x409,  0x79f,  "neg",    0, 0, 1, 0, 0},
	{0x489,  0x79f,  "not",    0, 0, 1, 0, 0},
	{0x619,  0x79f,  "quo",    0, 0, 1, 0, 0},
	{0x63,   0xffff, "rdval",  0, 4, 1, 4, 0},
	{0x699,  0x79f,  "rem",    0, 0, 1, 0, 0},
	{0x09,   0x79f,  "rot",    4, 0, 1, 0, 0},
	{0x407,  0x71f,  "round",  0, 0, 1, 2, 0},
	{0x309,  0x79f,  "sbit",   0, 0, 1, 0, 0},
	{0x389,  0x79f,  "sbiti",  0, 0, 1, 0, 0},
	{0x161,  0xfff,  "setcfg", 1, 2, 1, 4, 0},
	{0x6e7,  0x7ff,  "sfsr",   1, 0, 1, 4, 0},
	{0x181,  0x1f9f, "skps",   1, 1, 1, 0, 0},
	{0x1181, 0x1fff, "skpst",  1, 1, 1, 4, 0},
	{0x1e3,  0xfff,  "smr",    0, 3, 1, 4, 0},
	{0x217,  0x7df,  "sub",    0, 0, 1, 1, 0},
	{0x589,  0x79f,  "subp",   0, 0, 1, 0, 0},
	{0x507,  0x71f,  "trunc",  0, 0, 1, 2, 0},
	{0xe3,   0xffff, "wrval",  0, 4, 1, 4, 0},
	{0,0,0,0,0,0,0,0}
};

char *preg[] = {
	"upsr", "?", "?", "?",
	"?", "?", "?", "?",
	"fp", "sp", "sb", "?",
	"?", "psr", "intbase", "mod"
};

char *rnm[] = {
	"fp", "sp", "sb", "pc"
};

short flen[2] = {15, 11};	/* length parameters for f, l */

static int incp;
static int Idsp;
static int pflag;

void
printins(idsp, ins, pf)
{

	pflag = pf;
	Idsp = idsp;
	switch (ins & 7) {
	case 2:
		incp = 1;
		op1(ins);
		break;
	case 6:
		incp = 3;
		op3(ins);
		break;
	default:
		incp = 2;
		op2(ins);
		break;
	}
	dotinc = incp;
}

op1(a)
{
	register struct o1 *p;
	int i;

	a &= 0xff;
	for (p=ops1; p->val != 0; p++) {
		if (p->val == a) {
			if (pflag) adbpr("%s%8t", p->name);
			if (p->extra) {
				do_extra(p->extra);
			}
			return;
		}
	}
	if (pflag) adbpr("?");
}

op2(a)
{
	int i;
	register struct o2 *p;
	short cmp;

	a &= 0xffff;
	cmp = a>>2;
	for (p=ops2; p->mask != 0; p++) {
		if (p->val == (cmp & p->mask)) {
			if (pflag) adbpr(p->name);
			if (p->allow != 2) {
				if (pflag) printc("bw?d"[a&3]);
			}
			if (pflag) adbpr("%8t");
			switch (p->type) {
			case 0:
				gen2(a>>11, (a>>6)&0x1f, a&3, a&3);
				break;
			case 1:
				quick((a>>7)&0xf);
				if (pflag) printc(',');
				gen1(a>>11, a&3);
				break;
			case 2:
				gen1(a>>11, a&3);
				break;
			case 3:
				if (pflag) adbpr("%s,", preg[(a>>7)&0xf]);
				gen1(a>>11, a&3);
				break;
			}
			if (p->extra) {
				if (pflag) printc(',');
				do_extra(p->extra);
			}
			return;
		}
	}
	if (pflag) adbpr("??");
}

op3(a)
{
	int itype, ftype;
	int i;
	short l1, l2;
	register struct o3 *p;
	short cmp;

	a &= 0xffffff;
	cmp = a >> 3;
	for (p=ops3; p->mask != 0; p++) {
		if (p->val == (cmp & p->mask)) {
			if (pflag) adbpr(p->name);
			switch (p->typef) {
			case 0:
				itype = (a>>8)&3;
				l1 = l2 = itype;
				if (pflag) printc("bw?d"[itype]);
				break;
			case 1:
				ftype = (a>>8)&1;
				l1 = l2 = flen[ftype];
				if (pflag) printc("lf"[ftype]);
				break;
			case 2:
				itype = (a>>8)&3;
				ftype = (a>>10) & 1;
				l1 = flen[ftype];
				l2 = itype;
				if (pflag) {
					printc("lf"[ftype]);
					printc("bw?d"[itype]);
				}
				break;
			case 3:
				itype = (a>>8)&3;
				ftype = (a>>10) & 1;
				l1 = itype;
				l2 = flen[ftype];
				if (pflag) {
					printc("bw?d"[itype]);
					printc("lf"[ftype]);
				}
				break;
			case 4:
				l1 = l2 = 3;
				break;
			case 5:
				l1 = flen[0];
				l2 = flen[1];
				break;
			case 6:
				l1 = flen[1];
				l2 = flen[0];
				break;
			}
			if (pflag) adbpr("%8t");
			if (p->regf == 0) {
				if (pflag) adbpr("r%d,", (a>>11) & 7);
			}
			if (p->f1 == 0 && p->f2 == 0) {
				gen2(a>>19, (a>>14)&0x1f, l1, l2);
			} else {
				i = (a>>14) & 0x1f;
				if (p->f2 == 3) {
					do_ss(i>>1);
					if (pflag) printc(',');
				}
				if (p->f1 == 0) {
					gen1(a>>19, l1);
					if (p->f2 != 3)
						if (pflag) printc(',');
				}
				if (p->f1 >= 4) {
					gen1(a>>19, p->f1 - 4);
					if (pflag) printc(',');
				}
				switch (p->f2) {
				case 0:
					gen1(i, l1);
					      break;
				case 1:
					do_uwb(i>>2);
					break;
				case 2:
					do_xx(i>>1);
					break;
				case 3:
					break;
				default:
					gen1(i, p->f2 - 4);
					break;
				}
			}
			if (p->extra) {
				if (pflag) printc(',');
				do_extra(p->extra);
			}
			return;
		}
	}
	if (pflag) adbpr("??");
}

gen2(m1, m2, l1, l2)
{
	int idx1, idx2;

	if (m1 >= 0x1c) { /* scaled indexing */
		idx1 = egetchar();
	}
	if (m2 >= 0x1c) {
		idx2 = egetchar();
	}
	if (m1 >= 0x1c)
		sc_gen(idx1, m1&3);
	else
		sub_gen(m1, l1);
	if (pflag) printc(',');
	if (m2 >= 0x1c)
		sc_gen(idx2, m2&3);
	else
		sub_gen(m2, l2);
}
gen1(mode, len)
{
	int idx;

	if (mode >= 0x1c) {	/* scaled indexing */
		idx = egetchar();
		sc_gen(idx, mode&3);
	} else
		sub_gen(mode, len);
}
quick(x)
{
	if (x <= 7) {
		if (pflag) adbpr("$%R", x);
	} else
		if (pflag) adbpr("$%R", x-16);
}

/* scaled indexing - index byte in idx, scale factor in slen */
sc_gen(idx, slen)
{
	int mode, reg;

	mode = idx>>3;
	reg = idx & 7;
	if (mode == 0x14) {	/* immediate */
		if (pflag) adbpr("BAD");
		return;
	}
	sub_gen(mode, 0);
	if (pflag) adbpr("[r%d:%c]", reg, "bwdq"[slen]);
}

/* generic, but not scaled - */
sub_gen(mode, len)
{
	int d1, d2;

	if (mode <= 7) {	/* register */
		if (pflag) adbpr("%c%d", (len & 8) ? 'f' : 'r', mode);
		return;
	}
	if (mode <= 15) {	/* register relative */
		d1 = getdisp();
		if (pflag) adbpr("%R(r%d)", d1, mode&7);
		return;
	}
	if (mode <= 18) {	/* memory relative */
		d1 = getdisp();
		d2 = getdisp();
		if (pflag) adbpr("%R(%R(%s))", d2, d1, rnm[mode-16]);
		return;
	}
	if (mode >= 0x18) {	/* memory space */
		d1 = getdisp();
		if (pflag) adbpr("%R(%s)", d1, rnm[mode-0x18]);
		return;
	}
	switch (mode) {
	case 0x14:	/* immediate */
		putimm(len);
		return;
	case 0x15:	/* absolute */
		d1 = getdisp();
		if (pflag) psymoff(d1, IDSYM, "");
		return;
	case 0x16:	/* external */
		d1 = getdisp();
		d2 = getdisp();
		if (pflag) adbpr("ext(%R)%R", d1, d2);
		return;
	case 0x17:	/* top of stack */
		if (pflag) adbpr("tos");
		return;
	default:
		if (pflag) adbpr("??");
	}
}

/* get a 1 to 4 byte signed displacement */
int
getdisp()
{
	int a, b, c, d;

	a = egetchar();
	if ((a & 0x80) == 0) {
		if (a < 0x40)
			return(a);
		else
			return(a-0x80);
	}
	if ((a & 0xc0) == 0x80) {	/* short */
		b = egetchar();
		a = a<<8 | b;
		a &= 0x3fff;
		if (a < 0x2000)
			return(a);
		else
			return(a-0x4000);
	}
	/* long */
	b = egetchar(); c = egetchar(); d = egetchar();
	a = (a << 24) | (b << 16) | (c << 8) | d;
	a &= 0x3fffffff;
	if (a < 0x20000000)
		return(a);
	else
		return(a - 0x40000000);
}

/* print a 1 to 4 byte immediate */
/* or a 4 or 8 byte floating immediate */
int
putimm(len)
{
	int a, x;
	int flo;
	int i;

	flo = len & 8;
	len &= 7;
	x = 0;
	for (i=0; i<=len; i++) {
		a = egetchar();
		if (a == EOF) {
			if (pflag) adbpr("??");
			return;
		}
		if (i <= 3)
			x = x<<8 | a;
	/* note that bytes are backwards in immediates! */
	}
	if (flo) {
		int f, e;
		double ldexp();
		double d;

		if (len == 3) {	/* float */
			f = (x & 0x7fffff) | 0x800000;
			e = ((x>>23) & 0xff) - 127;
			e -= 23;
		} else {
			f = (x & 0xfffff) | 0x100000;
			e = ((x>>20) & 0x7ff) - 1023;
			e -= 20;
		}
		d = ldexp((double)f, e);
		if (x < 0)
			d = -d;
		if (pflag) adbpr("$%-32.18F", d);
	} else {
		if (len == 0 && (x & 0x80) != 0)
			x |= 0xffffff00;
		else if (len == 1 && (x & 0x8000) != 0)
			x |= 0xffff0000;
		if (pflag) adbpr("$%R",x);
	}
}

egetchar()
{
	int a;

	a = bchkget(inkdot(incp), Idsp);
	incp++;
	return a;
}

do_extra(x)
{
	int some = 0;
	int disp;
	int a, i, j;

	if (x & (1|8)) {	/* reglist */
		a = egetchar();
		if (pflag) printc('[');
		for (i=0; i<8; i++) {
			j = (x&1) ? 0x80>>i : 1<<i;
			if (a & j) {
				if (some)
					if (pflag) printc(',');
				if (pflag) adbpr("r%d", i);
				some++;
			}
		}
		if (pflag) printc(']');
		some++;
	}
	if (x & (2|16)) {	/* disp */
		if (some) {
			if (pflag) printc(',');
		} else
			some++;
		disp = getdisp();
		if (x & 2)
		{
			if (pflag) adbpr("%R", disp);
		} else {
			if (pflag) psymoff(dot + disp, ISYM, "");
		}
	}
	if (x & 4) {	/* short offset,len */
		if (some)
			if (pflag) printc(',');
		a = egetchar();
		if (pflag) adbpr("%R,%R", a>>5, (a&0x1f)+1);
	}
}

char *sname[] = {
	"bpr0", "bpr1", "?",   "?",
	"pf0",  "pf1",  "?",   "?",
	"sc",   "?",    "msr", "bcnt",
	"ptb0", "ptb1", "?",   "eia"
};

do_ss(x)
{
	if (pflag) adbpr(sname[x]);
}

do_uwb(x)
{
	int i, some;

	some = 0;
	if (pflag) printc('[');
	for (i=0; i<4; i++) {
		if (x & (1<<i)) {
			if (some) {
				if (pflag) printc(',');
			} else
				some++;
			if (pflag) printc("bwu"[i]);
		}
	}
	if (pflag) printc(']');
}

do_xx(x)
{
	int i, some;

	some = 0;
	if (pflag) printc('[');
	for (i=0; i<4; i++) {
		if (x & (1<<i)) {
			if (some) {
				if (pflag) printc(',');
			} else
				some++;
			if (pflag) printc("ifmc"[i]);
		}
	}
	if (pflag) printc(']');
}
q d   I]   cmd/adb/ns32000/output.c  /*	@(#)output.c	1.2	*/
#include "defs.h"

SCCSID(@(#)output.c	1.2);

static char printbuf[MAXLIN];
static char *printptr = printbuf;
static char *digitptr;
static void printd      ate();
static void printoct();
static void printnum();
static void printdbl();

int eqstr(s1, s2)
    STRING s1;
    STRING s2;
{
	return (!strcmp(s1,s2));
}

void printc(c)
    char c;
{
    char   d;
    STRING q;
    short  posn;
    short  tabs;
    short  p;

    if (mkfault)
		return; 
    else if ((*printptr = c) == EOR) {
        tabs = 0;
	posn = 0;
	q = printbuf;
	for (p = 0; p < printptr - printbuf; p++) {
		d = printbuf[p];
		if ((p & 07) == 0 && posn) {
			tabs++;
			posn = 0; 
		}
		if (d == SPACE)
			posn++; 
		else {
			while (tabs > 0 ) {
				*q++ = TB;
				tabs--; 
			}
			while (posn > 0 ) {
				*q++ = SPACE;
				posn--; 
			}
			*q++ = d;
		}
	}
	*q++ = EOR;
	if (-1 == write(outfile, printbuf, (unsigned) (q - printbuf)))
		perror("printc");
	printptr = printbuf;
	}
    else if (c == TB) {
	*printptr++ = SPACE;
        while ((printptr - printbuf) & 07)
		*printptr++ = SPACE; 
    } 
    else if (c)
	printptr++;
}

charpos()
{
	return(printptr - printbuf);
}

void flushbuf()
{
	if (printptr != printbuf) 
		printc(EOR);
}

/*VARARGS1*/
void adbpr(fmat, a1)
    STRING fmat;
    STRING *a1;
{
    STRING  fptr;
    STRING  s;
    short   *vptr;
    int     *dptr;
    double  *r2ptr;
    float   *rptr;
    short   width;
    short   prec;
    char    c;
    char    adj;
    short   x;
    short   n;
    int     lx;
    char    digits[64];

    fptr = fmat;
    vptr = (short *) &a1;
    dptr = (int *) vptr;

    while (c = *fptr++) {
		if (c != '%')
			printc(c);
		else {
			if (*fptr == '-' ) { 
				adj = 'l';
				fptr++;
			}
			else
				adj = 'r';
			width = convert(&fptr);
			if (*fptr == '.') {
				fptr++; 
				prec = convert(&fptr); 
			}
			else 
				prec = -1;
			digitptr = digits;
			rptr = (float *) dptr;
			r2ptr = (double *) dptr;
			x = shorten(lx = *dptr++);
		    	s = 0;
			switch (c = *fptr++) {

			case 'd':
                	case 'u':
                    		printnum(x, c, 10);
		    		break;

                	case 'o':
		    		printoct((unsigned short)x, 0);
		    		break;
					
                	case 'q':
		    		lx = x;
		    		printoct(lx, -1);
		    		break;

                	case 'x':
                    		printdbl(x, 16);
				break;

                	case 'r':
                    		printdbl(lx = x, radix);
				break;

                	case 'R':
                    		printdbl(lx, radix);
		    		vptr++;
		    		break;

                	case 'Y':
                    		printdate((long) lx);
		    		vptr++;
		    		break;

                	case 'D':
                	case 'U':
                    		printdbl(lx, 10);
		    		vptr++;
		    		break;

                	case 'O':
                    		printoct(lx, 0);
		    		vptr++; 
		    		break;

                	case 'Q':
                    		printoct(lx, -1);
		    		vptr++;
		    		break;

                	case 'X':
                    		printdbl(lx, 16);
		    		vptr++;
		    		break;

                	case 'c':
                    		printc(x);
		    		break;

                	case 's':
                    		s = (char *) lx;
                    		break;

                	case 'f':
				(void) sprintf(s = digits, "%-16.9e", *rptr); 
                    		prec = -1; 
                    		break;

                	case 'F':
                    		dptr++;
				(void) sprintf(s = digits, "%-32.18e", *r2ptr); 
                    		prec = -1; 
                    		break;

                	case 'm':
                    		vptr--;
		    		break;

                	case 'M':
                    		width = x;
		    		break;

                	case 'T':
                	case 't':
                    		if (c == 'T')
					width = x;
                    		else
					dptr--;
                    		if (width)
				width -= charpos() % width;
                    		break;

                	default:
                    		printc(c);
		    		dptr--;
		}

            if (s == 0) {
		*digitptr = 0;
		s = digits;
            }
            n = strlen(s);
            n = (prec < n && prec >= 0 ? prec : n);
            width -= n;
            if (adj == 'r') { 
		while (width-- > 0)
			printc(SPACE);
            }
            while (n--)
		printc(*s++);
            while (width-- > 0 )
		printc(SPACE);
            digitptr = digits;
	    }
	}
}

static void printdate(tvec)
 	long tvec;
{
 	int    i;
 	STRING timeptr;

 	timeptr = ctime(&tvec);
 	for (i = 20; i < 24; i++) 
		*digitptr++ = *(timeptr + i);
 	for (i = 3; i < 19; i++) 
		*digitptr++ = *(timeptr + i);
}

void prints(s)
	char *s;
{
	adbpr("%s", s);
}

void newline()
{
    printc(EOR);
}

static int convert(cp)
	STRING *cp;
{
	char c;
    int  n;

	n = 0;
	while (((c = *(*cp)++) >= '0') && (c <= '9')) 
		n = n * 10 + c - '0';
	(*cp)--;
	return(n);
}

static void printnum(n, fmat, base)
    int n;
{
	char k;
	int  *dptr;
	int  digs[15];

	dptr = digs;
	if (n < 0 && fmat == 'd') {
		n = -n;
		*digitptr++ = '-'; 
	}
	while (n) {
		*dptr++ = ((unsigned) n) % base;
		 n = ((unsigned) n) / base;
	}
	if (dptr == digs) 
		*dptr++ = 0;
	while (dptr != digs) {  
		k = *--dptr;
		*digitptr++ = (k + (k <= 9 ? '0' : 'a' - 10));
	}
}      

static void printoct(po, s)
    int po;
    int s;
{
    int  i;
    char digs[12];

    if (s) 
		if (po < 0) { 
			po = -po;
			*digitptr++ = '-';
        }
		else
			if (s > 0) 
				*digitptr++ = '+';
    for (i = 0; i <= 11; i++) { 
		digs[i] = po & 07;
		po >>= 3; 
	}
    digs[10] &= 03;
	digs[11] = 0;
    for (i = 11; i >= 0; i--)
		if (digs[i]) 
			break;
    for (i++; i >= 0; i--) 
		*digitptr++ = digs[i] + '0';
}

static void printdbl(lxy, base)
	int lxy;
	int base;
{ 
	char digs[35 * sizeof(int)];
	char *cp1;

    cp1 = digs; 
    if ((lxy & 0xFFFF0000L) == 0xFFFF0000L) {
        *cp1++ = '-'; 
        lxy = -lxy;
	}
	(void) sprintf(cp1, base==16 ? "%lx" : "%ld", lxy);
	cp1 = digs;
	while (*digitptr++ = *cp1++)
		;
	--digitptr;
}

void iclose()
{
    if (infile) {
		if (-1 == close(infile))
            perror("iclose");
	infile = 0;
    }
}

void oclose()
{
    if (outfile != 1) {
		flushbuf();
		if (-1 == close(outfile))
            perror("oclode");
		outfile = 1;
    }
}

void endline()
{
    if (maxpos <= charpos()) 
		adbpr("\n");
}
q n   LTt   Pcmd/adb/ns32000/pcs.c /*	@(#)pcs.c	1.2	*/
/* 
 *  Subprocess control 
 */

#include "defs.h"

SCCSID(@(#)pcs.c	1.2);

void subpcs(modif)
    char modif;
{
    int    check;
    int    execsig;
    int    runmode;
    int    oldflag;
    BKPTR  bkptr;
    STRING comptr;
    
    execsig = 0;
    loopcnt = cntval;
    
    switch (modif) {
    
        case 'd':
        case 'D':                     /* delete breakpoint */
            if (bkptr = scanbkpt(dot)) {
                bkptr->flag=0;
                return;
            } 
            else
                error(NOBKPT);
    
        case 'b':
        case 'B':           /* set breakpoint */
            oldflag = 0;
            if (bkptr = scanbkpt(dot)) { 
                if (bkptr->flag == BKPTEXEC) 
                    oldflag = 1;
                    bkptr->flag = 0;
            }
            for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt)
                if (bkptr->flag == 0) 
                    break;
            if (bkptr == 0)
                if (((int) (bkptr = (BKPTR) sbrk(sizeof *bkptr))) == -1) 
                    error(SZBKPT);
                else { 
                    bkptr->nxtbkpt = bkpthead;
                    bkpthead = bkptr;
                }
            bkptr->loc = dot;
            bkptr->initcnt = bkptr->count = cntval;
            bkptr->flag = oldflag ? BKPTEXEC : BKPTSET;
            check = MAXCOM - 11;
            comptr = bkptr->comm;
            (void) rdc();
            lp--;
            do { 
                *comptr++ = readchar();
            } while (check-- && lastc != EOR);
                *comptr = 0;
            lp--;
            if (check)
                return;
            else
                error(EXBKPT);
    
        case 'k':
        case 'K':             /* exit */
            if (pid) { 
                adbpr("%d: killed", pid);
                endpcs();
                return;
            }
            else
                error(NOPCS);
    
        case 'r':
        case 'R':                    /* run program */
            endpcs();
            setup();
            runmode = CONTIN;
            break;
    
        case 's': 
        case 'S':                         /* single step */
            if (pid) {
                runmode = SINGLE;
                execsig = getsig(signo);
            }
            else { 
                setup();
                loopcnt--;
            }
            break;
    
        case 'c': 
        case 'C': 
        case 0:          /* continue with optional signal */
            if (pid == 0) 
                error(NOPCS);
            runmode = CONTIN;
            execsig = getsig(signo);
            break;
    
        default:
            error(BADMOD);
    }
    
    if (loopcnt > 0 && runpcs(runmode,execsig)) 
        adbpr("breakpoint%16t");
    else
        adbpr("stopped at%16t");
    delbp();
    printpc();
}
q `   UW^s   cmd/adb/ns32000/print.c /*	@(#)print.c	1.2	*/
/* 
 *  General printing routines
 */

#include "defs.h"

SCCSID(@(#)print.c	1.2);

static STRING signals[] = {
				"",
				"hangup",
				"interrupt",
				"quit",
				"illegal instruction",
				"trace/BPT",
				"IOT",
				"EMT",
				"floating exception",
				"killed",
				"bus error",
				"memory fault",
				"bad system call",
				"broken pipe",
				"alarm call",
				"terminated",
				"user defined - 1",
				"user defined - 2",
				"death of a child",
				"power fail",
			};

static void printregs();
static void printfregs();
static void printmap();

void dollar(modif)
int modif;
{
unsigned narg;
short  i;
BKPTR  bkptr;
int    word;
STRING comptr;
int    argp;
int    frame;
int    oldframe, newframe;
SYMPTR symp;
int newest;
int j;

if (cntflg == FALSE)
	cntval = -1;

switch (modif) {

	case '<':
	case '>': {
		char  userfile[64];
		short index;

		index = 0;
		if (modif == '<')
			iclose();
		else
			oclose();
		if (rdc() != EOR) {
			do { 
				userfile[index++] = lastc;
				if (index >= 63)
						error(LONGFIL);
			} whi      le (readchar() != EOR);
			userfile[index] = 0;
			if (modif == '<') { 
				infile = open(userfile, 0);
				if (infile < 0) {
						infile = 0; 
						error(NOTOPEN);
				}
			}
			else { 
				outfile = open(userfile, 1);
				if (outfile < 0)
						outfile = creat(userfile, 0644);
				else 
						if (-1L == lseek(outfile, 0L, 2))
						    perror("dollar");
			}
		}
		lp--;
		}
		break;

	case 'd':
		if (adrflg) {
			if (adrval < 2 || adrval > 16)
				error(BADRAD);
			radix = adrval;
		}
			else
				radix = DEFRADIX;
		break;

	case 'o':
	   radix = 8;
	   break;

	case 'q': 
	case 'Q': 
	case '%':
		done();

	case 'w':
	case 'W':
		maxpos = (adrflg ? adrval : MAXPOS);
		break;

	case 's': 
	case 'S':
		maxoff = (adrflg ? adrval : MAXOFF);
		break;

	case 'v': 
	case 'V':
		prints("variables\n");
		for (i = 0; i < VARNO; i++)
			if (var[i]) {
				printc((i <= 9 ? '0' : 'a' - 10) + i);
				adbpr(" = %R\n",var[i]);
			}
		break;

	case 'm': 
	case 'M':
		printmap("? map", &qstmap);
		printmap("/ map", &slshmap);
		break;

	case   0: 
	case '?':
		if (pid)
			adbpr("pcs id = %d\n", pid);
		else
			prints("no process\n");
		sigprint();
		flushbuf();

	case 'r':
	case 'R':
		printregs();
		return;

	case 'c':
	case 'C':
		if (adrflg)
		{
 			callpc = get(adrval+4, DSP);
 			frame = get(adrval, DSP);
 			argp = frame + 8;
 			newframe = 0;
		}
		else
		{
			callpc = ADBREG(PC);
 			if (findsym(callpc, ISYM) == 0 || 
 			    (get(callpc, ISP) & 0xff) == 0x82) {
 				/* at entry - fp not saved yet */
 				frame = ADBREG(SP) - 4;
 				newframe = ADBREG(FP);
 			} else {
 				frame = ADBREG(FP);
 				newframe = 0;
 			}
 			argp = frame + 8;
		}
		newest = 1;
		while (cntval--) {
			chkerr();
			adbpr("%s(", findsym(callpc, ISYM) == 
					   0x7fffffffL ? "?" : symbol.n_nptr);
 			callpc = get(frame+4, DSP);
 			narg = get(callpc, ISP);
 			if ((narg & 0xFFFF) == 0xA57C) { /* adjspb ? */
 				narg >>= 16;
 				narg = (0x100 - (narg & 0xff)) / 4;
 			} else
				narg = 0;
			for ( ; ; ) { 
				if (narg == 0)
					break;
				adbpr("%R", get(argp, DSP));
				argp += 4;
				if (--narg != 0)
					printc(',');
			}
			prints(")\n");

			oldframe = frame;
 			if (newframe) {
 				frame = newframe;
 				newframe = 0;
 			} else
 				frame = get(frame, DSP);
 			argp = frame + 8;
			if (frame == 0 || frame <= oldframe)
				break;
		}
		break;

	case 'e': 
	case 'E':            /* Print externals */
		symset();
		while (symp = symget()) {
			chkerr();
			if (((symp->n_scnum == 3 || symp->n_scnum == 2) &&
				symp->n_sclass == C_EXT) ||
				(symp->n_scnum == 0 &&
				symp->n_sclass == C_EXT && symp->n_value != 0))
			{
				adbpr("%s:%12t%R\n", symp->n_nptr,
						get((int) symp->n_value, DSP));
			}
			skip_aux(symp);
		}
		break;

	case 'b':           /* print breakpoints */
	case 'B':           /* set default c frame */
		adbpr("breakpoints\ncount%8tbkpt%24tcommand\n");
		for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt) {
			if (bkptr->flag) {
				adbpr("%-8.8d", bkptr->count);
				psymoff(bkptr->loc, ISYM, "%24t");
				comptr = bkptr->comm;
				while (*comptr)
						printc(*comptr++);
			}
			}
		break;

	case 't':
		trace = ! trace;
		break;

	case 'f':
	case 'F':
		printfregs();
		return;

	default: 
		error(BADMOD);
}
}

static void printmap(s, amap)
STRING s;
MAP    *amap;
{
	int fid;

	fid = amap->ufd;
	adbpr("%s%12t`%s'\n", s, (fid < 0 ? "-" : 
		(fid == fcor ? corfil : symfil)));
	adbpr("b1 = %-16R", amap->b1);
	adbpr("e1 = %-16R", amap->e1);
	adbpr("f1 = %-16R", amap->f1);
	adbpr("\nb2 = %-16R", amap->b2);
	adbpr("e2 = %-16R", amap->e2);
	adbpr("f2 = %-16R", amap->f2);
	printc(EOR);
}
   
static void printregs()
{
REGPTR p;
int    v;

	for (p = reglist; p < &reglist[MAXREGS]; p++) { 
		v = ADBREG(p->roffs);
		adbpr("%s%6t%R %16t", p->rname, v);
		valpr(v, (p->roffs == PC ? ISYM : DSYM));
		printc(EOR);
	}
	printpc();
}
   
static void 
printfregs()
{
	REGPTR	p;
	long	v;
	union {
		double df;
		struct {
			unsigned u_low;
			unsigned u_high;
		} sf;
	} uf;

	p = freglist;
	v = ADBREG(p->roffs);
	adbpr("%s%6t%x %16t", p->rname, v);
	printc(EOR);

	for (p++; p < &freglist[MAXFREGS]; p++) {
		uf.sf.u_high = ADBREG(p++->roffs);
		uf.sf.u_low = ADBREG(p->roffs);
		if ((uf.sf.u_high & 0x7ff00000) == 0x7ff00000)
			adbpr("%s%6tINFINITY %x %x%16t", p->rname,
				uf.sf.u_high, uf.sf.u_low);
		else if (((uf.sf.u_high & 0x7ff00000) == 0) &&
				((uf.sf.u_high & 0xfffff) || uf.sf.u_low))
			adbpr("%s%6tDENORMALIZED %x %x%16t", p->rname,
				uf.sf.u_high, uf.sf.u_low);
		else
			adbpr("%s%6t%-32.18F %16t", p->rname, uf.df);
		printc(EOR);
	}
}

struct grres getreg(regnam)
int regnam;
{
	REGPTR p;
	STRING regptr;
	char   *olp;
	struct grres result;

	result.sf = 0;
	result.roff = 0;

	olp = lp;
	for (p = reglist; p < &reglist[MAXREGS]; p++) { 
		regptr = p->rname;
		if (regnam == *regptr++) {
			while (*regptr) { 
				if (readchar() != *regptr++) { 
					--regptr;
					break;
				}
			}
			if (*regptr)
				lp = olp;
			else {
				result.sf = 1;
				result.roff = p->roffs;
				return(result);
			}
		}
	}
	lp = olp;
	return(result);
}

void print      pc()
{
	dot = ADBREG(PC);
	psymoff(dot, ISYM, ":%16t"); 
	printins(ISP, (int) chkget(dot, ISP), 1);
	printc(EOR);
}

void sigprint()
{
if ((signo >= 0) && (signo <= NSIG))
prints(signals[signo]);
}
q MV   vW^(   cmd/adb/ns32000/runpcs.c  /*	@(#)runpcs.c	1.2	*/
/* 
 *  Service routines for subprocess control 
 */

#include "defs.h"

SCCSID(@(#)runpcs.c	1.2);

#define BPOUT 0
#define BPIN 1

static int  bpstate = BPOUT;
static int  userpc = 1;
static void doexec();
static void setbp();
static void bpwait();
static void readregs();

int getsig(sig)
    int sig;
{
    return(expr(0) ? expv : sig);
}

int runpcs(runmode,execsig)
    int runmode;
    int execsig;
{
    int   rc;
    BKPTR bkpt;
    extern int usrfcntl ;

    if (adrflg) {
        if (bkpt = scanbkpt(userpc))
			bkpt->flag = BKPTSET; 
        userpc = dot;
    }
    adbpr("%s: running\n", symfil);

    setbp();
    while (--loopcnt >= 0) {
        if ((bkpt = scanbkpt(userpc)) && (bkpt->flag == BKPTEXEC)) {
            dot = bkpt->loc;
            execbkpt(bkpt, execsig);
            execsig = 0;
            if (runmode == CONTIN) { 
		fcntl(0,F_SETFL,usrfcntl) ;
                if (-1 == ptrace(runmode, pid, userpc, execsig))
                    perror("runpcs");
                bpwait();
				chkerr();
				execsig = 0;
				readregs();
            }
        }
		else {
            if (-1 == ptrace(runmode, pid, userpc, execsig))
                perror("runpcs");
            bpwait();
			chkerr();
			execsig = 0;
			readregs();
        }

        if ((signo == 0) && (bkpt = scanbkpt(userpc))) {
            bkpt->flag = BKPTEXEC;
            --bkpt->count;
            command(bkpt->comm, ':');
            if ((bkpt->count == 0)) { 
				bkpt->count = bkpt->initcnt;
				rc = 1;
				loopcnt = 0;
            }
			else
                if (runmode == CONTIN)
					loopcnt++;
        } 
		else { 
			execsig = signo;
			rc = 0;
        }
    }
    return(rc);
}

void endpcs()
{
    BKPTR bkptr;

    if (pid) {
		(void) ptrace(EXIT, pid, 0, 0);
		pid = 0;
		userpc = 1;
        for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt)
			if (bkptr->flag) 
				bkptr->flag = BKPTSET;
    }
    bpstate = BPOUT;
}

void setup()
{
    if (-1 == close(fsym))
        perror("setup");
    fsym = -1;
    if ((pid = fork()) == 0) { 
		(void) ptrace(SETTRC, 0, 0, 0);
        if (-1 == (int) signal(SIGINT, sigint.siFUN))
			perror("setup");
		if (-1 == (int) signal(SIGQUIT, sigqit.siFUN))
			perror("setup");
        doexec(); 
		(void) exit(0);
    } 
    else if (pid == -1) 
		error(NOFORK);
    else { 
		bpwait();
		errno = 0;
		if ((-1 == (int) (u.u_ar0 = (int *) ptrace(RUREGS, 
			pid, (int) (((char *) &u.u_ar0) - ((int) &u)), 0))) && 
			(errno != 0))
			perror("setup");
        u.u_ar0 = (int *) (((char *) u.u_ar0) - ADDR_U);
        u.u_ar0 = (int *) (((char *) u.u_ar0) + (int) &u);
		readregs();
		lp[0] = EOR;
		lp[1] = 0;
        if (-1 == (fsym = open(symfil, wtflag)))
            perror("setup");
        if (errflg != NULL) { 
			(void) fprintf(stderr, "%s: cannot execute\n", symfil);
            endpcs();
			error((STRING) NULL);
        }
    }
    bpstate=BPOUT;
}

static execbkpt(bkptr, execsig)
    BKPTR bkptr;
    int execsig;
{
    extern struct termio usrtermio ;
    extern int usrfcntl ;

    delbp();
    ioctl(0,TCSETAF,&usrtermio) ;
    fcntl(0,F_SETFL,usrfcntl) ;
    (void) ptrace(SINGLE, pid, bkptr->loc, execsig);
    bkptr->flag = BKPTSET;
    bpwait(); 
    chkerr(); 
    readregs();
    setbp();
}


static void doexec()
{
    STRING argl[MAXARG];
    char   args[LINSIZ];
    STRING p = args;
    STRING *ap = argl;
    STRING filnam;

    *ap++ = symfil;
    do { 
		if (rdc() == EOR) 
			break;
        *ap = p;
        while (lastc != EOR && lastc != SPACE && lastc != TB) { 
			*p++ = lastc;
			(void) readchar(); 
		}
        *p++ = 0;
		filnam = *ap + 1;
        if (**ap == '<') {
			if (-1 == close(0))
                perror("doexec");
            if (open(filnam, 0) == -1) { 
				perror("doexec");
                (void) exit(0);
            }
        } 
		else if (**ap == '>') {
			if (-1 == close(1))
                perror("doexec - close 2");
            if (creat(filnam, 0666) == -1) { 
				perror("doexec - creat");
                (void) exit(0);
            }
        }
		else 
			ap++;
    } while (lastc != EOR);
    *ap++ = 0;
    if (-1 == exect(symfil, argl, environ))
        perror("doexec - exect");
}

BKPTR scanbkpt(adr)
    int adr;
{
    BKPTR bkptr;

    for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt)
		if (bkptr->flag && bkptr->loc == adr)
			break;

    return(bkptr);
}

void delbp()
{
    int   a;
    BKPTR bkptr;
    int   ptrres;

    if (bpstate != BPOUT) {
        for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt) {  
			if (bkptr->flag) { 
				a = bkptr->loc;
				errno = 0;
                if ((-1 == (ptrres = ptrace(RIUSER, pid, a, 0))) && 
					(errno != 0))
                    perror("delbp");
				errno = 0;
                if ((-1 == ptrace(WIUSER, pid, a, 
					(bkptr->ins & 0xFF) | (ptrres & ~0xFF))))
                          perror("delbp");
            }
        }
        bpstate = BPOUT;
    }
}

static void setbp()
{
    int   a;
    BKPTR bkptr;

    if (bpstate != BPIN) {
        for (bkptr = bkpthead; bkptr; bkptr = bkptr->nxtbkpt) { 
			if (bkptr->flag) { 
				a = bkptr->loc;
				errno = 0;
                bkptr->ins = ptrace(RIUSER, pid, a, 0);
                if ((errno != 0) && (-1 == bkptr->ins))
                    perror("setbp");
				errno = 0;
                if ((-1 == ptrace(WIUSER, pid, a, BPT | 
					(bkptr->ins&~0xFF)))) { 
					prints("cannot set breakpoint: ");
                    psymoff(bkptr->loc, ISYM, "\n");
                }
            }
        }
		bpstate = BPIN;
    }
}

static void bpwait()
{
    int w;
    int stat;
    extern struct termio adbtermio,usrtermio ;
    extern int adbfcntl,usrfcntl ;

    if (-1 == (int) signal(SIGINT, SIG_IGN))
		perror("bpwait");
    while ((w = wait(&stat)) != pid && w != -1 )
		;
    if (-1 == (int) signal(SIGINT, sigint.siFUN))
		perror("bpwait");

/*	Save the terminal state that the process had and restore a	*/
/*	state that can be used for talking to adb.			*/

    ioctl(0,TCGETA,&usrtermio) ;
    ioctl(0,TCSETAF,&adbtermio) ;
    usrfcntl = fcntl(0,F_GETFL,0) ;
    fcntl(0,F_SETFL,adbfcntl) ;

    if (w == -1) { 
		pid = 0;
        errflg = BADWAIT;
    }
    else if ((stat & 0177) != 0177) { 
		if (signo = stat & 0177)
			sigprint();
        if (stat & 0200) { 
			prints(" - core dumped");
            if (-1 == close(fcor))
                perror("bpwait");
            setcor();
        }
        pid = 0;
        errflg = ENDPCS;
    }
    else { 
		signo = stat >> 8;
        if (signo != SIGTRAP)
			sigprint();
        else 
			signo = 0;
        flushbuf();
    }
}

static void readregs()      /* Get register values from child */
{
    int i;
    int ptrres;

    for (i = 0; i < MAXREGS; i++) { 
	errno = 0;
	if ((-1 == (ptrres = ptrace(RUREGS, pid,
		    SYSREG(reglist[i].roffs), 0))) && (errno != 0))
        	perror("readregs");
        ADBREG(reglist[i].roffs) = ptrres;
    }
    userpc = ADBREG(PC);
    for (i = 0; i < MAXFREGS; i++) { 
	errno = 0;
	if ((-1 == (ptrres = ptrace(RUREGS, pid,
		    SYSREG(freglist[i].roffs), 0))) && (errno != 0))
        	perror("readregs");
        ADBREG(freglist[i].roffs) = ptrres;
    }
}
q Z   d]   cmd/adb/ns32000/setup.c /*	@(#)setup.c	1.2	*/
#include "defs.h"

SCCSID(@(#)setup.c	1.2);

#define TXTRNDSIZ 512


void setsym()
{
	SYMSLAVE    *symptr;
	char numaux;
	SYMPTR      symp;
	AOUTHDR aouthdr;
	FILHDR filehdr;
	SCNHDR scnhdr;

	qstmap.ufd = fsym = getfile(symfil, 1);
	if((read(fsym,(char *) &filehdr,FILHSZ) == FILHSZ) && filehdr.f_opthdr)
	{
		read(fsym, (char *) &aouthdr, filehdr.f_opthdr);
		magic = aouthdr.magic;
		txtsiz = (aouthdr.tsize & ~0x80000000) ;
		datsiz = (aouthdr.dsize & ~0x80000000) ;
		entrypt = aouthdr.entry;
	}
	symbas = filehdr.f_symptr;
	symnum = filehdr.f_nsyms;
#ifdef DEBUG
	printf("symnum=%x\n",symnum);
#endif
	read(fsym, (char *) &scnhdr, SCNHSZ);
/* comments contain original 5.2 code */
/*	qstmap.b1 = 0;*/
        qstmap.b1 = (magic == 0411 ? 0x200 : scnhdr.s_vaddr);;
/*	qstmap.e1 = txtsiz;*/
        qstmap.e1 = qstmap.b1 + (magic == 0407 ? symbas : 
				 magic == 0411 ? txtsiz+((int)sizeof(filehdr))
						       +((int)sizeof(aouthdr)) :
						 txtsiz);
/*	qstmap.f1 = scnhdr.s_scnptr;*/
        qstmap.f1 = (magic == 0411 ? 0x200 : scnhdr.s_scnptr);
	read(fsym, (char *) &scnhdr, SCNHSZ);
/*	qstmap.b2 = (magic == 0410 ? round(txtsiz, TXTRNDSIZ) : txtsiz);*/
	qstmap.b2 = scnhdr.s_vaddr;
/*	qstmap.e2 = qstmap.b2 + datsiz;*/
        qstmap.e2 = qstmap.b2 + (magic == 0407 ? symbas : datsiz);
/*	qstmap.f2 = scnhdr.s_scnptr;*/
	qstmap.f2 = (magic == 0411 ? qstmap.e1 : scnhdr.s_scnptr);
#ifdef DEBUG
	printf("symbas=%x\n", symbas);
#endif

	symvec = (SYMSLAVE *) sbrk((1 + symnum) * sizeof (SYMSLAVE));
	if (((int) (symptr = symvec)) == -1) 
	{
		(void) fprintf(stderr, "%s\n", BADNAM);
		symptr = symvec = (SYMSLAVE *) sbrk(sizeof (SYMSLAVE));
		if (-1 == (int) symvec)
	            perror("setsym");
	}
	else 
	{
		readstrtbl( fsym, filehdr );
	        symset();
	        while ((symp = symget()) && errflg == NULL) 
		{
			if(symp->n_sclass<C_NULL||symp->n_sclass>=C_BLOCK||
				eqstr(symp->n_nptr, ".text")||
				eqstr(symp->n_nptr, ".data")||
				eqstr(symp->n_nptr, ".bss"))
			{
				symptr->typslave = N_DEBUG;
				symptr->valslave = 0;
				symptr++;
			}
			else
			{
				symptr->typslave = typesym( symp->n_scnum);
				symptr->valslave = symp->n_value;
				symptr++;
		        }
			/* get rid of auxilliary entries */
			skip_aux(symp);
			numaux = symp->n_numaux;
			while(numaux)
			{
				symptr->typslave = N_DEBUG;
				symptr->valslave = 0;
				symptr++;
				numaux--;
			}
		}
	    }
	symptr->typslave = ENDSYMS;
	if (magic == 0)
	qstmap.e1 = maxfile;
}

void setcor()
{
    slshmap.ufd = fcor = getfile(corfil, 2);
    if (read(fcor, (char *) &u, ctob(USIZE)) == ctob(USIZE)) {

	/* u.u_ar0 is an address relative to the incore UBLOCK
	   currently 0xFF0208.  It must be transformed to be
	   relative t      o u, a variable in adb's data space.   */

	u.u_ar0 = (int *) (((char *) u.u_ar0) - ADDR_U);
	u.u_ar0 = (int *) (((char *) u.u_ar0) + (int) &u);

	txtsiz = ctob(u.u_tsize);
	datsiz = ctob(u.u_dsize);
	stksiz = ctob(u.u_ssize);
	slshmap.b1 = ((magic == 0410 || magic == 0411) ? txtsiz : 0);
	slshmap.e1 = (magic == 0407 ? txtsiz : slshmap.b1) + datsiz;
	slshmap.f1 = ctob(USIZE);
	slshmap.b2 = maxstor - stksiz;
	slshmap.e2 = maxstor;
	slshmap.f2 = ctob(USIZE) + ((magic==0410 || magic==0411) ?
			datsiz : slshmap.e1);
	signo = u.u_arg[0] & 017;
	if (magic && magic != u.u_exdata.ux_mag)
	    (void) fprintf(stderr, "%s\n", BADMAGIC);
    } else
	u.u_ar0 = (int *) (((int) &u) + ADRREG);
}

static int create(f)
    STRING f;
{
    int fd;

    if ((fd = creat(f, 0644)) != -1) { 
	if (-1 == close(fd))
	    perror("create");
	return(open(f, wtflag));
    }
    else 
	return(-1);
}

static int getfile(filnam, cnt)
    STRING filnam;
{
    int symfid;

    if ( ! eqstr("-", filnam)) { 
	symfid = open(filnam, wtflag);
	if (symfid == -1 && argcount > cnt) { 
	    if (wtflag == O_RDWR)
	        symfid = create(filnam);
	    if (symfid == -1)
	        (void) fprintf(stderr, "Cannot open `%s'\n", filnam);
	}
    }
    else
	symfid = -1;
    return(symfid);
}

static int typesym(sflag) /* Returns the space to look in for value */
    short sflag;
{
	if(sflag == N_DEBUG)
		return(EXTRASYM);
    switch (sflag) {
	
	case SECT1:
	    return(ISYM);

	case SECT2:
	case SECT3:
	    return(DSYM);

	default:
	    return(NSYM);
    }
}
Lq l   1\   cmd/adb/ns32000/sym.c /*	@(#)sym.c	1.3	*/
/* 
 *  Symbol table and file handling service routines
 */

#include "defs.h"

SCCSID(@(#)sym.c	1.3);

#define	ERROR	(-1)		/* Signifies something is wrong */
static int     symrqd = TRUE;
static SYMTAB  symbuf;     	/* Room for 1 symbol */
static	long curoffs = (ERROR -1);
static	char	*strtab;	/* String for string table. */
struct	sh_name{
	char	name[ 9 ];
};
static	struct	sh_name	*shstrtab;	/* Space for all names contained */
					/* in symbol table. */
static	long	strtablen;


void valpr(v, idsp)
    int v;
    int idsp;
{
    unsigned d = findsym(v, idsp);

    if (d < maxoff) {
		adbpr("%s", symbol.n_nptr);
    		if (d)
			adbpr(OFFMODE, d);
    }
}

/*ARGSUSED*/
void localsym(cframe,newest)
	int cframe;
	int newest;
{
	int word;

	if(!newest)
	{
		locadr = (get(cframe,DSP)-4);
	}
	else
	{
		locadr = cframe - 4;
	}
}

void psymoff(v, symtype, s) /* Prints symbol, offset, and suffix */
	int  v;
	int  symtype;
	char *s;                       /* Suffix for print line */
{
    unsigned w;

    if (v != 0) 
		w = findsym(v, symtype);
    if (v == 0 || w >= maxoff)     /* || (v>=0 && v<maxoff && w!=0) */
		adbpr(LPRMODE, v);
    else { 
		adbpr("%s", symbol.n_nptr);
    		if (w)
			adbpr(OFFMODE, w);
    }
    adbpr(s);
}

/* added long rdsym( offset, symep )
 *	Stores symbol in location pointed to by symep.
 *	Returns offset for next syment
 *	Seeks done here if necessary; removed from other symt.c code
 *	for COFF, always just 0 or 1 auxiliary entries
 */

long
rdsym( offset, symep )
long offset;
register SYMENT *symep;
{
	register int numaux;

	if(offset <= 0 || offset >= symbas + symnum * SYMESZ)
		return(ERROR);
	lseek( fsym, offset, 0 );
	curoffs = offset;
	if ( read( fsym, (char *)symep, SYMESZ) < SYMESZ)
	{
		curoffs = ERROR -1;
		return(ERROR);
	}
#ifdef FLEXNAMES
	if( symep->n_zeroes == 0 )
	{
		if (symep->n_offset < 4 || symep->n_offset > strtablen)
		{
			printf("Bad string table offset @ 0x%lx\n",
				curoffs - SYMESZ);
			return (ERROR);
		}
		symep->n_nptr = &strtab[ symep->n_offset ];
	}
	else
#endif
	{
		long	i = offset - symbas;
		i /= SYMESZ;
		strncpy( shstrtab[ i ].name, symep->n_name, SYMNMLEN );
		shstrtab[ i ].name[ 8 ] = '\0';
		symep->n_zeroes = 0;
		symep->n_offset = 0;
		symep->n_nptr = shstrtab[ i ].name;
	}
/*
**	printf("Found name `%s'\n", symep->n_nptr);
*/
	curoffs += SYMESZ;
	return(curoffs);
}

/*	skip_aux - skip auxilliary entries

	input - symp = symbol just read
*/
long
skip_aux( symp )
register SYMENT *symp;
{
	register int numaux = symp->n_numaux;

	curoffs += numaux * AUXESZ;
	return(curoffs);
}

unsigned findsym(value, symtype) /* Linear search through slave array */
    int value;
    int symtype;
{
/* 
 *  Linear search through slave array; finds the symbol closest
 *  above value
 */
    int      diff;
    int      symval;
    int      offset;
    int      slvtype;
    SYMSLAVE *symptr;
    SYMSLAVE *symsav;

    diff = 0x7fffffffL;
    symsav = 0;
    if (symtype != NSYM && (symptr = symvec)) { 
	while (diff && (slvtype = symptr->typslave) != ENDSYMS) {  
		if (((slvtype == symtype) || ((symtype == IDSYM) &&
				((slvtype == DSYM) || (slvtype == ISYM)))) &&
				(slvtype != EXTRASYM)) {
			symval = symptr->valslave;
               		if (value - symval < diff && value >= symval) {
    				diff = value - symval;
      				symsav = symptr;
               		}
		}
		symptr++;
        }
        if (symsav) {      /* Best entry */
	    int ret;
            offset = symsav - symvec;
	    ret = rdsym((long)(symbas + off      set * SYMBOLSIZE), &symbol);
	    if (ret == ERROR)
                perror("findsym");
        }
    }
    return(diff);
}

/* sequential search through file */
void symset()
{
	if (-1L == lseek(fsym, (long) symbas, 0))
		perror("symset");
	curoffs = (long) symbas;
	(void) symread();
	curoffs = (long) symbas;
} 

SYMPTR symget()
{
	if (curoffs >= symbas + symnum * SYMESZ)
		return ((SYMPTR)NULL);
	if (symread())
		return (&symbuf);
	else
	{
		errflg = BADFIL;
		return ((SYMPTR)NULL);
	}
}
/*
	Note to future maintainers: this code used to be
	buffered in symbuf, but no longer is.  There is
	much remaining extraneous code.
*/

static int symread()
{
    if (rdsym(curoffs, &symbuf) == ERROR)
    {
	perror("symread");
	return (FALSE);
    }
    else
        return (TRUE);
}
int
readstrtbl( fd, filehdr)
int  fd;
FILHDR filehdr;
{
	extern char *sbrk();
	long home;
	register int i;

	home = lseek( fd, 0L, 1 );
	if ( lseek( fd, symbas, 0 ) == -1 )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	i = (((filehdr.f_nsyms + 1) * sizeof(struct sh_name)) + 3) & ~3;
	if ((shstrtab = (struct sh_name *)sbrk(i)) == (struct sh_name *)(-1))
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if ( lseek( fd, filehdr.f_nsyms * SYMESZ + filehdr.f_symptr, 0 ) == -1 )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if( read( fd, (char *) &strtablen, sizeof( long ) ) != sizeof( long ) )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if ((strtab = sbrk((strtablen + 3 ) & ~3)) == (char *)(-1))
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if ( read( fd, &strtab[ sizeof( long ) ], strtablen - sizeof( long ) )
		!= strtablen - sizeof( long ) )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	if ( strtab[ strtablen - 1 ] != '\0' )
	{
		(void) lseek( fd, home, 0 );
		return;
	}
	lseek( fd, home, 0 );
	/*
	**	Used for debugging the reading in of string table for FLEXNAMES.
	**	printf("STRING TABLE\n");
	**	for (i = 4; i < strtablen; i++)
	**	{
	**		if (strtab[i] == '\0')
	**			printf("^@\n");
	**		else if (strtab[i] < ' ')
	**			printf("^%c", strtab[i]|0100);
	**		else if (strtab[i] == '\177')
	**			printf("^?");
	**		else if (strtab[i] > '~')
	**			printf("M-%c", strtab[i]&0177);
	**		else
	**			printf("%c", strtab[i]);
	**	}
	*/
	return;
}
q Y   WTnq   kcmd/adb/ns32000/sys.h /*	@(#)sys.h	1.2	*/
/*
 *  External declarations for system call library routines
 */

extern int  close();
extern int  creat();
extern int  execl();
extern int  exit();
extern int  fork();
extern long lseek();
extern int  open();
extern int  ptrace();
extern int  read();
extern char *sbrk();
extern int  (* signal())();
extern int  wait();
extern int  write();
(q _   <$   cmd/adb/ns32000/machine.SV  /*	@(#)machine.h	1.3	*/
/* 
 * NS32000 UNIX parameters 
 */

/* User block in core file */

#define ADDR_U ((unsigned) 0x810000)
#define ADRREG ((unsigned) 0x1C4)
#define ADRFREG ((unsigned) 0x208)
union  Uuniontag {
    struct user strpart;
    char chrpart[ctob(USIZE)];
};

extern union Uuniontag Uunion;

/*  Note - the following define must appear after the above
 *  definition else the preprocessor will use the wrong u
 *  in the expansion of USIZE.
*/
#define u Uunion.strpart
q W   W
   cmd/asa.c /*	@(#)asa.c	1.3	*/

/*
 *	asa - interpret asa carriage control characters
 *
 *	This program is designed to make sense out of the output
 *	of fortran programs whose authors have used asa carriage
 *	control characters.  "asa" processes either the files
 *	whose names are given as arguments or the standard input
 *	if no file names are given.  "asa" processes each input files
 *	and produces the results to the standard output.
 *	The first character of each line is assumed to be a control
 *	character: the meanings of the control characters are:
 *
 *	' '	single-space before printing
 *	'0'	double-space before printing
 *	'-'	triple-space before printing
 *	'1'	new page before printing
 *	'+'	do not space at all before printing
 *
 *	A line beginning with '+' will overprint the previous line.
 *
 *	Lines beginning with other than the above characters are
 *	treated as if they began with ' '.  The first characters
 *	of such lines will be replaced by ' '.
 *	If any such lines appear,
 *	an appropriate diagnostic will appear on the standard error
 *	file after processing each file.  The return code reflects
 *	the error conditions after processing:
 *		0	if no error
 *		-1	output error
 *		>0	It shows there is no output error and
 *			there are some input files which cannot
 *			be opened. The return code is the total number
 *			of input files which cannot be opened.
 *
 *	The program forces the first line of each file to
 *	start on a new page.  This program requires the printer
 *	be able to perform the formfeed character.
 *
 *	example:
 *		asa [-s] [files]
 *	-s will suppress the error messages.
 *	if there are no files the input file defaults to stdin.
 */

#include <stdio.h>

/* program name, for diagnostics */
char *pgmname;

/* count of lines with bad control characters */
long badlines = 0;

/* number of errors detected */
int retcode = 0;

/* m      ask for error message */
int prnt = 1;

main (argc, argv)
	int argc; char **argv;
{
int i;
	pgmname = argv[0];

	/* were any files given, or do we process stdin? */
	if (argc == 1)

		/* process standard input */
		dofile ("standard input");
	else {
		/* suppress error messages ? */
		i=1;
		if (argv[1][0]=='-' && argv[1][1]=='s') {
			prnt=0; i++;
			if (argc==2) dofile("standard input");
			}
		/* one iteration per input file */
		for ( ; i < argc; i++) {
			if (freopen (argv[i], "r", stdin) == NULL) {
			fprintf (stderr, "%s: cannot open %s\n",
				pgmname, argv[i]);
			retcode++;
			}
			else
				dofile (argv[i]);
	     }
	}

	/* Check if any error on output stream */
	if (ferror (stdout)) {
		fprintf (stderr, "%s: output error\n", pgmname);
		retcode= -1;
	}

	exit(retcode);
}

/*
 *	dofile - process the standard input.
 *
 *	This program is called once for each input file, with stdin
 *	redirected to the file.  The "fname" argument is used
 *	for writing diagnostic messages only.
 */

dofile (fname)
	char *fname;
{
	register int c;
	int firstchar; /* flag to show first char in a line */

	badlines=firstchar=0;
	c=getchar();
	lff: putchar('\f');  /* start with a new page */
	c=getchar();
	while (c!=EOF)
		{
		if (firstchar) {
			firstchar=0;
			switch (c) {
				/* new page */
				case '\f':
				case '1':
					putchar('\n');
					putchar('\f');
					break;

				/* triple space */
				/* this is not in the spec! */
				case '-':
					putchar('\n');

				/* double space */
				case '0':
					putchar('\n');

				/* single space */
				case ' ':
					putchar('\n');
					break;
				case '\n':
					firstchar=1;
					putchar('\n');
					break;

				/* no space at all */
				case '+':
					putchar('\r');
					break;
				default:
					badlines++;
					putchar('\n');
				}
			}
		else 	{
			switch (c) {
				case '\f':
					putchar('\n');
					putchar('\f');
					break;
				case '\n':
					firstchar=1;
					break;
				default:
					putchar(c);
					break;
				}
			}
		c=getchar();
		}
	putchar('\n');

	/* report invalid input lines -- dofile increments badlines */
	if (badlines && prnt)
	fprintf (stderr, "%s: %ld invalid input lines in %s\n",
		pgmname, badlines, fname);
	return;
}
q HVA   Wɲ     cmd/awk q R   g`#   f
cmd/awk/EXPLAIN Nov 30, 1979:

Awk has been modified yet again, in an attempt to make
its behavior more rational and predictable in the areas
of initialization, comparison, and type coercion.
Herewith what we believe the current truth to be:

1. Each variable and field can potentially be a string
or a number or both at any time.
When a variable is set by the assignment
	v = expr
its type is set to that of expr.  (This includes +=, ++, etc.)
An arithmetic expression is of type number, a
concatenation is of type string,  and so on.

If the assignment is a simple copy, as in
	v1 = v2
then the type of v1 becomes that of v2.

2. In comparisons, if both operands are numeric,
the comparison is made numerically.  Otherwise,
operands are coerced to string if necessary, and
the comparison is made on strings.

3. The type of any expression can be coerced to
numeric by subterfuges (kludges?) such as
	expr + 0
and to string by
	expr ""
(i.e., concatenation with a null string).

4. Uninitialized variables have the numeric value
0 and the string value "".  Accordingly, if x is
uninitialized,
	if (x) ...
is false, and
	if (!x) ...
	if (x == 0) ...
	if (x == "") ...
are all true.  But note that
	if (x == "0") ...
is false.

5. The type of a field is determined by context
when possible; for example,
	$1++
clearly implies that $1 is to be numeric, and
	$1 = $1 "," $2
implies that $1 and $2 are both to be strings.
Coercion will be done as needed.

In contexts where types cannot be reliably determined, e.g.,
	if ($1 == $2) ...
the type of each field is determined on input by
inspection.  All fields are strings; in addition,
each field that contains only a number (in the
sense of Fortran, say) is also considered numeric.
This ensures (for better or worse) that the test
	if ($1 == $2) ...
will succeed on the inputs
	0	0.0
	100	1e2
	+100	100
	1e-3	1e-3
and fail on the inputs
	(null)	0
	(null)	0.0
	2E-518	6E-427
as we believe it should.

Fields which are explicitly null have the string
value ""; they are not numeric.
Non-existent fields (i.e., fields past NF) are
treated this way too.

As it is for fields, so it is for array elements
created by split(...).

6. There is no warranty of merchantability nor any warranty
of fitness for a particular purpose nor any other warranty,
either express or implied, as to the accuracy of the
enclosed materials or as to their suitability for any
particular purpose.  Accordingly, the AWK Development
Task Force assumes no responsibility for their use by the
recipient.   Further, the Task Force assumes no obligation
to furnish any assistance of any kind whatsoever, or to
furnish any additional information or documentation.
q DV   /g`#   cmd/awk/README  CHANGES as of July 12:

1. \ddd allowed in regular expressions.

2. exit <expression> causes the expression to
to be the statu      s return upon completion.

3. a new builtin called "getline" causes the next
input line to be read immediately.  Fields, NR, etc.,
are all set, but you are left at exactly the same place
in the awk program.  Getline returns 0 for end of file;
1 for a normal record.


CHANGES SINCE MEMO:
Update to TM of Sept 1, 1978:

1. A new form of for loop
	for (i in array)
		statement
is now available. It provides a way to walk
along the members of an array, most usefully
for associative arrays with non-numeric subscripts.
Elements are accessed in an unpredictable order,
so don't count on anything.
Futhermore, havoc ensues if elements are created
during this operation, or if the index variable
is fiddled.

2. index(s1, s2) returns the position in s1
where s2 first occurs, or 0 if it doesn't.

3. Multi-line records are now supported more
conveniently. If the record separator is null
	RS = ""
then a blank line terminates a record, and newline
is a default field separator, along with
blank and tab.

4. The syntax of split has been changed.
	n = split(str, arrayname, sep)
splits the string str into the array using
the separator sep (a single character).
If no sep field is given, FS is used instead.
The elements are array[1] ... array[n]; n
is the function value.

5. some minor bugs have been fixed.

IMPLEMENTATION NOTES:

Things to watch out for when trying to make awk:

1. The yacc -d business creates a new file y.tab.h
with the yacc #defines in it. this is compared to
awk.h on each successive compile, and major recompilation
is done only if the files differ. (This permits editing
the grammar file without causing everything in sight
to be recompiled, so long as the definitions don't
change.)

2. The program proc.c is compiled into proc, which
is used to create proctab.c. proctab.c is the
table of function pointers used by run to actually
execute things. Don't try to load proc.c with the
other .c files; it also contains a "main()".

3. Awk uses structure assignment. Be sure your
version of the C compiler has it.

4. The loader flag -lm is used to fetch the standard
math library on the Research system. It is more likely
that you will want to use -lS on yours.
run.c also includes "math.h", which contains sensible
definitions for log(), sqrt(), etc. If you don't have this
include file, comment the line out, and all will be well
anyway.

5. The basic sequence of events (in case make doesn't
seem to do the job) is
	yacc -d awk.g.y
	cc -O -c y.tab.c
	mv y.tab.o awk.g.o
	lex awk.lx.l
	cc -O -c lex.yy.c
	mv lex.yy.o awk.lx.o
	cc -O -c b.c
	cc -O -c main.c
	e - <tokenscript
	cc -O -c token.c
	cc -O -c tran.c
	cc -O -c lib.c
	cc -O -c run.c
	cc -O -c parse.c
	cc -O -c proc.c
	cc -o proc proc.c token.o
	proc >proctab.c
	cc -O -c proctab.c
	cc -i -O awk.g.o awk.lx.o b.o main.o token.o tran.o lib.o run.o parse.o proctab.o -lm
q [   >g`#   acmd/awk/awk.def #define	xfree(a)	{ if(a!=NULL) { yfree(a); a=NULL;} }
#define yfree free
#ifdef	DEBUG
#	define	dprintf	if(dbg)printf
#else
#	define	dprintf(x1, x2, x3, x4)
#endif
typedef double	awkfloat;

extern char	**FS;
extern char	**RS;
extern char	**ORS;
extern char	**OFS;
extern char	**OFMT;
extern awkfloat *NR;
extern awkfloat *NF;
extern char	**FILENAME;

extern char	*record;
extern int	dbg;
extern int	lineno;
extern int	errorflag;
extern int	donefld;	/* 1 if record broken into fields */
extern int	donerec;	/* 1 if record is valid (no fld has changed */

/* CELL:  all information about a variable or constant */

typedef struct val {
	char	ctype;		/* CELL, BOOL, JUMP, etc. */
	char	csub;		/* subtype of ctype */
	char	*nval;		/* name, for variables only */
	char	*sval;		/* string value */
	awkfloat fval;		/* value as number */
	unsigned tval;		/* type info */
	struct val *nextval;	/* ptr to next if chained */
} CELL;

extern CELL	*symtab[];
extern CELL	*setsymtab(), *lookup(), **makesymtab();

extern CELL	*recloc;	/* location of input record */
extern CELL	*nrloc;		/* NR */
extern CELL	*nfloc;		/* NF */

/* CELL.tval values: */
#define	STR	01	/* string value is valid */
#define	NUM	02	/* number value is valid */
#define FLD	04	/* FLD means don't free string space */
#define	CON	010	/* this is a constant */
#define	ARR	020	/* this is an array */

awkfloat	setfval(), getfval();
char		*setsval(), *getsval();
char	*tostring(), *tokname(), *malloc();
double	log(), sqrt(), exp(), atof();

/* function types */
#define	FLENGTH	1
#define	FSQRT	2
#define	FEXP	3
#define	FLOG	4
#define	FINT	5

#define BOTCH	1
typedef struct nd {
	char	ntype;
	char	subtype;
	struct nd *nnext;
	int	nobj;
	struct nd *narg[BOTCH];	/* C won't take a zero length array */
} NODE;

extern NODE	*winner;
extern NODE	*nullstat;

/* ctypes */
#define OCELL	1
#define OBOOL	2
#define OJUMP	3

/* CELL subtypes */
#define CCON	5
#define CTEMP	4
#define CNAME	3 
#define CVAR	2
#define CFLD	1

/* bool subtypes */
#define BTRUE	1
#define BFALSE	2

/* jump subtypes */
#define JEXIT	1
#define JNEXT	2
#define	JBREAK	3
#define	JCONT	4

/* node types */
#define NVALUE	1
#define NSTAT	2
#define NEXPR	3

extern CELL	*(*proctab[])();
extern int	pairstack[]      , paircnt;

#define cantexec(n)	(n->ntype == NVALUE)
#define notlegal(n)	(n <= FIRSTTOKEN || n >= LASTTOKEN || proctab[n-FIRSTTOKEN]== nullproc)
#define isexpr(n)	(n->ntype == NEXPR)
#define isjump(n)	(n->ctype == OJUMP)
#define isexit(n)	(n->ctype == OJUMP && n->csub == JEXIT)
#define	isbreak(n)	(n->ctype == OJUMP && n->csub == JBREAK)
#define	iscont(n)	(n->ctype == OJUMP && n->csub == JCONT)
#define	isnext(n)	(n->ctype == OJUMP && n->csub == JNEXT)
#define isstr(n)	(n->tval & STR)
#define isnum(n)	(n->tval & NUM)
#define istrue(n)	(n->ctype == OBOOL && n->csub == BTRUE)
#define istemp(n)	(n->ctype == OCELL && n->csub == CTEMP)
#define isfld(n)	(!donefld && n->csub==CFLD && n->ctype==OCELL && n->nval==0)
#define isrec(n)	(donefld && n->csub==CFLD && n->ctype==OCELL && n->nval!=0)
extern CELL	*nullproc();
extern CELL	*relop();

#define MAXSYM	50
#define	HAT	0177	/* matches ^ in regular expr */
			/* watch out for mach dep */
	q CV   SWg`#   cmd/awk/awk.g.y %token	FIRSTTOKEN	/*must be first*/
%token	FINAL FATAL
%token	LT LE GT GE EQ NE
%token	MATCH NOTMATCH
%token	APPEND
%token	ADD MINUS MULT DIVIDE MOD UMINUS 
%token	ASSIGN ADDEQ SUBEQ MULTEQ DIVEQ MODEQ
%token	JUMP
%token	XBEGIN XEND
%token	NL
%token	PRINT PRINTF SPRINTF SPLIT
%token	IF ELSE WHILE FOR IN NEXT EXIT BREAK CONTINUE
%token	PROGRAM PASTAT PASTAT2

%right	ASGNOP
%left	BOR
%left	AND
%left	NOT
%left	NUMBER VAR ARRAY FNCN SUBSTR LSUBSTR INDEX
%left	GETLINE
%nonassoc RELOP MATCHOP
%left	OR
%left	STRING  DOT CCL NCCL CHAR
%left	'(' '^' '$'
%left	CAT
%left	'+' '-'
%left	'*' '/' '%'
%left	STAR PLUS QUEST
%left	POSTINCR PREINCR POSTDECR PREDECR INCR DECR
%left	FIELD INDIRECT
%token	JUMPTRUE JUMPFALSE PUSH GETREC
%token	NEWSTAT
%token	IN_INIT IN_EXIT
%token	LASTTOKEN	/* has to be last */

%{
#include "awk.def"
#ifndef	DEBUG
#	define	PUTS(x)
#endif
%}
%%

program:
	  begin pa_stats end	{ if (errorflag==0) winner = (NODE *)stat3(PROGRAM, $1, $2, $3); }
	| error			{ yyclearin; yyerror("bailing out"); }
	;

begin:
	  XBEGIN '{' stat_list '}'	{ $$ = $3; }
	| begin NL
	| 	{ $$ = (int) 0; }
	;

end:
	  XEND '{' stat_list '}'	{ $$ = $3; }
	| end NL
	|	{ $$ = (int) 0; }
	;

compound_conditional:
	  conditional BOR conditional	{ $$ = op2(BOR, $1, $3); }
	| conditional AND conditional	{ $$ = op2(AND, $1, $3); }
	| NOT conditional		{ $$ = op1(NOT, $2); }
	| '(' compound_conditional ')'	{ $$ = $2; }
	;

compound_pattern:
	  pattern BOR pattern	{ $$ = op2(BOR, $1, $3); }
	| pattern AND pattern	{ $$ = op2(AND, $1, $3); }
	| NOT pattern		{ $$ = op1(NOT, $2); }
	| '(' compound_pattern ')'	{ $$ = $2; }
	;

conditional:
	  expr	{ $$ = op2(NE, $1, valtonode(lookup("$zero&null", symtab, 0), CCON)); }
	| rel_expr
	| lex_expr
	| compound_conditional	 
	;

else:
	  ELSE optNL
	;

field:
	  FIELD		{ $$ = valtonode($1, CFLD); }
	| INDIRECT term { $$ = op1(INDIRECT, $2); }
	;

if:
	  IF '(' conditional ')' optNL	{ $$ = $3; }
	;

lex_expr:
	  expr MATCHOP regular_expr	{ $$ = op2($2, $1, makedfa($3)); }
	| '(' lex_expr ')'		{ $$ = $2; }
	;

var:
	  NUMBER	{ $$ = valtonode($1, CCON); }
	| STRING 	{ $$ = valtonode($1, CCON); }
	| VAR		{ $$ = valtonode($1, CVAR); }
	| VAR '[' expr ']'	{ $$ = op2(ARRAY, $1, $3); }
	| field
	;
term:
	  var
	| GETLINE	{ $$ = op1(GETLINE, 0); }
	| FNCN		{
		$$ = op2(FNCN, $1, valtonode(lookup("$record", symtab, 0), CFLD));
			}
	| FNCN '(' ')'	{ 
			$$ = op2(FNCN, $1, valtonode(lookup("$record", symtab, 0), CFLD));
			}
	| FNCN '(' expr ')'	{ $$ = op2(FNCN, $1, $3); }
	| SPRINTF print_list	{ $$ = op1($1, $2); }
	| SUBSTR '(' expr ',' expr ',' expr ')'
			{ $$ = op3(SUBSTR, $3, $5, $7); }
	| SUBSTR '(' expr ',' expr ')'
			{ $$ = op3(SUBSTR, $3, $5, 0); }
	| SPLIT '(' expr ',' VAR ',' expr ')'
			{ $$ = op3(SPLIT, $3, $5, $7); }
	| SPLIT '(' expr ',' VAR ')'
			{ $$ = op3(SPLIT, $3, $5, 0); }
	| INDEX '(' expr ',' expr ')'
			{ $$ = op2(INDEX, $3, $5); }
	| '(' expr ')'			{$$ = $2; }
	| term '+' term			{ $$ = op2(ADD, $1, $3); }
	| term '-' term			{ $$ = op2(MINUS, $1, $3); }
	| term '*' term			{ $$ = op2(MULT, $1, $3); }
	| term '/' term			{ $$ = op2(DIVIDE, $1, $3); }
	| term '%' term			{ $$ = op2(MOD, $1, $3); }
	| '-' term %prec QUEST		{ $$ = op1(UMINUS, $2); }
	| '+' term %prec QUEST		{ $$ = $2; }
	| INCR var	{ $$ = op1(PREINCR, $2); }
	| DECR var	{ $$ = op1(PREDECR, $2); }
	| var INCR	{ $$= op1(POSTINCR, $1); }
	| var DECR	{ $$= op1(POSTDECR, $1); }
	;

expr:
	  term
	| expr term	{ $$ = op2(CAT, $1, $2); }
	| var ASGNOP expr	{ $$ = op2($2, $1, $3); }
	;

optNL:
	  NL
	|
	;

pa_stat:
	  pattern	{ $$ = stat2(PASTAT, $1, genprint()); }
	| pattern '{' stat_list '}'	{ $$ = stat2(PASTAT, $1, $3); }
	| pattern ',' pattern		{ $$ = pa2stat($1, $3, genprint()); }
	| pattern ',' pattern '{' stat_list '}'
					{ $$ = pa2stat($1, $3, $5); }
	| '{' stat_list '}'	{ $$ = stat2(PASTAT, 0, $2); }
	;

pa_stats:
	  pa_stats pa_stat st	{ $$ = linkum($1, $2); }
	|	{ $$ = (int)0; }
	| pa_stats pa_stat	{ $$ = linkum($1, $2); }
	;

pattern:
	  regular_expr	{ 
		$$ = op2(MATCH, valtonode(lookup("$record", symtab, 0), CFLD), makedfa($1));
		}
	| rel_expr
	| lex_expr
	| compound_patter      n
	;

print_list:
	  expr
	| pe_list
	|		{ $$ = valtonode(lookup("$record", symtab, 0), CFLD); }
	;

pe_list:
	  expr ',' expr	{$$ = linkum($1, $3); }
	| pe_list ',' expr	{$$ = linkum($1, $3); }
	| '(' pe_list ')'		{$$ = $2; }
	;

redir:
	  RELOP
	| '|'
	;

regular_expr:
	  '/'	{ startreg(); }
	  r '/'
		{ $$ = $3; }
	;

r:
	  CHAR		{ $$ = op2(CHAR, (NODE *) 0, $1); }
	| DOT		{ $$ = op2(DOT, (NODE *) 0, (NODE *) 0); }
	| CCL		{ $$ = op2(CCL, (NODE *) 0, cclenter($1)); }
	| NCCL		{ $$ = op2(NCCL, (NODE *) 0, cclenter($1)); }
	| '^'		{ $$ = op2(CHAR, (NODE *) 0, HAT); }
	| '$'		{ $$ = op2(CHAR, (NODE *) 0, (NODE *) 0); }
	| r OR r	{ $$ = op2(OR, $1, $3); }
	| r r   %prec CAT
			{ $$ = op2(CAT, $1, $2); }
	| r STAR	{ $$ = op2(STAR, $1, (NODE *) 0); }
	| r PLUS	{ $$ = op2(PLUS, $1, (NODE *) 0); }
	| r QUEST	{ $$ = op2(QUEST, $1, (NODE *) 0); }
	| '(' r ')'	{ $$ = $2; }
	;

rel_expr:
	  expr RELOP expr
		{ $$ = op2($2, $1, $3); }
	| '(' rel_expr ')'
		{ $$ = $2; }
	;

st:
	  NL
	| ';'
	;

simple_stat:
	  PRINT print_list redir expr
		{ $$ = stat3($1, $2, $3, $4); }
	| PRINT print_list
		{ $$ = stat3($1, $2, 0, 0); }
	| PRINTF print_list redir expr
		{ $$ = stat3($1, $2, $3, $4); }
	| PRINTF print_list
		{ $$ = stat3($1, $2, 0, 0); }
	| expr	{ $$ = exptostat($1); }
	|		{ $$ = (int)0; }
	| error		{ yyclearin; yyerror("illegal statement"); }
	;

statement:
	  simple_stat st
	| if statement		{ $$ = stat3(IF, $1, $2, 0); }
	| if statement else statement
		{ $$ = stat3(IF, $1, $2, $4); }
	| while statement	{ $$ = stat2(WHILE, $1, $2); }
	| for
	| NEXT st		{ $$ = stat1(NEXT, 0); }
	| EXIT st		{ $$ = stat1(EXIT, 0); }
	| EXIT expr st		{ $$ = stat1(EXIT, $2); }
	| BREAK st		{ $$ = stat1(BREAK, 0); }
	| CONTINUE st		{ $$ = stat1(CONTINUE, 0); }
	| '{' stat_list '}'	{ $$ = $2; }
	;

stat_list:
	  stat_list statement	{ $$ = linkum($1, $2); }
	|			{ $$ = (int)0; }
	;

while:
	  WHILE '(' conditional ')' optNL	{ $$ = $3; }
	;

for:
	  FOR '(' simple_stat ';' conditional ';' simple_stat ')' optNL statement
		{ $$ = stat4(FOR, $3, $5, $7, $10); }
	| FOR '(' simple_stat ';'  ';' simple_stat ')' optNL statement
		{ $$ = stat4(FOR, $3, 0, $6, $9); }
	| FOR '(' VAR IN VAR ')' optNL statement
		{ $$ = stat3(IN, $3, $5, $8); }
	;

%%
Cq O   ga#   Hcmd/awk/awk.lx.l a%Start A str chc sc reg comment

%{
#include	"awk.h"
#include	"awk.def"
#undef	input	/* defeat lex */
extern int	yylval;
extern int	mustfld;

int	lineno	= 1;
#ifdef	DEBUG
#	define	RETURN(x)	{if (dbg) ptoken(x); return(x); }
#else
#	define	RETURN(x)	return(x)
#endif
#define	CADD	cbuf[clen++]=yytext[0]; if(clen>=CBUFLEN-1) {yyerror("string too long", cbuf); BEGIN A;}
#define	CBUFLEN	150
char	cbuf[CBUFLEN];
int	clen, cflag;
%}

A	[a-zA-Z_]
B	[a-zA-Z0-9_]
D	[0-9]
WS	[ \t]

%%
	switch (yybgin-yysvec-1) {	/* witchcraft */
	case 0:
		BEGIN A;
		break;
	case sc:
		BEGIN A;
		RETURN('}');
	}

<A>^\n		lineno++;
<A>^{WS}*#.*\n	lineno++;	/* strip comment lines */
<A>{WS}		;
<A,reg>"\\"\n	lineno++;
<A>"||"		RETURN(BOR);
<A>BEGIN	RETURN(XBEGIN);
<A>END		RETURN(XEND);
<A>PROGEND	RETURN(EOF);
<A>"&&"		RETURN(AND);
<A>"!"		RETURN(NOT);
<A>"!="		{ yylval = NE; RETURN(RELOP); }
<A>"~"		{ yylval = MATCH; RETURN(MATCHOP); }
<A>"!~"		{ yylval = NOTMATCH; RETURN(MATCHOP); }
<A>"<"		{ yylval = LT; RETURN(RELOP); }
<A>"<="		{ yylval = LE; RETURN(RELOP); }
<A>"=="		{ yylval = EQ; RETURN(RELOP); }
<A>">="		{ yylval = GE; RETURN(RELOP); }
<A>">"		{ yylval = GT; RETURN(RELOP); }
<A>">>"		{ yylval = APPEND; RETURN(RELOP); }
<A>"++"		{ yylval = INCR; RETURN(INCR); }
<A>"--"		{ yylval = DECR; RETURN(DECR); }
<A>"+="		{ yylval = ADDEQ; RETURN(ASGNOP); }
<A>"-="		{ yylval = SUBEQ; RETURN(ASGNOP); }
<A>"*="		{ yylval = MULTEQ; RETURN(ASGNOP); }
<A>"/="		{ yylval = DIVEQ; RETURN(ASGNOP); }
<A>"%="		{ yylval = MODEQ; RETURN(ASGNOP); }
<A>"="		{ yylval = ASSIGN; RETURN(ASGNOP); }

<A>"$"{D}+	{	if (atoi(yytext+1)==0) {
				yylval = (int)lookup("$record", symtab, 0);
				RETURN(STRING);
			} else {
				yylval = fieldadr(atoi(yytext+1));
				RETURN(FIELD);
			}
		}
<A>"$"{WS}*	{ RETURN(INDIRECT); }
<A>NF		{ mustfld=1; yylval = (int)setsymtab(yytext, NULL, 0.0, NUM, symtab); RETURN(VAR); }
<A>({D}+("."?){D}*|"."{D}+)((e|E)("+"|-)?{D}+)?	{
		yylval = (int)setsymtab(yytext, NULL, atof(yytext), CON|NUM, symtab); RETURN(NUMBER); }
<A>"}"{WS}*\n	{ BEGIN sc; lineno++; RETURN(';'); }
<A>"}"		{ BEGIN sc; RETURN(';'); }
<A>;\n		{ lineno++; RETURN(';'); }
<A>\n		{ lineno++; RETURN(NL); }
<A>while	RETURN(WHILE);
<A>for		RETURN(FOR);
<A>if		RETURN(IF);
<A>else		RETURN(ELSE);
<A>next		RETURN(NEXT);
<A>exit		RETURN(EXIT);
<A>break	RETURN(BREAK);
<A>continue	RETURN(CONTINUE);
<A>print	{ yylval = PRINT; RETURN(PRINT); }
<A>printf	{ yylval = PRINTF; RETURN(PRINTF); }
<A>sprintf	{ yylval = SPRINTF; RETURN(SPRINTF); }
<A>split	{ yylval = SPLIT; RETURN(SPLIT); }
<A>substr	RETURN(SUBSTR);
<A>index	RETURN(INDEX);
<A>in		RETURN(IN);
<A>getline	RETURN(GETLINE);
<A>length	{ yylval = FLENGTH; RETURN(FNCN); }
<A>log		{ yylval = FLOG; RETURN(FNCN); }
<A>int		{ yylval = FINT; RETURN(FNCN); }
<A>exp		{ yylval = FEXP; RETURN(FNCN); }
<A>sqrt		{ yylv      al = FSQRT; RETURN(FNCN); }
<A>{A}{B}*	{ yylval = (int)setsymtab(yytext, tostring(""), 0.0, STR|NUM, symtab); RETURN(VAR); }
<A>\"		{ BEGIN str; clen=0; }

<A>#		{ BEGIN comment; }
<comment>\n	{ BEGIN A; lineno++; RETURN(NL); }
<comment>.	;

<A>.		{ yylval = yytext[0]; RETURN(yytext[0]); }

<reg>"["	{ BEGIN chc; clen=0; cflag=0; }
<reg>"[^"	{ BEGIN chc; clen=0; cflag=1; }

<reg>"?"	RETURN(QUEST);
<reg>"+"	RETURN(PLUS);
<reg>"*"	RETURN(STAR);
<reg>"|"	RETURN(OR);
<reg>"."	RETURN(DOT);
<reg>"("	RETURN('(');
<reg>")"	RETURN(')');
<reg>"^"	RETURN('^');
<reg>"$"	RETURN('$');
<reg>\\{D}{D}{D}	{ sscanf(yytext+1, "%o", &yylval); RETURN(CHAR); }
<reg>\\.	{	if (yytext[1]=='n') yylval = '\n';
			else if (yytext[1] == 't') yylval = '\t';
			else if (yytext[1] == 'b') yylval = '\b';
			else if (yytext[1] == 'r') yylval = '\r';
			else if (yytext[1] == 'f') yylval = '\f';
			else yylval = yytext[1];
			RETURN(CHAR);
		}
<reg>"/"	{ BEGIN A; unput('/'); }
<reg>\n		{ yyerror("newline in regular expression"); lineno++; BEGIN A; }
<reg>.		{ yylval = yytext[0]; RETURN(CHAR); }

<str>\"		{ char *s; BEGIN A; cbuf[clen]=0; s = tostring(cbuf);
		cbuf[clen] = ' '; cbuf[++clen] = 0;
		yylval = (int)setsymtab(cbuf, s, 0.0, CON|STR, symtab); RETURN(STRING); }
<str>\n		{ yyerror("newline in string"); lineno++; BEGIN A; }
<str>"\\\""	{ cbuf[clen++]='"'; }
<str,chc>"\\"n	{ cbuf[clen++]='\n'; }
<str,chc>"\\"t	{ cbuf[clen++]='\t'; }
<str,chc>"\\"b	{ cbuf[clen++]='\b'; }
<str,chc>"\\"r	{ cbuf[clen++]='\r'; }
<str,chc>"\\"f 	{ cbuf[clen++]='\f'; }
<str,chc>"\\\\"	{ cbuf[clen++]='\\'; }
<str>.		{ CADD; }

<chc>"\\""]"	{ cbuf[clen++]=']'; }
<chc>"]"	{ BEGIN reg; cbuf[clen]=0; yylval = (int)tostring(cbuf);
		if (cflag==0) { RETURN(CCL); }
		else { RETURN(NCCL); } }
<chc>\n		{ yyerror("newline in character class"); lineno++; BEGIN A; }
<chc>.		{ CADD; }

%%

input()
{
	register c;
	extern char *lexprog;

	if (yysptr > yysbuf)
		c = U(*--yysptr);
	else if (yyin == NULL)
		c = *lexprog++;
	else
		c = getc(yyin);
	if (c == '\n')
		yylineno++;
	else if (c == EOF)
		c = 0;
	return(c);
}

startreg()
{
	BEGIN reg;
}
q ?V   )W8   P	cmd/awk/awk.mk lROOT = 
PFX=
CC=$(PFX)cc
SL = /usr/src/cmd
INSDIR = $(ROOT)/usr/bin
RDIR = $(SL)/awk
YACCRM=-rm
TESTDIR = .
FRC =
INS = :
B10 =
B11 =
IFLAG = -i
CFLAGS=-O
YFLAGS=-d
LDFLAGS = -s $(IFLAG) $(FFLAGS)
REL = current
LIST = lp
FILES=awk.lx.o b.o main.o token.o tran.o lib.o run.o parse.o proctab.o freeze.o
SOURCE=EXPLAIN README awk.def awk.g.y awk.h awk.lx.l b.c lib.c main.c parse.c \
	makeprctab.c freeze.c\
	run.c token.c tokenscript tran.c

all:  awk

awk:	$(FILES) awk.g.o
	$(CC) $(LDFLAGS) awk.g.o  $(FILES)  -lm -o  $(TESTDIR)/awk
	$(INS)     $(TESTDIR)/awk	$(INSDIR)

y.tab.h:	awk.g.o

awk.h:	y.tab.h
	-cp y.tab.h awk.h

$(FILES):	awk.h awk.def $(FRC)

token.c:	awk.h tokenscript
	ed - <tokenscript

src:	$(SOURCE) test.a tokenscript makefile README
	cp $? /usr/src/cmd/awk
	touch src

get:
	for i in $(SOURCE) awk.mk tokenscript README; do cp /usr/src/cmd/awk/$$i .; done

bin:
	cp a.out /usr/bin/awk
	strip /usr/bin/awk

profile:	awk.g.o $(FILES) mon.o
	$(CC) -p -i awk.g.o $(FILES) mon.o -lm

find:
	egrep -n "$(PAT)" *.[ylhc] awk.def

list:
	-pr WISH $(SOURCE) awk.mk tokenscript README EXPLAIN

lint:
	lint -spu b.c main.c token.c tran.c run.c lib.c parse.c -lm |\
		egrep -v '^(error|free|malloc)'

proctab.c:	./makeprctab
	./makeprctab >proctab.c

./makeprctab:	awk.h makeprctab.c token.c
	# must run local in possible cross env - do not use $(CC)
	cc -o ./makeprctab makeprctab.c token.c
	# remake for possible cross env
	$(CC) $(CFLAGS) -c token.c

clean:
	rm -f a.out *.o t.* *temp* *.out *junk* y.tab.* awk.h ./makeprctab proctab.c

diffs:
	-for i in $(SOURCE); do echo $$i:; diff $$i /usr/src/cmd/awk | ind; done
lcomp:
	-rm -f  [b-z]*.o
	lcomp b.c main.c token.c tran.c run.c lib.c parse.c freeze.c proctab.c   *.o -lm

FRC:

install: 
	$(MAKE) -f awk.mk INS=cp ROOT=$(ROOT) PFX=$(PFX) \
			IFLAG=$(IFLAG) YACCRM=$(YACCRM) 

build:	bldmk
	get -p -r`gsid awk $(REL)` s.awk.src $(REWIRE) | ntar -d $(RDIR) -g
	cd $(RDIR) ; $(YACC) $(YFLAGS) awk.g.y
	cd $(RDIR) ; mv y.tab.c  awk.g.c ; rm -f y.tab.h

bldmk:
	get -p -r`gsid awk.km $(REL) s.awk.mk >$(RDIR)/awk.mk

listing:
	pr awk.mk $(SOURCE) | $(LIST)

listmk:
	pr awk.mk | $(LIST)

edit:
	get -e -p s.awk.src |ntar -g

delta:
	ntar -p $(SOURCE) >awk.src
	delta s.awk.src
	rm -f $(SOURCE)

mkedit:		;	get -e s.awk.mk
mkdelta:	;	delta s.awk.mk

clobber:	clean
	-rm  -f  $(TESTDIR)/awk

delete:	clobber
	rm -f $(SOURCE)

q {    ga#   }*cmd/awk/b.c #include "awk.def"
#include "stdio.h"
#include "awk.h"

extern NODE *op2();
extern struct fa *cgotofn();
#define MAXLIN 256
#define NCHARS 128
#define NSTATES 256

#define type(v)	v->nobj
#define left(v)	v->narg[0]
#define right(v)	v->narg[1]
#define parent(v)	v->nnext

#define LEAF	case CCL: case NCCL: case CHAR: case DOT:
#define UNARY	case FINAL: case STAR: case PLUS: case QUEST:

/* encoding in tree NODEs:
	leaf (CCL, NCCL, CHAR, DOT): left is index, right contains value or pointer to value
	unary (FINAL, STAR, PLUS, QUEST): left is child      , right is null
	binary (CAT, OR): left and right are children
	parent contains pointer to parent
*/

struct fa {
	int cch;
	struct fa *st;
};

int	*state[NSTATES];
int	*foll[MAXLIN];
char	chars[MAXLIN];
int	setvec[MAXLIN];
NODE	*point[MAXLIN];

int	setcnt;
int	line;


struct fa *makedfa(p)	/* returns dfa for tree pointed to by p */
NODE *p;
{
	NODE *p1;
	struct fa *fap;
	p1 = op2(CAT, op2(STAR, op2(DOT, (NODE *) 0, (NODE *) 0), (NODE *) 0), p);
		/* put DOT STAR in front of reg. exp. */
	p1 = op2(FINAL, p1, (NODE *) 0);		/* install FINAL NODE */

	line = 0;
	penter(p1);	/* enter parent pointers and leaf indices */
	point[line] = p1;	/* FINAL NODE */
	setvec[0] = 1;		/* for initial DOT STAR */
	cfoll(p1);	/* set up follow sets */
	fap = cgotofn();
	freetr(p1);	/* add this when alloc works */
	return(fap);
}

penter(p)	/* set up parent pointers and leaf indices */
NODE *p;
{
	switch(type(p)) {
		LEAF
			left(p) = (NODE *) line;
			point[line++] = p;
			break;
		UNARY
			penter(left(p));
			parent(left(p)) = p;
			break;
		case CAT:
		case OR:
			penter(left(p));
			penter(right(p));
			parent(left(p)) = p;
			parent(right(p)) = p;
			break;
		default:
			error(FATAL, "unknown type %d in penter\n", type(p));
			break;
	}
}

freetr(p)	/* free parse tree and follow sets */
NODE *p;
{
	switch(type(p)) {
		LEAF
			xfree(foll[(int) left(p)]);
			xfree(p);
			break;
		UNARY
			freetr(left(p));
			xfree(p);
			break;
		case CAT:
		case OR:
			freetr(left(p));
			freetr(right(p));
			xfree(p);
			break;
		default:
			error(FATAL, "unknown type %d in freetr", type(p));
			break;
	}
}
char *cclenter(p)
register char *p;
{
	register i, c;
	char *op;

	op = p;
	i = 0;
	while ((c = *p++) != 0) {
		if (c == '-' && i > 0 && chars[i-1] != 0) {
			if (*p != 0) {
				c = chars[i-1];
				while (c < *p) {
					if (i >= MAXLIN)
						overflo();
					chars[i++] = ++c;
				}
				p++;
				continue;
			}
		}
		if (i >= MAXLIN)
			overflo();
		chars[i++] = c;
	}
	chars[i++] = '\0';
	dprintf("cclenter: in = |%s|, out = |%s|\n", op, chars, NULL);
	xfree(op);
	return(tostring(chars));
}

overflo()
{
	error(FATAL, "regular expression too long\n");
}

cfoll(v)		/* enter follow set of each leaf of vertex v into foll[leaf] */
register NODE *v;
{
	register i;
	int prev;
	int *add();

	switch(type(v)) {
		LEAF
			setcnt = 0;
			for (i=1; i<=line; i++)
				setvec[i] = 0;
			follow(v);
			if (notin(foll, ( (int) left(v))-1, &prev)) {
				foll[(int) left(v)] = add(setcnt);
			}
			else
				foll[ (int) left(v)] = foll[prev];
			break;
		UNARY
			cfoll(left(v));
			break;
		case CAT:
		case OR:
			cfoll(left(v));
			cfoll(right(v));
			break;
		default:
			error(FATAL, "unknown type %d in cfoll", type(v));
	}
}

first(p)			/* collects initially active leaves of p into setvec */
register NODE *p;		/* returns 0 or 1 depending on whether p matches empty string */
{
	register b;

	switch(type(p)) {
		LEAF
			if (setvec[(int) left(p)] != 1) {
				setvec[(int) left(p)] = 1;
				setcnt++;
			}
			if (type(p) == CCL && (*(char *) right(p)) == '\0')
				return(0);		/* empty CCL */
			else return(1);
		case FINAL:
		case PLUS:
			if (first(left(p)) == 0) return(0);
			return(1);
		case STAR:
		case QUEST:
			first(left(p));
			return(0);
		case CAT:
			if (first(left(p)) == 0 && first(right(p)) == 0) return(0);
			return(1);
		case OR:
			b = first(right(p));
			if (first(left(p)) == 0 || b == 0) return(0);
			return(1);
	}
	error(FATAL, "unknown type %d in first\n", type(p));
	return(-1);
}

follow(v)
NODE *v;		/* collects leaves that can follow v into setvec */
{
	NODE *p;

	if (type(v) == FINAL)
		return;
	p = parent(v);
	switch (type(p)) {
		case STAR:
		case PLUS:	first(v);
				follow(p);
				return;

		case OR:
		case QUEST:	follow(p);
				return;

		case CAT:	if (v == left(p)) {	/* v is left child of p */
					if (first(right(p)) == 0) {
						follow(p);
						return;
					}
				}
				else		/* v is right child */
					follow(p);
				return;
		case FINAL:	if (setvec[line] != 1) {
					setvec[line] = 1;
					setcnt++;
				}
				return;
	}
}

member(c, s)	/* is c in s? */
register char c, *s;
{
	while (*s)
		if (c == *s++)
			return(1);
	return(0);
}

notin(array, n, prev)		/* is setvec in array[0] thru array[n]? */
int **array;
int *prev; {
	register i, j;
	int *ptr;
	for (i=0; i<=n; i++) {
		ptr = array[i];
		if (*ptr == setcnt) {
			for (j=0; j < setcnt; j++)
				if (setvec[*(++ptr)] != 1) goto nxt;
			*prev = i;
			return(0);
		}
		nxt: ;
	}
	return(1);
}

int *add(n) {		/* remember setvec */
	int *ptr, *p;
	register i;
	if ((p = ptr = (int *) malloc((n+1)*sizeof(int))) == NULL)
		overflo();
	*ptr = n;
	dprintf("add(%d)\n", n, NULL, NULL);
	for (i=1; i <= line; i++)
		if (setvec[i] == 1) {
			*(++ptr) = i;
			dprintf("  ptr = %o, *ptr = %d, i = %d\n", ptr, *ptr, i);
		}
	dprintf("\n", NULL, NULL, NULL);
	return(p);
}

struct fa *cgotofn()
{
	register i, k;
	register int *ptr;
	char c;
	char *p;
	NODE *cp;
	int j, n, s, ind, numtrans;
	int finflg;
	int curpos, num, prev;
	struct fa *where[NSTATES];

	int fatab[257];
	struct fa *pfa;

	char index[MAXLIN];
	char iposns[M      AXLIN];
	int sposns[MAXLIN];
	int spmax, spinit;

	char symbol[NCHARS];
	char isyms[NCHARS];
	char ssyms[NCHARS];
	int ssmax, ssinit;

	for (i=0; i<=line; i++) index[i] = iposns[i] = setvec[i] = 0;
	for (i=0; i<NCHARS; i++)  isyms[i] = symbol[i] = 0;
	setcnt = 0;
	/* compute initial positions and symbols of state 0 */
	ssmax = 0;
	ptr = state[0] = foll[0];
	spinit = *ptr;
	for (i=0; i<spinit; i++) {
		curpos = *(++ptr);
		sposns[i] = curpos;
		iposns[curpos] = 1;
		cp = point[curpos];
		dprintf("i = %d, spinit = %d, curpos = %d\n", i, spinit, curpos);
		switch (type(cp)) {
			case CHAR:
				k = (int) right(cp);
				if (isyms[k] != 1) {
					isyms[k] = 1;
					ssyms[ssmax++] = k;
				}
				break;
			case DOT:
				for (k=1; k<NCHARS; k++) {
					if (k != HAT) {
						if (isyms[k] != 1) {
							isyms[k] = 1;
							ssyms[ssmax++] = k;
						}
					}
				}
				break;
			case CCL:
				for (p = (char *) right(cp); *p; p++) {
					if (*p != HAT) {
						if (isyms[*p] != 1) {
							isyms[*p] = 1;
							ssyms[ssmax++] = *p;
						}
					}
				}
				break;
			case NCCL:
				for (k=1; k<NCHARS; k++) {
					if (k != HAT && !member(k, (char *) right(cp))) {
						if (isyms[k] != 1) {
							isyms[k] = 1;
							ssyms[ssmax++] = k;
						}
					}
				}
		}
	}
	ssinit = ssmax;
	n = 0;
	for (s=0; s<=n; s++)  {
	dprintf("s = %d\n", s, NULL, NULL);
		ind = 0;
		numtrans = 0;
		finflg = 0;
		if (*(state[s] + *state[s]) == line) {		/* s final? */
			finflg = 1;
			goto tenter;
		}
		spmax = spinit;
		ssmax = ssinit;
		ptr = state[s];
		num = *ptr;
		for (i=0; i<num; i++) {
			curpos = *(++ptr);
			if (iposns[curpos] != 1 && index[curpos] != 1) {
				index[curpos] = 1;
				sposns[spmax++] = curpos;
			}
			cp = point[curpos];
			switch (type(cp)) {
				case CHAR:
					k = (int) right(cp);
					if (isyms[k] == 0 && symbol[k] == 0) {
						symbol[k] = 1;
						ssyms[ssmax++] = k;
					}
					break;
				case DOT:
					for (k=1; k<NCHARS; k++) {
						if (k != HAT) {
							if (isyms[k] == 0 && symbol[k] == 0) {
								symbol[k] = 1;
								ssyms[ssmax++] = k;
							}
						}
					}
					break;
				case CCL:
					for (p = (char *) right(cp); *p; p++) {
						if (*p != HAT) {
							if (isyms[*p] == 0 && symbol[*p] == 0) {
								symbol[*p] = 1;
								ssyms[ssmax++] = *p;
							}
						}
					}
					break;
				case NCCL:
					for (k=1; k<NCHARS; k++) {
						if (k != HAT && !member(k, (char *) right(cp))) {
							if (isyms[k] == 0 && symbol[k] == 0) {
								symbol[k] = 1;
								ssyms[ssmax++] = k;
							}
						}
					}
			}
		}
		for (j=0; j<ssmax; j++) {	/* nextstate(s, ssyms[j]) */
			c = ssyms[j];
			symbol[c] = 0;
			setcnt = 0;
			for (k=0; k<=line; k++) setvec[k] = 0;
			for (i=0; i<spmax; i++) {
				index[sposns[i]] = 0;
				cp = point[sposns[i]];
				if ((k = type(cp)) != FINAL)
					if (k == CHAR && c == (int) right(cp)
					 || k == DOT
					 || k == CCL && member(c, (char *) right(cp))
					 || k == NCCL && !member(c, (char *) right(cp))) {
						ptr = foll[sposns[i]];
						num = *ptr;
						for (k=0; k<num; k++) {
							if (setvec[*(++ptr)] != 1
								&& iposns[*ptr] != 1) {
								setvec[*ptr] = 1;
								setcnt++;
							}
						}
					}
			} /* end nextstate */
			if (notin(state, n, &prev)) {
				if (n >= NSTATES) {
					dprintf("cgotofn: notin; state = %d, n = %d\n", state, n, NULL);
					overflo();
				}
				state[++n] = add(setcnt);
				dprintf("	delta(%d,%o) = %d", s,c,n);
				dprintf(", ind = %d\n", ind+1, NULL, NULL);
				fatab[++ind] = c;
				fatab[++ind] = n;
				numtrans++;
			}
			else {
				if (prev != 0) {
					dprintf("	delta(%d,%o) = %d", s,c,prev);
					dprintf(", ind = %d\n", ind+1, NULL, NULL);
					fatab[++ind] = c;
					fatab[++ind] = prev;
					numtrans++;
				}
			}
		}
	tenter:
		if ((pfa = (struct fa *) malloc((numtrans + 1) * sizeof(struct fa))) == NULL)
			overflo();
		where[s] = pfa;
		if (finflg)
			pfa->cch = -1;		/* s is a final state */
		else
			pfa->cch = numtrans;
		pfa->st = 0;
		for (i=1, pfa += 1; i<=numtrans; i++, pfa++) {
			pfa->cch = fatab[2*i-1];
			pfa->st = (struct fa *) fatab[2*i];
		}
	}
	for (i=0; i<=n; i++) {
		xfree(state[i]);	/* free state[i] */
		pfa = where[i];
		pfa->st = where[0];
		dprintf("state %d: (%o)\n", i, pfa, NULL);
		dprintf("	numtrans = %d,	default = %o\n", pfa->cch, pfa->st, NULL);
		for (k=1; k<=pfa->cch; k++) {
			(pfa+k)->st = where[ (int) (pfa+k)->st];
			dprintf("	char = %o,	nextstate = %o\n",(pfa+k)->cch, (pfa+k)->st, NULL);
		}
	}
	pfa = where[0];
	if ((num = pfa->cch) < 0)
		return(where[0]);
	for (pfa += num; num; num--, pfa--)
		if (pfa->cch == HAT) {
			return(pfa->st);
		}
	return(where[0]);
}

match(pfa, p)
register struct fa *pfa;
register char *p;
{
	register count;
	char c;
	if (p == 0) return(0);
	if (pfa->cch == 1) {		/* fast test for first character, if possible */
		c = (++pfa)->cch;
		do
			if (c == *p) {
				p++;
				pfa = pfa->st;
				goto adv;
			}
		while (*p++ != 0);
		return(0);
	}
   adv: if ((count = pfa->cch) < 0) return(1);
	do {
		for (pfa += count; count; count--, pfa--)
			if (pfa->cch == *p) {
				break;
			}
		pf      a = pfa->st;
		if ((count = pfa->cch) < 0) return(1);
	} while(*p++ != 0);
	return(0);
}
	q K   SVgb#   cmd/awk/freeze.c a#include "stdio.h"
freeze(s) char *s;
{	int fd;
	unsigned int *len;
	len = (unsigned int *)sbrk(0);
	if((fd = creat(s, 0666)) < 0) {
		perror(s);
		return(1);
	}
	write(fd, &len, sizeof(len));
	write(fd, (char *)0, len);
	close(fd);
	return(0);
}

thaw(s) char *s;
{	int fd;
	unsigned int *len;
	if(*s == 0) {
		fprintf(stderr, "empty restore file\n");
		return(1);
	}
	if((fd = open(s, 0)) < 0) {
		perror(s);
		return(1);
	}
	read(fd, &len, sizeof(len));
	(void) brk(len);
	read(fd, (char *)0, len);
	close(fd);
	return(0);
}
q     VJ;W   cmd/awk/lib.c #include "stdio.h"
#include "awk.def"
#include "awk.h"
#include "ctype.h"

FILE	*infile	= NULL;
char	*file;
#define	RECSIZE	(5 * 512)
char	recdata[RECSIZE];
char	*record	= recdata;
char	fields[RECSIZE];

#define	MAXFLD	100
int	donefld;	/* 1 = implies rec broken into fields */
int	donerec;	/* 1 = record is valid (no flds have changed) */
int	mustfld;	/* 1 = NF seen, so always break*/

#define	FINIT	{ OCELL, CFLD, 0, NULL, 0.0, FLD|STR }
CELL fldtab[MAXFLD] = {		/* room for fields */
	{ OCELL, CFLD, "$record", recdata, 0.0, STR|FLD},
	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT,
	FINIT, FINIT, FINIT, FINIT, FINIT, FINIT, FINIT
};
int	maxfld	= 0;	/* last used field */


getrec()
{
	register char *rr;
	register c, sep;
	register FILE *inf;
	extern int svargc;
	extern char **svargv;

	dprintf("**RS=%o, **FS=%o\n", **RS, **FS, NULL);
	donefld = 0;
	donerec = 1;
	record[0] = 0;
	while (svargc > 0) {
		dprintf("svargc=%d, *svargv=%s\n", svargc, *svargv, NULL);
		if (infile == NULL) {	/* have to open a new file */
			if (member('=', *svargv)) {	/* it's a var=value argument */
				setclvar(*svargv);
				svargv++;
				svargc--;
				continue;
			}
			*FILENAME = file = *svargv;
			dprintf("opening file %s\n", file, NULL, NULL);
			if (*file == '-')
				infile = stdin;
			else if ((infile = fopen(file, "r")) == NULL)
				error(FATAL, "can't open %s", file);
		}
		if ((sep = **RS) == 0)
			sep = '\n';
		inf = infile;
		for (rr = record; ; ) {
			for (; (c=getc(inf)) != sep && c != EOF; *rr++ = c)
				;
			if (**RS == sep || c == EOF)
				break;
			if ((c = getc(inf)) == '\n' || c == EOF)	/* 2 in a row */
				break;
			*rr++ = '\n';
			*rr++ = c;
		}
		if (rr > record + RECSIZE)
			error(FATAL, "record `%.20s...' too long", record);
		*rr = 0;
		if (mustfld)
			fldbld();
		if (c != EOF || rr > record) {	/* normal record */
			recloc->tval &= ~NUM;
			recloc->tval |= STR;
			++nrloc->fval;
			nrloc->tval &= ~STR;
			nrloc->tval |= NUM;
			return(1);
		}
		/* EOF arrived on this file; set up next */
		if (infile != stdin)
			fclose(infile);
		infile = NULL;
		svargc--;
		svargv++;
	}
	return(0);	/* true end of file */
}

setclvar(s)	/* set var=value from s */
char *s;
{
	char *p;
	CELL *q;

	for (p=s; *p != '='; p++)
		;
	*p++ = 0;
	q = setsymtab(s, tostring(p), 0.0, STR, symtab);
	setsval(q, p);
	dprintf("command line set %s to |%s|\n", s, p, NULL);
}
static int ctest[0200];

fldbld()
{
	register char *r, *fr, sep;
	CELL *p, *q;
	static char *nullstat = "";
	int i, j;

	r = record;
	fr = fields;
	i = 0;	/* number of fields accumulated here */
	if ((sep = **FS) == ' ')
		for (i = 0; ; ) {
			while (*r == ' ' || *r == '\t' || *r == '\n')
				r++;
			if (*r == 0)
				break;
			i++;
			if (i >= MAXFLD)
				error(FATAL, "record `%.20s...' has too many fields", record);
			if (!(fldtab[i].tval&FLD))
				xfree(fldtab[i].sval);
			fldtab[i].sval = fr;
			fldtab[i].tval = FLD | STR;
			ctest[' '] = ctest['\t'] = ctest['\n'] = ctest['\0'] =1;
			do
				*fr++ = *r++;
			/*while (*r != ' ' && *r != '\t' && *r != '\n' && *r != '\0');*/
			while(!ctest[*r]);
			ctest[' '] = ctest['\t'] = ctest['\n'] = ctest['\0'] =0;

			*fr++ = 0;
		}
	else if (*r != 0)	/* if 0, it's a null field */
		for (;;) {
			i++;
			if (i >= MAXFLD)
				error(FATAL, "record `%.20s...' has too many fields", record);
			if (!(fldtab[i].tval&FLD))
				xfree(fldtab[i].sval);
			fldtab[i].sval = fr;
			fldtab[i].tval = FLD | STR;
			ctest[sep] = ctest['\n'] = ctest['\0'] = 1;
			while(!ctest[*r])
			/*while (*r != sep && *r != '\n' && *r != '\0')*/
				/* \n always a separator */
				*fr++ = *r++;
			ctest[sep] = ctest['\n'] = ctest['\0'] = 0;
			*fr++ = 0;
			if (*r++ == 0)
				break;
		}
	*fr = 0;
	/* clean out junk from previous record */
	for (p = &fldtab[maxfld], q = &fldtab[i]; p > q; p--) {
		if (!(p->tval&FLD))
			xfree(p->sval);
		p->tval = STR | FLD;
		p->sval = nullstat;
	}
	maxfld = i;
	donefld = 1;
	for (i = 1; i <= maxfld; i++)
		if(isnumber(fldtab[i].sval)) {
			fldtab[i].fval = atof(fldtab[i].sval);
			fldtab[i].tval |= NUM;
		}
	setfval(lookup("NF", symtab, 0), (awkfloat) maxfld);
	if (dbg)
		for (i = 0; i <= maxfld; i++)
			print      f("field %d: |%s|\n", i, fldtab[i].sval);
}

recbld()
{
	int i;
	register char *r, *p;

	if (donefld == 0 || donerec == 1)
		return;
	r = record;
	for (i = 1; i <= *NF; i++) {
		p = getsval(&fldtab[i]);
		while (*r++ = *p++)
			;
		*(r-1) = **OFS;
	}
	*(r-1) = '\0';
	dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL);
	recloc->tval = STR | FLD;
	dprintf("in recbld FS=%o, recloc=%o\n", **FS, recloc, NULL);
	if (r > record+RECSIZE)
		error(FATAL, "built giant record `%.20s...'", record);
	dprintf("recbld = |%s|\n", record, NULL, NULL);
}

CELL *fieldadr(n)
{
	if (n >= MAXFLD)
		error(FATAL, "trying to access field %d", n);
	return(&fldtab[n]);
}

int	errorflag	= 0;

yyerror(s) char *s; {
	fprintf(stderr, "awk: %s near line %d\n", s, lineno);
	errorflag = 2;
}

error(f, s, a1, a2, a3, a4, a5, a6, a7) {
	fprintf(stderr, "awk: ");
	fprintf(stderr, s, a1, a2, a3, a4, a5, a6, a7);
	fprintf(stderr, "\n");
	if (*NR > 0)
		fprintf(stderr, " record number %g\n", *NR);
	if (f)
		exit(2);
}

PUTS(s) char *s; {
	dprintf("%s\n", s, NULL, NULL);
}

#define	MAXEXPON	38	/* maximum exponenet for fp number */

isnumber(s)
register char *s;
{
	register d1, d2;
	int point;
	char *es;

	d1 = d2 = point = 0;
	while (*s == ' ' || *s == '\t' || *s == '\n')
		s++;
	if (*s == '\0')
		return(0);	/* empty stuff isn't number */
	if (*s == '+' || *s == '-')
		s++;
	if (!isdigit(*s) && *s != '.')
		return(0);
	if (isdigit(*s)) {
		do {
			d1++;
			s++;
		} while (isdigit(*s));
	}
	if(d1 >= MAXEXPON)
		return(0);	/* too many digits to convert */
	if (*s == '.') {
		point++;
		s++;
	}
	if (isdigit(*s)) {
		d2++;
		do {
			s++;
		} while (isdigit(*s));
	}
	if (!(d1 || point && d2))
		return(0);
	if (*s == 'e' || *s == 'E') {
		s++;
		if (*s == '+' || *s == '-')
			s++;
		if (!isdigit(*s))
			return(0);
		es = s;
		do {
			s++;
		} while (isdigit(*s));
		if (s - es > 2)
			return(0);
		else if (s - es == 2 && 10 * (*es-'0') + *(es+1)-'0' >= MAXEXPON)
			return(0);
	}
	while (*s == ' ' || *s == '\t' || *s == '\n')
		s++;
	if (*s == '\0')
		return(1);
	else
		return(0);
}
/*
isnumber(s) char *s; {return(0);}
*/
sq G   Vgb#   wcmd/awk/main.c c#include "stdio.h"
#include "ctype.h"
#include "awk.def"
#include "awk.h"
#define TOLOWER(c)	(isupper(c) ? tolower(c) : c) /* ugh!!! */

int	dbg	= 0;
int	svflg	= 0;
int	rstflg	= 0;
int	svargc;
char	**svargv, **xargv;
extern FILE	*yyin;	/* lex input file */
char	*lexprog;	/* points to program argument if it exists */
extern	errorflag;	/* non-zero if any syntax errors; set by yyerror */

int filefd, symnum, ansfd;
char *filelist;
extern int maxsym, errno;
main(argc, argv) int argc; char *argv[]; {
	if (argc == 1)
		error(FATAL, "Usage: awk [-f source | 'cmds'] [files]");
	syminit();
	while (argc > 1) {
		argc--;
		argv++;
		/* this nonsense is because gcos argument handling */
		/* folds -F into -f.  accordingly, one checks the next
		/* character after f to see if it's -f file or -Fx.
		*/
		if (argv[0][0] == '-' && TOLOWER(argv[0][1]) == 'f' && argv[0][2] == '\0') {
			yyin = fopen(argv[1], "r");
			if (yyin == NULL)
				error(FATAL, "can't open %s", argv[1]);
			argc--;
			argv++;
			break;
		} else if (argv[0][0] == '-' && TOLOWER(argv[0][1]) == 'f') {	/* set field sep */
			if (argv[0][2] == 't')	/* special case for tab */
				**FS = '\t';
			else
				**FS = argv[0][2];
			continue;
		} else if (argv[0][0] != '-') {
			dprintf("cmds=|%s|\n", argv[0], NULL, NULL);
			yyin = NULL;
			lexprog = argv[0];
			argv[0] = argv[-1];	/* need this space */
			break;
		} else if (strcmp("-d", argv[0])==0) {
			dbg = 1;
		}
		else if(strcmp("-S", argv[0]) == 0) {
			svflg = 1;
		}
		else if(strncmp("-R", argv[0], 2) == 0) {
			if(thaw(argv[0] + 2) == 0)
				rstflg = 1;
			else {
				fprintf(stderr, "not restored\n");
				exit(1);
			}
		}
	}
	if (argc <= 1) {
		argv[0][0] = '-';
		argv[0][1] = '\0';
		argc++;
		argv--;
	}
	svargc = --argc;
	svargv = ++argv;
	dprintf("svargc=%d svargv[0]=%s\n", svargc, svargv[0], NULL);
	*FILENAME = *svargv;	/* initial file name */
	if(rstflg == 0)
		yyparse();
	dprintf("errorflag=%d\n", errorflag, NULL, NULL);
	if (errorflag)
		exit(errorflag);
	if(svflg) {
		svflg = 0;
		if(freeze("awk.out") != 0)
			fprintf(stderr, "not saved\n");
		exit(0);
	}
	run(winner);
	exit(errorflag);
}


yywrap()
{
	return(1);
}
dq F   Vgb#   K	cmd/awk/makeprctab.c n#include "awk.h"
#define NULL 0
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR,       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print", "print"},
	{ SPLIT, "split", "split"},
	{ ASSIGN, "assign", " = "},
	{ ADDEQ, "assign", " += "},
	{ SUBEQ, "assign", " -= "},
	{ MULTEQ, "assign", " *= "},
	{ DIVEQ, "assign", " /= "},
	{ MODEQ, "assign", " %= "},
	{ IF, "ifstat", "if("},
	{ WHILE, "whilestat", "while("},
	{ FOR, "forstat", "for("},
	{ IN, "instat", "instat"},
	{ NEXT, "jump", "next"},
	{ EXIT, "jump", "exit"},
	{ BREAK, "jump", "break"},
	{ CONTINUE, "jump", "continue"},
	{ FNCN, "fncn", "fncn"},
	{ GETLINE, "getline", "getline"},
	{ 0, ""},
};
#define SIZE	LASTTOKEN - FIRSTTOKEN
char *table[SIZE];
char *names[SIZE];

main()
{
	struct xx *p;
	int i;

	printf("#include \"awk.def\"\n");
	printf("CELL *nullproc();\n");
	for (i = SIZE; --i >= 0; )
		names[i] = "";
	for (p=proc; p->token!=0; p++)
		if (p==proc || strcmp(p->name, (p-1)->name))
			printf("extern CELL *%s();\n",p->name);
	for (p=proc; p->token!=0; p++)
		table[p->token-FIRSTTOKEN] = p->name;
	printf("CELL *(*proctab[%d])() = {\n", SIZE);
	for (i=0; i<SIZE; i++)
		if (table[i]==0)
			printf("/*%s*/\tnullproc,\n", tokname(i+FIRSTTOKEN));
		else
			printf("/*%s*/\t%s,\n",tokname(i+FIRSTTOKEN),table[i]);
	printf("};\n");
	printf("char *printname[%d] = {\n", SIZE);
	for (p=proc; p->token!=0; p++)
		names[p->token-FIRSTTOKEN] = p->pname;
	for (i=0; i<SIZE; i++)
		printf("/*%s*/\t\"%s\",\n",tokname(i+FIRSTTOKEN),names[i]);
	printf("};\n");
	exit(0);
}

q D   uVgc#   R	cmd/awk/parse.c #include "awk.def"
#include "awk.h"
#include "stdio.h"
NODE *nodealloc(n)
{
	register NODE *x;
	x = (NODE *) malloc(sizeof(NODE) + (n-1)*sizeof(NODE *));
	if (x == NULL)
		error(FATAL, "out of space in nodealloc");
	return(x);
}

NODE *exptostat(a) NODE *a;
{
	a->ntype = NSTAT;
	return(a);
}

NODE *node0(a)
{
	register NODE *x;
	x = nodealloc(0);
	x->nnext = NULL;
	x->nobj = a;
	return(x);
}

NODE *node1(a,b) NODE *b;
{
	register NODE *x;
	x = nodealloc(1);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0]=b;
	return(x);
}

NODE *node2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = nodealloc(2);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	return(x);
}

NODE *node3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = nodealloc(3);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	return(x);
}

NODE *node4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = nodealloc(4);
	x->nnext = NULL;
	x->nobj = a;
	x->narg[0] = b;
	x->narg[1] = c;
	x->narg[2] = d;
	x->narg[3] = e;
	return(x);
}

NODE *stat3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NSTAT;
	return(x);
}

NODE *op2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NEXPR;
	return(x);
}

NODE *op1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat1(a,b) NODE *b;
{
	register NODE *x;
	x = node1(a,b);
	x->ntype = NSTAT;
	return(x);
}

NODE *op3(a,b,c,d) NODE *b, *c, *d;
{
	register NODE *x;
	x = node3(a,b,c,d);
	x->ntype = NEXPR;
	return(x);
}

NODE *stat2(a,b,c) NODE *b, *c;
{
	register NODE *x;
	x = node2(a,b,c);
	x->ntype = NSTAT;
	return(x);
}

NODE *stat4(a,b,c,d,e) NODE *b, *c, *d, *e;
{
	register NODE *x;
	x = node4(a,b,c,d,e);
	x->ntype = NSTAT;
	return(x);
}

NODE *valtonode(a, b) CELL *a;
{
	register NODE *x;
	x = node0(a);
	x->ntype = NVALUE;
	x->subtype = b;
	return(x);
}

NODE *pa2stat(a,b,c) NODE *a, *b, *c;
{
	register NODE *x;
	x = node4(PASTAT2, a, b, c, (NODE *) paircnt);
	paircnt++;
	x->ntype = NSTAT;
	return(x);
}

NODE *linkum(a,b) NODE *a, *b;
{
	register NODE *c;
	if(a == NULL) return(b);
	else if(b == NULL) return(a);
	for (c = a; c->nnext != NULL; c=c->nnext)
		;
	c->nnext = b;
	return(a);
}

NODE *genprint()
{
	register NODE *x;
	x = stat2(PRINT,valtonode(lookup("$record", symtab, 0), CFLD), NULL);
	return(x);
}

q C   gc#   I	cmd/awk/proc.c  #include "awk.h"
#define NULL 0
static char SCCSID[] = "%W";
struct xx
{	int token;
	char *name;
	char *pname;
} proc[] = {
	{ PROGRAM, "program", NULL},
	{ BOR, "boolop", " || "},
	{ AND, "boolop", " && "},
	{ NOT, "boolop", " !"},
	{ NE, "relop", " != "},
	{ EQ, "relop", " == "},
	{ LE, "relop", " <= "},
	{ LT, "relop", " < "},
	{ GE, "relop", " >= "},
	{ GT, "relop", " > "},
	{ ARRAY, "array", NULL},
	{ INDIRECT, "indirect", "$("},
	{ SUBSTR, "substr", "substr"},
	{ INDEX, "sindex", "sindex"},
	{ SPRINTF, "asprintf", "sprintf "},
	{ ADD, "arith", " + "},
	{ MINUS, "arith", " - "},
	{ MULT, "arith", " * "},
	{ DIVIDE, "arith", " / "},
	{ MOD, "arith", " % "},
	{ UMINUS, "arith", " -"},
	{ PREINCR, "incrdecr", "++"},
	{ POSTINCR, "incrdecr", "++"},
	{ PREDECR, "incrdecr", "--"},
	{ POSTDECR, "incrdecr", "--"},
	{ CAT, "cat", " "},
	{ PASTAT, "pastat", NULL},
	{ PASTAT2, "dopa2", NULL},
	{ MATCH, "matchop", " ~ "},
	{ NOTMATCH, "matchop", " !~ "},
	{ PRINTF, "aprintf", "printf"},
	{ PRINT, "print"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    