/*
 * Csh.h - header for a shell by PJAC
 */
#define	NULL	0	/* the only defs needed from stdio.h */
#define	EOF	(-1)
#include <signal.h>
#include <setjmp.h>
#include <errno.h>
extern	int	errno;

#ifdef	MSDOS
#include <process.h>
#endif

/*
 * name of shell used to execute shell scripts
 */
extern	char	SHELL[];

#define	MAXARGS	256	/* maximum number of arguments to a command */

#define	MAXINLINE 128	/* maximum input line */
extern	char	*in_buf;
extern	char	*in_bufp;
extern	int	in_len;
extern	int	in_ifd;
extern	int	in_ofd;
extern	int	in_efd;
extern	char	*in_savblk;

#define	OK	0
#define	ERR	1

char	*malloc();
char	*mmalloc();
char	*strsave();
char	*getcwd();
char	*skipsp();
char	*index(), *rindex();
char	*my_Itoa();
char	*read_blk();

extern	char	*Args[];
extern	int	Argc;

#define	TRUE	1
#define	FALSE	0

#define	MAX_CWD	64+4	/* maximum CWD str length */

extern	char	CWD[];
extern	char	HOME[];

#define	INIT_IFS	" \t\n"
extern	char	*IFS;

#define	INIT_PROMPT	"% "	/* prompt strings */
#define	INIT_SPROMPT	"? "
extern	char	*Prompt[];

extern	char	**environ;
extern	char	**Real_Environ;
extern	int	Nenvir;

#ifdef	MSDOS
#define	INIT_PATH	".;/bin;"
#else
#define	INIT_PATH	":/bin:/usr/bin"
#endif

extern	char	*Path;

extern	char	Special[];

extern	char	IPipe[];	/* name of pipe file, delete if exists */
extern	char	OPipe[];

extern	int	status;
extern	int	noglob;
extern	int	igneof;
/* 
 * directory stack handling
 */
#define	MAX_DSTACK	10

extern	char	*dirstack[];
int	ndirstack;

int	do_cd(), do_set(), do_hist(), do_alias(), do_pwd();
int	do_unset(), do_setenv(), do_u_nsetenv(), do_drive();
int	do_echo(), do_ualias(), do_pushd(), do_popd(), do_dirs();
int	do_exit(), do_prtenv(), do_rehash(), do_for(), do_shift();
int	do_end(), do_while(), do_brk(), do_cont(), do_source(), do_if();
int	do_atsign(), do_colon();
#ifdef	MSDOS
int	do_ctty();
#endif

struct	inbuilt {
	char	*in_cmd;
	int	(*in_prog)();
};

extern	struct	inbuilt	 incmds[];

/*
 * structure to store shell strings, and aliases
 * strings and aliases are stored as argv vectors
 */

#define	L_ADONE   01	/* used by aliasing */
#define	L_SYS		0100000 /* variable is a system variable */
#define	L_ECHO		01
#define	L_HISTORY	02
#define	L_HOME		03
#define	L_IGNOREEOF	04
#define	L_NOGLOB	05
#define	L_PATH		06
#define	L_PROMPT	07
#define	L_SHELL		010
#define	L_STATUS 	011
#define	L_VERBOSE	012

struct	lvars	{
	char	*L_name;
	int	L_flags;
	union {
		int	LL_ival;
		char	**LL_ssval;
	} L;
#define	L_ival	L.LL_ival
#define	L_aval	L.LL_ssval
	struct	lvars	*L_next;
};

extern	struct	lvars	*Lvars;

/*
 * the list of aliases
 */
extern	struct	lvars	*Aliases;

#define	NORMAL	0	/* return values from parser */
#define	SPECIAL	1
#define	GLOBER	2
#define	COMMENT 3

/*
 * structure to store parse tree state
 */

struct	cmd {
	struct	cmd	*cm_next;
	struct	cmd	*cm_child;
	struct	cmd	*cm_parent;
	char	*cm_ifile;
	char	*cm_ofile;
	char	**cm_argv;
	int	cm_argc;
	int	cm_savc;
};

extern	struct	cmd	*ctree;

extern	char	**History;
extern	int	Curcnum;
extern	int	Hist_siz;
extern	char	*last_cmd;

#define	MAX_INS	15	/* maximum amount of redirection and shells */

struct	ins	{
	int	i_fd;
	int	i_nleft;
	char	*i_ptr;
	char	*i_buf;
	struct	forblk	*i_fblk;
};

extern	struct	ins	 in_bufs[], *Cur_ins;

/*
 * forblk - control struct for loops, later
 */

struct	forblk	{
	char	*F_name;
	char	**F_argv;
	int	F_argc;
};

extern	jmp_buf	env_main;
extern	int	ctrlcret;
#define	INTERUPT	1
#define	BADPARSE	2
#define	INT_READ	3
#define	NOMEM		4
#define	EXPRERR		5

extern	char	mustcd;

/* various flags */
extern	char	cflag, eflag, fflag, iflag, nflag, sflag, tflag;
extern	char	vflag, xflag, XVflag, Pflag; 
extern	char	Lflag;	/* flag, set if login shell */
extern	char	sh_script;	/* set if current command is a shell script */
extern	char	in_cshrc;	/* set if reading cshrc */
extern	char	*scr_name;
