/*	defs.h	4.2	83/06/10	*/

/*
 *	UNIX shell
 */

#ifdef MAIN
#define Extern extern
#define eXtern 
#else
#define eXtern extern
#define Extern extern
#endif

/* error exits from various parts of shell */
#define ERROR	1
#define SYNBAD	2
#define SIGFAIL 3
#define SIGFLG	0200

/* command tree */
#define FPRS	020
#define FINT	040
#define FAMP	0100
#define FPIN	0400
#define FPOU	01000
#define FPCL	02000
#define FCMD	04000
#define COMMSK	017

#define TCOM	0
#define TPAR	1
#define TFIL	2
#define TLST	3
#define TIF	4
#define TWH	5
#define TUN	6
#define TSW	7
#define TAND	8
#define TORF	9
#define TFORK	10
#define TFOR	11

/* execute table */
#define SYSSET	1
#define SYSCD	2
#define SYSEXEC	3
#define SYSLOGIN 4
#define SYSTRAP	5
#define SYSEXIT	6
#define SYSSHFT 7
#define SYSWAIT	8
#define SYSCONT 9
#define SYSBREAK 10
#define SYSEVAL 11
#define SYSDOT	12
#define SYSRDONLY 13
#define SYSTIMES 14
#define SYSXPORT 15
#define SYSNULL 16
#define SYSREAD 17
#define SYSTST	18
#define	SYSUMASK	19

/* used for input and output of shell */
#define INIO 8
#define OTIO 9

/*io nodes*/
#define USERIO	10
#define IOUFD	15
#define IODOC	16
#define IOPUT	32
#define IOAPP	64
#define IOMOV	128
#define IORDW	256
#define INPIPE	0
#define OTPIPE	1

/* arg list terminator */
#define ENDARGS	0

#include	"mac.h"
#include	"mode.h"
#include	"name.h"


/* result type declarations */
#define alloc malloc
ADDRESS		alloc();
VOID		addblok();
STRING		make();
STRING		movstr();
TREPTR		cmd();
TREPTR		makefork();
NAMPTR		lookup();
VOID		setname();
VOID		setargs();
DOLPTR		useargs();
STRING		catpath();
STRING		getpath();
STRING		*scan();
STRING		mactrim();
STRING		macro();
VOID		await();
VOID		post();
VOID		exname();
VOID		printnam();
VOID		printflg();
VOID		prs();
VOID		prc();
VOID		getenv();
STRING		*setenv();

#define attrib(n,f)	(n->namflg |= f)
#define round(a,b)	(((int)((ADR(a)+b)-1))&~((b)-1))
#define closepipe(x)	(close(x[INPIPE]), close(x[OTPIPE]))
#define eq(a,b)		(cf(a,b)==0)
#define max(a,b)	((a)>(b)?(a):(b))
#define assert(x)	;

/* temp files and io */
eXtern UFD		output;
eXtern INT		ioset;
eXtern IOPTR		iotemp;		/* files to be deleted sometime */
eXtern IOPTR		iopend;		/* documents waiting to be read at NL */

/* substitution */
eXtern INT		dolc;
eXtern STRING		*dolv;
eXtern DOLPTR		argfor;
eXtern ARGPTR		gchain;

/* stack */
#define		BLK(x)	((BLKPTR)(x))
#define		BYT(x)	((BYTPTR)(x))
#define		STK(x)	((STKPTR)(x))
#define		ADR(x)	((char*)(x))

/* stak stuff */
#include	"stak.h"

/* string constants */
Extern char		atline[];
Extern char		readmsg[];
Extern char		colon[];
Extern char		minus[];
Extern char		nullstr[];
Extern char		sptbnl[];
Extern char		unexpected[];
Extern char		endoffile[];
Extern char		synmsg[];

/* name tree and words */
Extern struct sysnod	rserved[];   /* Was reserved[] */
eXtern INT		wdval;
eXtern INT		wdnum;
eXtern ARGPTR		wdarg;
eXtern INT		wdset;
eXtern BOOL		reserv;

/* prompting */
Extern char		stdprompt[];
Extern char		supprompt[];
Extern char		profile[];

/* built in names */
Extern NAMNOD		fngnod;
Extern NAMNOD		ifsnod;
Extern NAMNOD		homenod;
Extern NAMNOD		mailnod;
Extern NAMNOD		pathnod;
Extern NAMNOD		ps1nod;
Extern NAMNOD		ps2nod;

/* special names */
Extern char		flagadr[];
eXtern STRING		cmdadr;
eXtern STRING		exitadr;
eXtern STRING		dolladr;
eXtern STRING		pcsadr;
eXtern STRING		pidadr;

Extern char		defpath[];

/* names always present */
Extern char		mailname[];
Extern char		homename[];
Extern char		pathname[];
Extern char		fngname[];
Extern char		ifsname[];
Extern char		ps1name[];
Extern char		ps2name[];

/* transput */
eXtern STRING		tmpnam;
eXtern INT		serial;
#define		TMPNAM 7
eXtern FILE		standin;
eXtern char		tmpout[20];
#define input	(standin->fdes)
#define eof	(standin->feof)
eXtern INT		peekc;
eXtern STRING		comdiv;
eXtern char		devnull[12];

/* flags */
#define		noexec	01
#define		intflg	02
#define		prompt	04
#define		setflg	010
#define		errflg	020
#define		ttyflg	040
#define		forked	0100
#define		oneflg	0200
#define		rshflg	0400
#define		waiting	01000
#define		stdflg	02000
#define		execpr	04000
#define		readpr	010000
#define		keyflg	020000
eXtern INT		flags;

/* error exits from various parts of shell */
#include	"setjmp.h"
eXtern jmp_buf		subshell;
eXtern jmp_buf		errshell;
eXtern jmp_buf		INTbuf;

/* fault handling */
#include	"brkincr.h"
Extern POS		brkincr;

#define MINTRAP	0
#define MAXTRAP	17

#define INTR	2
#define QUIT	3
#define MEMF	11
#define ALARM	14
#define KILL	15
#define TRAPSET	2
#define SIGSET	4
#define SIGMOD	8

VOID		fault();
eXtern BOOL		trapnote;
Extern STRING		trapcom[];
Extern BOOL		trapflg[];
Extern BOOL		trapjmp[];

/* name tree and words */
Extern STRING		*environ;
Extern CHAR		numbuf[];
Extern char		export[];
Extern char		readonly[];

/* execflgs */
eXtern INT		exitval;
eXtern BOOL		execbrk;
eXtern INT		loopcnt;
eXtern INT		breakcnt;

/* messages */
Extern char		mailmsg[];
Extern char		coredump[];
Extern char		badopt[];
Extern char		badparam[];
Extern char		badsub[];
Extern char		nospace[];
Extern char		notfound[];
Extern char		badtrap[];
Extern char		baddir[];
Extern char		badshift[];
Extern char		illegal[];
Extern char		restricted[];
Extern char		execpmsg[];
Extern char		notid[];
Extern char		wtfailed[];
Extern char		badcreate[];
Extern char		piperr[];
Extern char		badopen[];
Extern char		badnum[];
Extern char		arglist[];
Extern char		txtbsy[];
Extern char		toobig[];
Extern char		badexec[];
Extern char		notfound[];
Extern char		badfile[];

Extern address	end[];

#include	"ctype.h"

