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

#include "shell.h"
#include "mystring.h"
#include "init.h"
#include "eval.h"
#include "expand.h"
#include <stdio.h>
#include "input.h"
#include "error.h"
#include "parser.h"
#include "redir.h"
#include "trap.h"
#include "output.h"
#include "memalloc.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "cd.h"
#include "var.h"



#undef  ATABSIZE
#define ATABSIZE 39
#undef  ARITH_MAX_PREC
#define ARITH_MAX_PREC 8
#undef  CD_PHYSICAL
#define CD_PHYSICAL 1
#undef  CD_PRINT
#define CD_PRINT 2
#undef  CMDTABLESIZE
#define CMDTABLESIZE 31		/* should be prime */
#undef  ARB
#define ARB 1			/* actual size determined at run time */
#undef  RMESCAPE_ALLOC
#define RMESCAPE_ALLOC	0x1	/* Allocate a new string */
#undef  RMESCAPE_GLOB
#define RMESCAPE_GLOB	0x2	/* Add backslashes for glob */
#undef  RMESCAPE_GROW
#define RMESCAPE_GROW	0x8	/* Grow strings instead of stalloc */
#undef  RMESCAPE_HEAP
#define RMESCAPE_HEAP	0x10	/* Malloc strings instead of stalloc */
#undef  QUOTES_ESC
#define QUOTES_ESC	(EXP_FULL | EXP_CASE | EXP_QPAT)
#undef  QUOTES_KEEPNUL
#define QUOTES_KEEPNUL	EXP_TILDE
#undef  MAXHISTLOOPS
#define MAXHISTLOOPS	4	/* max recursions through fc */
#undef  DEFEDITOR
#define DEFEDITOR	"ed"	/* default editor *should* be $EDITOR */
#undef  editing
#define editing (Eflag || Vflag)
#undef  EOF_NLEFT
#define EOF_NLEFT -99		/* value of parsenleft when EOF pushed back */
#undef  IBUFSIZ
#define IBUFSIZ (BUFSIZ + 1)
#undef  CUR_DELETE
#define CUR_DELETE 2
#undef  CUR_RUNNING
#define CUR_RUNNING 1
#undef  CUR_STOPPED
#define CUR_STOPPED 0
#undef  DOWAIT_NORMAL
#define DOWAIT_NORMAL 0
#undef  DOWAIT_BLOCK
#define DOWAIT_BLOCK 1
#undef  DOWAIT_WAITCMD
#define DOWAIT_WAITCMD 2
#undef  MAXMBOXES
#define MAXMBOXES 10
#undef  PROFILE
#define PROFILE 0
#undef  MINSIZE
#define MINSIZE SHELL_ALIGN(504)
#undef  DEFINE_OPTIONS
#define DEFINE_OPTIONS
#undef  FAKEEOFMARK
#define FAKEEOFMARK (char *)1
#undef  REALLY_CLOSED
#define REALLY_CLOSED -3	/* fd that was closed and still is */
#undef  EMPTY
#define EMPTY -2		/* marks an unused slot in redirtab */
#undef  CLOSED
#define CLOSED -1		/* fd opened for redir needs to be closed */
#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  OUTBUFSIZ
#define OUTBUFSIZ BUFSIZ
#undef  MEM_OUT
#define MEM_OUT -3		/* output to dynamically allocated memory */
#undef  SKIP1
#define SKIP1	"#-+ 0"
#undef  SKIP2
#define SKIP2	"*0123456789"
#undef  isalnum
#define isalnum _isalnum
#undef  iscntrl
#define iscntrl _iscntrl
#undef  islower
#define islower _islower
#undef  isspace
#define isspace _isspace
#undef  isalpha
#define isalpha _isalpha
#undef  isdigit
#define isdigit _isdigit
#undef  isprint
#define isprint _isprint
#undef  isupper
#define isupper _isupper
#undef  isblank
#define isblank _isblank
#undef  isgraph
#define isgraph _isgraph
#undef  ispunct
#define ispunct _ispunct
#undef  isxdigit
#define isxdigit _isxdigit
#undef  VTABSIZE
#define VTABSIZE 39



extern int loopnest;		/* current loop nesting level */

struct strpush {
	struct strpush *prev;	/* preceding string on stack */
	char *prevstring;
	int prevnleft;
	struct alias *ap;	/* if push was associated with an alias */
	char *string;		/* remember the string since it may change */
};

struct parsefile {
	struct parsefile *prev;	/* preceding file on stack */
	int linno;		/* current line */
	int fd;			/* file descriptor (or -1 if string) */
	int nleft;		/* number of chars left in this line */
	int lleft;		/* number of chars left in this buffer */
	char *nextc;		/* next char in buffer */
	char *buf;		/* input buffer */
	struct strpush *strpush; /* for pushing strings at this level */
	struct strpush basestrpush; /* so pushing one is fast */
};

extern int parselleft;		/* copy of parsefile->lleft */
extern struct parsefile basepf;	/* top level input file */
extern char basebuf[IBUFSIZ];	/* buffer for top level input file */

struct redirtab {
	struct redirtab *next;
	int renamed[10];
};

extern struct redirtab *redirlist;

extern struct localvar_list *localvar_stack;
extern char **environ;



/*
 * Initialization code.
 */

void
init() {

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/input.c: */
      {
	      basepf.nextc = basepf.buf = basebuf;
      }

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/trap.c: */
      {
	      sigmode[SIGCHLD - 1] = S_DFL;
	      setsignal(SIGCHLD);
      }

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/output.c: */
      {
#ifdef USE_GLIBC_STDIO
	      initstreams();
#endif
      }

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/var.c: */
      {
	      char **envp;
	      static char ppid[32] = "PPID=";
	      const char *p;
	      struct stat st1, st2;

	      initvar();
	      for (envp = environ ; *envp ; envp++) {
		      p = endofname(*envp);
		      if (p != *envp && *p == '=') {
			      setvareq(*envp, VEXPORT|VTEXTFIXED);
		      }
	      }

	      setvarint("OPTIND", 1, 0);

	      fmtstr(ppid + 5, sizeof(ppid) - 5, "%ld", (long) getppid());
	      setvareq(ppid, VTEXTFIXED);

	      p = lookupvar("PWD");
	      if (p)
		      if (*p != '/' || stat(p, &st1) || stat(".", &st2) ||
			  st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
			      p = 0;
	      setpwd(p, 0);
      }
}



/*
 * 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() {

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/eval.c: */
      {
	      evalskip = 0;
	      loopnest = 0;
      }

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/expand.c: */
      {
	      ifsfree();
      }

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/input.c: */
      {
	      parselleft = parsenleft = 0;	/* clear input buffer */
	      popallfiles();
      }

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/parser.c: */
      {
	      tokpushback = 0;
	      checkkwd = 0;
      }

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/redir.c: */
      {
	      /*
	       * Discard all saved file descriptors.
	       */
	      unwindredir(0);
      }

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/output.c: */
      {
#ifdef notyet
	      out1 = &output;
	      out2 = &errout;
#ifdef USE_GLIBC_STDIO
	      if (memout.stream != NULL)
		      __closememout();
#endif
	      if (memout.buf != NULL) {
		      ckfree(memout.buf);
		      memout.buf = NULL;
	      }
#endif
      }

      /* from /usr/src/dash-0.5.8-3.i686/src/dash-0.5.8/src/var.c: */
      {
	      unwindlocalvars(0);
      }
}
