xref: /titanic_51/usr/src/lib/libast/common/include/shcmd.h (revision 613a2f6ba31e891e3d947a356daf5e563d43c1ce)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 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_run(c, ac, av)	((c)?(*((Shbltin_t*)(c))->shrun)(ac,av):-1)
70 #   define sh_system(c,str)	((c)?(*((Shbltin_t*)(c))->shtrap)(str,0):system(str))
71 #   define sh_exit(c,n)		((c)?(*((Shbltin_t*)(c))->shexit)(n):exit(n))
72 #   define sh_checksig(c)	((c) && ((Shbltin_t*)(c))->sigset)
73 #   if defined(SFIO_VERSION) || defined(_AST_H)
74 #	define LIB_INIT(c)
75 #   else
76 #	define LIB_INIT(c)	((c) && (((Shbltin_t*)(c))->nosfio = 1))
77 #   endif
78 #   ifndef _CMD_H
79 #	define cmdinit(ac,av,c,cat,flg)		do { if((ac)<=0) return(0); \
80 	    (((Shbltin_t*)(c))->notify = ((flg)&ERROR_NOTIFY)?1:0);} while(0)
81 #   endif
82 #endif
83 
84 #if _BLD_ast && defined(__EXPORT__)
85 #define extern		__EXPORT__
86 #endif
87 
88 extern int		astintercept(Shbltin_t*, int);
89 
90 #undef	extern
91 
92 #endif
93