/*
 * This file was generated by the mkinit program.
 */

#include "shell.h"
#include "mystring.h"
#include "init.h"
#include "eval.h"
#include <stdio.h>
#include "input.h"
#include "error.h"
#include <stdlib.h>
#include "options.h"
#include "output.h"
#include "memalloc.h"
#include "redir.h"
#include <signal.h>
#include "trap.h"
#include "var.h"
#include "shinstance.h"



#undef  PROFILE
#define PROFILE 0
#undef  SIGSSIZE
#define SIGSSIZE (sizeof(sigs)/sizeof(sigs[0]))
#undef  MAXPWD
#define MAXPWD 256
#undef  ALL
#define ALL (E_OPEN|E_CREAT|E_EXEC)
#undef  EV_EXIT
#define EV_EXIT 01		/* exit after evaluating tree */
#undef  EV_TESTED
#define EV_TESTED 02		/* exit status is checked; ignore -e flag */
#undef  EV_BACKCMD
#define EV_BACKCMD 04		/* command executing within back quotes */
#undef  NEWARGS
#define NEWARGS 5
#undef  MAXHISTLOOPS
#define MAXHISTLOOPS	4	/* max recursions through fc */
#undef  DEFEDITOR
#define DEFEDITOR	"ed"	/* default editor *should* be $EDITOR */
#undef  editing
#define editing (Eflag(psh) || Vflag(psh))
#undef  EOF_NLEFT
#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
#undef  DEFINE_OPTIONS
#define DEFINE_OPTIONS
#undef  BLOCK_OUT
#define BLOCK_OUT -2		/* output to a fixed block of memory */
#undef  OUTPUT_ERR
#define OUTPUT_ERR 01		/* error occurred on output */
#undef  TEMPSIZE
#define TEMPSIZE 32
#undef  HAVE_VASPRINTF
#define HAVE_VASPRINTF 1
#undef  EOFMARKLEN
#define EOFMARKLEN 79
#undef  OPENBRACE
#define OPENBRACE '{'
#undef  CLOSEBRACE
#define CLOSEBRACE '}'
#undef  EMPTY
#define EMPTY -2		/* marks an unused slot in redirtab */
#undef  S_DFL
#define S_DFL 1			/* default signal handling (SIG_DFL) */
#undef  S_CATCH
#define S_CATCH 2		/* signal is caught */
#undef  S_IGN
#define S_IGN 3			/* signal is ignored (SIG_IGN) */
#undef  S_HARD_IGN
#define S_HARD_IGN 4		/* signal is ignored permenantly */
#undef  S_RESET
#define S_RESET 5		/* temporary - to reset a hard ignored sig */
#undef  INCL_BASE
#define INCL_BASE
#undef  LIBPATHSTRICT
#define LIBPATHSTRICT 3
#undef  QHINF_EXEINFO
#define QHINF_EXEINFO       1 /* NE exeinfo. */
#undef  QHINF_READRSRCTBL
#define QHINF_READRSRCTBL   2 /* Reads from the resource table. */
#undef  QHINF_READFILE
#define QHINF_READFILE      3 /* Reads from the executable file. */
#undef  QHINF_LIBPATHLENGTH
#define QHINF_LIBPATHLENGTH 4 /* Gets the libpath length. */
#undef  QHINF_LIBPATH
#define QHINF_LIBPATH       5 /* Gets the entire libpath. */
#undef  QHINF_FIXENTRY
#define QHINF_FIXENTRY      6 /* NE only */
#undef  QHINF_STE
#define QHINF_STE           7 /* NE only */
#undef  QHINF_MAPSEL
#define QHINF_MAPSEL        8 /* NE only */
#undef  SET_LEN
#define	SET_LEN	6		/* initial # of bitcmd struct to malloc */
#undef  SET_LEN_INCR
#define	SET_LEN_INCR 4		/* # of bitcmd structs to add as needed */
#undef  CMD2_CLR
#define	CMD2_CLR	0x01
#undef  CMD2_SET
#define	CMD2_SET	0x02
#undef  CMD2_GBITS
#define	CMD2_GBITS	0x04
#undef  CMD2_OBITS
#define	CMD2_OBITS	0x08
#undef  CMD2_UBITS
#define	CMD2_UBITS	0x10
#undef  STANDARD_BITS
#define	STANDARD_BITS	(S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
#undef  SHMEMHDR_MAGIC_FREE
#define SHMEMHDR_MAGIC_FREE     0xbeeff00d
#undef  SHMEMHDR_MAGIC_USED
#define SHMEMHDR_MAGIC_USED     0xfeedface
#undef  SHMEMCHUNK_MAGIC
#define SHMEMCHUNK_MAGIC        0x12345678
#undef  SHHEAP_MIN_CHUNK
#define SHHEAP_MIN_CHUNK        0x80000 //(1024*1024)
#undef  SHFILE_MAX
#define SHFILE_MAX          1024
#undef  SHFILE_GROW
#define SHFILE_GROW         64
#undef  SHFILE_UNIX_MIN_FD
#define SHFILE_UNIX_MIN_FD  32
#undef  SHFILE_MAX_PATH
#define SHFILE_MAX_PATH     4096
#undef  YY_NO_UNPUT
#define YY_NO_UNPUT



extern void rmaliases(shinstance *psh);

extern void deletefuncs(struct shinstance *);
extern void hash_special_builtins(struct shinstance *);



/*
 * Initialization code.
 */

void
init(shinstance *psh) {

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/exec.c: */
      {
	      hash_special_builtins(psh);
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/input.c: */
      {
	      psh->basepf.nextc = psh->basepf.buf = psh->basebuf;
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/options.c: */
      {
	      memcpy(&psh->optlist[0], &ro_optlist[0], sizeof(psh->optlist));
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/var.c: */
      {
	      char **envp;

	      initvar(psh);
	      for (envp = sh_environ(psh) ; *envp ; envp++) {
		      if (strchr(*envp, '=')) {
			      setvareq(psh, *envp, VEXPORT|VTEXTFIXED);
		      }
	      }
      }
}



/*
 * This routine is called when an error or an interrupt occurs in an
 * interactive shell and control is returned to the main command loop.
 */

void
reset(shinstance *psh) {

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/eval.c: */
      {
	      psh->evalskip = 0;
	      psh->loopnest = 0;
	      psh->funcnest = 0;
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/input.c: */
      {
	      if (psh->exception != EXSHELLPROC)
		      psh->parselleft = psh->parsenleft = 0;	/* clear input buffer */
	      popallfiles(psh);
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/output.c: */
      {
	      psh->out1 = &psh->output;
	      psh->out2 = &psh->errout;
	      if (psh->memout.buf != NULL) {
		      ckfree(psh, psh->memout.buf);
		      psh->memout.buf = NULL;
		      psh->memout.nextc = NULL;
	      }
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/parser.c: */
      {
	      psh->tokpushback = 0;
	      psh->checkkwd = 0;
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/redir.c: */
      {
	      while (psh->redirlist)
		      popredir(psh);
      }
}



/*
 * This routine is called to initialize the shell to run a shell procedure.
 */

void
initshellproc(shinstance *psh) {

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/alias.c: */
      {
	      rmaliases(psh);
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/eval.c: */
      {
	      psh->exitstatus = 0;
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/exec.c: */
      {
	      deletefuncs(psh);
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/input.c: */
      {
	      popallfiles(psh);
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/jobs.c: */
      {
	      psh->backgndpid = -1;
#if JOBS
	      psh->jobctl = 0;
#endif
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/options.c: */
      {
	      int i;

	      for (i = 0; psh->optlist[i].name; i++)
		      psh->optlist[i].val = 0;
# if DEBUG == 2
	      debug(psh) = 1;
# endif
	      optschanged(psh);
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/redir.c: */
      {
	      clearredir(psh);
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/trap.c: */
      {
	      char *sm;

	      clear_traps(psh);
	      for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) {
		      if (*sm == S_IGN)
			      *sm = S_HARD_IGN;
	      }
      }

      /* from /Volumes/ScratchHFS/bird/kBuild/svn/trunk/src/kash/var.c: */
      {
	      shprocvar(psh);
      }
}
