1da2e3ebchin/***********************************************************************
2da2e3ebchin*                                                                      *
3da2e3ebchin*               This software is part of the ast package               *
43e14f97Roger A. Faulkner*          Copyright (c) 1982-2010 AT&T Intellectual Property          *
5da2e3ebchin*                      and is licensed under the                       *
6da2e3ebchin*                  Common Public License, Version 1.0                  *
77c2fbfbApril Chin*                    by AT&T Intellectual Property                     *
8da2e3ebchin*                                                                      *
9da2e3ebchin*                A copy of the License is available at                 *
10da2e3ebchin*            http://www.opensource.org/licenses/cpl1.0.txt             *
11da2e3ebchin*         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12da2e3ebchin*                                                                      *
13da2e3ebchin*              Information and Software Systems Research               *
14da2e3ebchin*                            AT&T Research                             *
15da2e3ebchin*                           Florham Park NJ                            *
16da2e3ebchin*                                                                      *
17da2e3ebchin*                  David Korn <dgk@research.att.com>                   *
18da2e3ebchin*                                                                      *
19da2e3ebchin***********************************************************************/
20da2e3ebchin#pragma prototyped
21da2e3ebchin#ifndef SH_SIGBITS
22da2e3ebchin/*
23da2e3ebchin *	UNIX shell
24da2e3ebchin *	S. R. Bourne
25da2e3ebchin *	Rewritten by David Korn
26da2e3ebchin *
27da2e3ebchin */
28da2e3ebchin
29da2e3ebchin#include	<sig.h>
30da2e3ebchin#include	<setjmp.h>
31da2e3ebchin#include	<error.h>
32da2e3ebchin#include	<sfio.h>
33da2e3ebchin#include	"FEATURE/setjmp"
34da2e3ebchin#include	"FEATURE/sigfeatures"
35da2e3ebchin
367c2fbfbApril Chin
37da2e3ebchin#ifndef SIGWINCH
38da2e3ebchin#   ifdef SIGWIND
39da2e3ebchin#	define SIGWINCH	SIGWIND
40da2e3ebchin#   else
41da2e3ebchin#	ifdef SIGWINDOW
42da2e3ebchin#	    define SIGWINCH	SIGWINDOW
43da2e3ebchin#	endif
44da2e3ebchin#   endif
45da2e3ebchin#endif
46da2e3ebchin
47da2e3ebchintypedef void (*SH_SIGTYPE)(int,void(*)(int));
48da2e3ebchin
49da2e3ebchin#define SH_FORKLIM		16	/* fork timeout interval */
50da2e3ebchin
51da2e3ebchin#define SH_TRAP			0200	/* bit for internal traps */
52da2e3ebchin#define SH_ERRTRAP		0	/* trap for non-zero exit status */
53da2e3ebchin#define SH_KEYTRAP		1	/* trap for keyboard event */
54da2e3ebchin#define SH_DEBUGTRAP		4	/* must be last internal trap */
55da2e3ebchin
56da2e3ebchin#define SH_SIGBITS		8
57da2e3ebchin#define SH_SIGFAULT		1	/* signal handler is sh_fault */
58da2e3ebchin#define SH_SIGOFF		2	/* signal handler is SIG_IGN */
59da2e3ebchin#define SH_SIGSET		4	/* pending signal */
60da2e3ebchin#define SH_SIGTRAP		010	/* pending trap */
61da2e3ebchin#define SH_SIGDONE		020	/* default is exit */
62da2e3ebchin#define SH_SIGIGNORE		040	/* default is ingore signal */
63da2e3ebchin#define SH_SIGINTERACTIVE	0100	/* handle interactive specially */
64da2e3ebchin#define SH_SIGTSTP		0200	/* tstp signal received */
65da2e3ebchin#define SH_SIGALRM		0200	/* timer alarm received */
66da2e3ebchin#define SH_SIGTERM		SH_SIGOFF /* term signal received */
677c2fbfbApril Chin#define SH_SIGRUNTIME		0400	/* runtime value */
687c2fbfbApril Chin
697c2fbfbApril Chin#define SH_SIGRTMIN		0	/* sh.sigruntime[] index */
707c2fbfbApril Chin#define SH_SIGRTMAX		1	/* sh.sigruntime[] index */
71da2e3ebchin
72da2e3ebchin/*
73da2e3ebchin * These are longjmp values
74da2e3ebchin */
75da2e3ebchin
76da2e3ebchin#define SH_JMPDOT	2
77da2e3ebchin#define SH_JMPEVAL	3
78da2e3ebchin#define SH_JMPTRAP	4
79da2e3ebchin#define SH_JMPIO	5
80da2e3ebchin#define SH_JMPCMD	6
81da2e3ebchin#define SH_JMPFUN	7
82da2e3ebchin#define SH_JMPERRFN	8
83da2e3ebchin#define SH_JMPSUB	9
84da2e3ebchin#define SH_JMPERREXIT	10
85da2e3ebchin#define SH_JMPEXIT	11
86da2e3ebchin#define SH_JMPSCRIPT	12
87da2e3ebchin
88da2e3ebchinstruct openlist
89da2e3ebchin{
90da2e3ebchin	Sfio_t	*strm;
91da2e3ebchin	struct openlist *next;
92da2e3ebchin};
93da2e3ebchin
94da2e3ebchinstruct checkpt
95da2e3ebchin{
96da2e3ebchin	sigjmp_buf	buff;
97da2e3ebchin	sigjmp_buf	*prev;
98da2e3ebchin	int		topfd;
99da2e3ebchin	int		mode;
100da2e3ebchin	struct openlist	*olist;
101da2e3ebchin#if (ERROR_VERSION >= 20030214L)
102da2e3ebchin	Error_context_t err;
103da2e3ebchin#else
104da2e3ebchin	struct errorcontext err;
105da2e3ebchin#endif
106da2e3ebchin};
107da2e3ebchin
108da2e3ebchin#define sh_pushcontext(bp,n)	( (bp)->mode=(n) , (bp)->olist=0,  \
109da2e3ebchin				  (bp)->topfd=sh.topfd, (bp)->prev=sh.jmplist, \
110da2e3ebchin				  (bp)->err = *ERROR_CONTEXT_BASE, \
111da2e3ebchin					sh.jmplist = (sigjmp_buf*)(&(bp)->buff) \
112da2e3ebchin				)
113da2e3ebchin#define sh_popcontext(bp)	(sh.jmplist=(bp)->prev, errorpop(&((bp)->err)))
114da2e3ebchin
115da2e3ebchinextern void 	sh_fault(int);
1167c2fbfbApril Chinextern void 	sh_done(void*,int);
117da2e3ebchinextern void 	sh_chktrap(void);
118da2e3ebchinextern void 	sh_sigclear(int);
119da2e3ebchinextern void 	sh_sigdone(void);
1207c2fbfbApril Chinextern void	sh_siginit(void*);
121da2e3ebchinextern void 	sh_sigtrap(int);
122da2e3ebchinextern void 	sh_sigreset(int);
123da2e3ebchinextern void 	sh_timetraps(void);
124da2e3ebchinextern void 	*sh_timeradd(unsigned long,int ,void (*)(void*),void*);
125da2e3ebchinextern void	timerdel(void*);
126da2e3ebchin
127da2e3ebchinextern const char e_alarm[];
128da2e3ebchin
129da2e3ebchin#endif /* !SH_SIGBITS */
130