/*
 * CDE - Common Desktop Environment
 *
 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these libraries and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
 */
/* $XConsortium: defs.h /main/3 1995/11/01 16:39:16 rswiston $ */
/***************************************************************
*                                                              *
*                      AT&T - PROPRIETARY                      *
*                                                              *
*        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF        *
*                    AT&T BELL LABORATORIES                    *
*         AND IS NOT TO BE DISCLOSED OR USED EXCEPT IN         *
*            ACCORDANCE WITH APPLICABLE AGREEMENTS             *
*                                                              *
*                Copyright (c) 1995 AT&T Corp.                 *
*              Unpublished & Not for Publication               *
*                     All Rights Reserved                      *
*                                                              *
*       The copyright notice above does not evidence any       *
*      actual or intended publication of such source code      *
*                                                              *
*               This software was created by the               *
*           Advanced Software Technology Department            *
*                    AT&T Bell Laboratories                    *
*                                                              *
*               For further information contact                *
*                    {research,attmail}!dgk                    *
*                                                              *
***************************************************************/

/* : : generated by proto : : */

#if !defined(__PROTO__)
#if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
#if defined(__cplusplus)
#define __MANGLE__	"C"
#else
#define __MANGLE__
#endif
#define __STDARG__
#define __PROTO__(x)	x
#define __OTORP__(x)
#define __PARAM__(n,o)	n
#if !defined(__STDC__) && !defined(__cplusplus)
#if !defined(c_plusplus)
#define const
#endif
#define signed
#define void		int
#define volatile
#define __V_		char
#else
#define __V_		void
#endif
#else
#define __PROTO__(x)	()
#define __OTORP__(x)	x
#define __PARAM__(n,o)	o
#define __MANGLE__
#define __V_		char
#define const
#define signed
#define void		int
#define volatile
#endif
#if defined(__cplusplus) || defined(c_plusplus)
#define __VARARG__	...
#else
#define __VARARG__
#endif
#if defined(__STDARG__)
#define __VA_START__(p,a)	va_start(p,a)
#else
#define __VA_START__(p,a)	va_start(p)
#endif
#endif
#define mount	_AST__mount

#include	<ast.h>
#include	<sfio.h>
#include	<error.h>
#include	"FEATURE/options"
#include	<history.h>
#include	"fault.h"
#include	"argnod.h"

struct sh_scoped
{
	struct slnod	*staklist;	/* link list of function stacks */
	int		states;
	int		breakcnt;
	int		execbrk;
	int		loopcnt;
	int		firstline;
	int		dolc;
	char		**dolv;
	long		optindex;
	long		optnum;
	short		optchar;
	short		opterror;
	char		*cmdname;
	int		ioset;
	short		trapmax;
	char		*trap[SH_DEBUGTRAP+1];
	char		**trapcom;
	char		**otrapcom;
	__V_		*timetrap;
	__V_		*par_tree;	/* for calling function */
	struct sh_scoped *prevst;	/* pointer to previous state */
};

struct limits
{
	int		open_max;	/* maximum number of file descriptors */
	int		clk_tck;	/* number of ticks per second */
	int		child_max;	/* maxumum number of children */
	int		ngroups_max;	/* maximum number of process groups */
	unsigned char	posix_version;	/* posix version number */
	unsigned char	posix_jobcontrol;/* non-zero for job control systems */
	unsigned char	fs3d;		/* non-zero for 3-d file system */
};

#define _SH_PRIVATE \
	struct sh_scoped st;		/* scoped information */ \
	struct limits	lim;		/* run time limits */ \
	Hashtab_t	*track_tree;	/* for tracked aliases*/ \
	Hashtab_t	*bltin_tree;	/* for builtin commands */ \
	Hashtab_t	*var_base;	/* global level variables */ \
	History_t	*hist_ptr;	/* history file pointer */ \
	Sfio_t		*outpool;	/* ouput stream pool */ \
	long		timeout;	/* read timeout */ \
	long		tmout;		/* value for TMOUT */ \
	int		curenv;		/* current subshell number */ \
	int		jobenv;		/* subshell number for jobs */ \
	int		nextprompt;	/* next prompt is PS<nextprompt> */ \
	Namval_t	*bltin_cmds;	/* pointer to built-in commands */ \
	Namval_t	*posix_fun;	/* points to last name() function */ \
	int		infd;		/* input file descriptor */ \
	char		*outbuff;	/* pointer to output buffer */ \
	char		*errbuff;	/* pointer to stderr buffer */ \
	char		*prompt;	/* pointer to prompt string */ \
	char		*shname;	/* shell name */ \
	char		*comdiv;	/* points to sh -c argument */ \
	char		*prefix;	/* prefix for compound assignment */ \
	sigjmp_buf	*jmplist;	/* longjmp return stack */ \
	char		**sigmsg;	/* points to signal messages */ \
	int		oldexit; \
	uid_t 		userid,euserid;	/* real and effective user id */ \
	gid_t 		groupid,egroupid;/* real and effective group id */ \
	pid_t		pid;		/* process id of shell */ \
	pid_t		bckpid;		/* background process id */ \
	pid_t		cpid; \
	long		ppid;		/* parent process id of shell */ \
	int		topfd; \
	int		sigmax;		/* maximum number of signals */ \
	unsigned char	*sigflag;	/* pointer to signal states */ \
	char		intrap; \
	char		login_sh; \
	char		lastbase; \
	char		universe; \
	char		forked;	\
	char		binscript;	\
	char		used_pos;	/* used postional parameter */\
	unsigned char	lastsig;	/* last signal received */ \
	char		*readscript;	/* set before reading a script */ \
	int		*inpipe;	/* input pipe pointer */ \
	int		*outpipe;	/* output pipe pointer */ \
	int		cpipe[2]; \
	int		coutpipe; \
	struct argnod	*envlist; \
	struct dolnod	*arglist; \
	int		fn_depth; \
	int		dot_depth; \
	long		nforks; \
	char		ifstable[256];

#include	<shell.h>


/* error exits from various parts of shell */
#define	NIL(type)	((type)0)

#define new_of(type,x)	((type*)malloc((unsigned)sizeof(type)+(x)))

#define exitset()	(sh.savexit=sh.exitval)


/* states */
/* low numbered states are same as options */
#define SH_NOFORK	0x1	/* set when fork not necessary, not a state */
#define SH_COMPLETE	0x1	/* set for command completion */
#define SH_TTYWAIT	0x40	/* waiting for keyboard input */ 
#define	SH_FORKED	0x80	/* set when process has been forked */
#define	SH_PROFILE	0x100	/* set when processing profiles */
#define SH_NOALIAS	0x200	/* do not expand non-exported aliases */
#define SH_NOTRACK	0x400	/* set to disable sftrack() function */
#define SH_STOPOK	0x800	/* set for stopable builtins */
#define SH_GRACE	0x1000	/* set for timeout grace period */
#define SH_TIMING	0x2000	/* set while timing pipelines */
#define SH_DEFPATH	0x4000	/* set when using default path */
#define SH_INIT		0x8000	/* set when initializing the shell */

extern __MANGLE__ Namval_t		*sh_assignok __PROTO__((Namval_t*,int));
extern __MANGLE__ int 		sh_echolist __PROTO__((Sfio_t*, int, char**));
extern __MANGLE__ struct argnod	*sh_endword __PROTO__((int));
extern __MANGLE__ char 		**sh_envgen __PROTO__((void));
extern __MANGLE__ void 		sh_envnolocal __PROTO__((Namval_t*));
extern __MANGLE__ char		*sh_etos __PROTO__((double,int));
extern __MANGLE__ char		*sh_ftos __PROTO__((double,int));
extern __MANGLE__ double		sh_arith __PROTO__((const char*));
extern __MANGLE__ pid_t 		sh_fork __PROTO__((int,int*));
extern __MANGLE__ char 		*sh_mactrim __PROTO__((char*,int));
extern __MANGLE__ int 		sh_macexpand __PROTO__((struct argnod*,struct argnod**));
extern __MANGLE__ void 		sh_machere __PROTO__((Sfio_t*, Sfio_t*, char*));
extern __MANGLE__ char 		*sh_mactry __PROTO__((char*));
extern __MANGLE__ int 		sh_readline __PROTO__((char**,int,int,long));
extern __MANGLE__ void		sh_reinit __PROTO__((char*[]));
extern __MANGLE__ Sfio_t		*sh_sfeval __PROTO__((char*[]));
extern __MANGLE__ void		sh_subtmpfile __PROTO__((void));
extern __MANGLE__ Sfio_t 		*sh_subshell __PROTO__((union anynode*, int, int));
extern __MANGLE__ char 		*sh_substitute __PROTO__((const char*,const char*,char*));
extern __MANGLE__ int		sh_tdump __PROTO__((Sfio_t*, const union anynode*));
extern __MANGLE__ int		sh_trace __PROTO__((char*[],int));
extern __MANGLE__ union anynode	*sh_trestore __PROTO__((Sfio_t*));
extern __MANGLE__ void		sh_trim __PROTO__((char*));
extern __MANGLE__ void		sh_userinit __PROTO__((void));
extern __MANGLE__ int 		sh_whence __PROTO__((char**,int));


#define	sh_isstate(x)	(sh.st.states&((int)(x)))
#define	sh_onstate(x)	(sh.st.states |= ((int)(x)))
#define	sh_setstate(x)	(sh.st.states = ((int)(x)))
#define	sh_offstate(x)	(sh.st.states &= ~((int)(x)))

extern __MANGLE__ time_t		sh_mailchk;
