xref: /titanic_44/usr/src/lib/libast/common/include/shcmd.h (revision cab25e88571b90083876d2876f790fdf153773a2)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2009 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 
24 /*
25  * ksh builtin command api
26  */
27 
28 #ifndef _SHCMD_H
29 #define _SHCMD_H	1
30 
31 #ifndef SH_VERSION
32 #   define Shell_t	void
33 #endif
34 #ifndef NV_DEFAULT
35 #   define Namval_t	void
36 #endif
37 #ifndef ERROR_NOTIFY
38 #   define ERROR_NOTIFY	1
39 #endif
40 
41 typedef int (*Shbltin_f)(int, char**, void*);
42 
43 #undef Shbltin_t
44 typedef struct Shbltin_s
45 {
46 	Shell_t		*shp;
47 	void		*ptr;
48 	int		version;
49 	int		(*shrun)(int, char**);
50 	int		(*shtrap)(const char*, int);
51 	void		(*shexit)(int);
52 	Namval_t	*(*shbltin)(const char*, Shbltin_f, void*);
53 	unsigned char	notify;
54 	unsigned char	sigset;
55 	unsigned char	nosfio;
56 	Namval_t	*bnode;
57 	Namval_t	*vnode;
58 	char		*data;
59 	int		flags;
60 	char		*(*shgetenv)(const char*);
61 	char		*(*shsetenv)(const char*);
62 	int		invariant;
63 } Shbltin_t;
64 
65 #if defined(SH_VERSION) ||  defined(_SH_PRIVATE)
66 #   undef Shell_t
67 #   undef Namval_t
68 #else
69 #   define sh_context(c)	((Shbltin_t*)(c))
70 #   define sh_run(c, ac, av)	((c)?(*sh_context(c)->shrun)(ac,av):-1)
71 #   define sh_system(c,str)	((c)?(*sh_context(c)->shtrap)(str,0):system(str))
72 #   define sh_exit(c,n)		((c)?(*sh_context(c)->shexit)(n):exit(n))
73 #   define sh_checksig(c)	((c) && sh_context(c)->sigset)
74 #   if defined(SFIO_VERSION) || defined(_AST_H)
75 #	define LIB_INIT(c)
76 #   else
77 #	define LIB_INIT(c)	((c) && (sh_context(c)->nosfio = 1))
78 #   endif
79 #   ifndef _CMD_H
80 #	define cmdinit(ac,av,c,cat,flg)		do { if((ac)<=0) return(0); \
81 	    (sh_context(c)->notify = ((flg)&ERROR_NOTIFY)?1:0);} while(0)
82 #   endif
83 #endif
84 
85 #if _BLD_ast && defined(__EXPORT__)
86 #define extern		__EXPORT__
87 #endif
88 
89 extern int		astintercept(Shbltin_t*, int);
90 
91 #undef	extern
92 
93 #endif
94