xref: /titanic_44/usr/src/lib/libcmd/i386/include/ast/cmd.h (revision 023e71de9e5670cebc23dd51162833661d3d2d3b)
1 
2 /* : : generated by proto : : */
3 /***********************************************************************
4 *                                                                      *
5 *               This software is part of the ast package               *
6 *          Copyright (c) 1992-2009 AT&T Intellectual Property          *
7 *                      and is licensed under the                       *
8 *                  Common Public License, Version 1.0                  *
9 *                    by AT&T Intellectual Property                     *
10 *                                                                      *
11 *                A copy of the License is available at                 *
12 *            http://www.opensource.org/licenses/cpl1.0.txt             *
13 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
14 *                                                                      *
15 *              Information and Software Systems Research               *
16 *                            AT&T Research                             *
17 *                           Florham Park NJ                            *
18 *                                                                      *
19 *                 Glenn Fowler <gsf@research.att.com>                  *
20 *                  David Korn <dgk@research.att.com>                   *
21 *                                                                      *
22 ***********************************************************************/
23 
24 /*
25  * AT&T Research
26  *
27  * builtin cmd definitions
28  */
29 
30 #ifndef _CMD_H
31 #if !defined(__PROTO__)
32 #include <prototyped.h>
33 #endif
34 #if !defined(__LINKAGE__)
35 #define __LINKAGE__		/* 2004-08-11 transition */
36 #endif
37 
38 #define _CMD_H
39 
40 #include <ast.h>
41 #include <error.h>
42 #include <stak.h>
43 #include <shcmd.h>
44 
45 #define cmdinit			_cmd_init
46 
47 #define ERROR_CALLBACK		ERROR_SET
48 
49 #if _BLD_cmd && defined(__EXPORT__)
50 #undef __MANGLE__
51 #define __MANGLE__ __LINKAGE__		__EXPORT__
52 #endif
53 
54 #include <cmdext.h>
55 
56 #undef __MANGLE__
57 #define __MANGLE__ __LINKAGE__
58 
59 #if defined(CMD_BUILTIN) && !defined(CMD_STANDALONE)
60 #define CMD_STANDALONE	CMD_BUILTIN
61 #endif
62 
63 #ifdef CMD_STANDALONE
64 
65 #define CMD_CONTEXT(c)		((Shbltin_t*)0)
66 
67 #if CMD_DYNAMIC
68 
69 #include <dlldefs.h>
70 
71 typedef int (*Shbltin_f) __PROTO__((int, char**, __V_*));
72 
73 #else
74 
75 extern __MANGLE__ int CMD_STANDALONE __PROTO__((int, char**, __V_*));
76 
77 #endif
78 
79 #ifndef CMD_BUILTIN
80 
81 /*
82  * command initialization
83  */
84 
85 static int
86 cmdinit __PARAM__((int argc, register char** argv, __V_* context, const char* catalog, int flags), (argc, argv, context, catalog, flags)) __OTORP__(int argc; register char** argv; __V_* context; const char* catalog; int flags;){
87 	register char*	cp;
88 	register char*	pp;
89 
90 	if (cp = strrchr(argv[0], '/'))
91 		cp++;
92 	else
93 		cp = argv[0];
94 	if (pp = strrchr(cp, '_'))
95 		cp = pp + 1;
96 	error_info.id = cp;
97 	if (!error_info.catalog)
98 		error_info.catalog = (char*)catalog;
99 	opt_info.index = 0;
100 	if (context)
101 		error_info.flags |= flags & ~(ERROR_CALLBACK|ERROR_NOTIFY);
102 	return 0;
103 }
104 
105 #endif
106 
107 int
108 main __PARAM__((int argc, char** argv), (argc, argv)) __OTORP__(int argc; char** argv;){
109 #if CMD_DYNAMIC
110 	register char*	s;
111 	register char*	t;
112 	__V_*		dll;
113 	Shbltin_f	fun;
114 	char		buf[64];
115 
116 	if (s = strrchr(argv[0], '/'))
117 		s++;
118 	else if (!(s = argv[0]))
119 		return 127;
120 	if ((t = strrchr(s, '_')) && *++t)
121 		s = t;
122 	buf[0] = '_';
123 	buf[1] = 'b';
124 	buf[2] = '_';
125 	strncpy(buf + 3, s, sizeof(buf) - 4);
126 	buf[sizeof(buf) - 1] = 0;
127 	if (t = strchr(buf, '.'))
128 		*t = 0;
129 	for (;;)
130 	{
131 		if (dll = dlopen(NiL, RTLD_LAZY))
132 		{
133 			if (fun = (Shbltin_f)dlsym(dll, buf + 1))
134 				break;
135 			if (fun = (Shbltin_f)dlsym(dll, buf))
136 				break;
137 		}
138 		if (dll = dllfind("cmd", NiL, RTLD_LAZY))
139 		{
140 			if (fun = (Shbltin_f)dlsym(dll, buf + 1))
141 				break;
142 			if (fun = (Shbltin_f)dlsym(dll, buf))
143 				break;
144 		}
145 		return 127;
146 	}
147 	return (*fun)(argc, argv, NiL);
148 #else
149 	return CMD_STANDALONE(argc, argv, NiL);
150 #endif
151 }
152 
153 #else
154 
155 #undef	cmdinit
156 #ifdef _MSC_VER
157 #define CMD_CONTEXT(p)		((Shbltin_t*)(p))
158 #define cmdinit(a,b,c,d,e)	do{if(_cmd_init(a,b,c,d,e))return -1;}while(0)
159 #else
160 #define CMD_CONTEXT(p)		(((p)&&((Shbltin_t*)(p))->version>=20071012&&((Shbltin_t*)(p))->version<20350101)?((Shbltin_t*)(p)):0)
161 #define cmdinit(a,b,c,d,e)	do{if((c)&&!CMD_CONTEXT(c))c=0;if(_cmd_init(a,b,c,d,e))return -1;}while(0)
162 #endif
163 
164 #if _BLD_cmd && defined(__EXPORT__)
165 #undef __MANGLE__
166 #define __MANGLE__ __LINKAGE__ __EXPORT__
167 #endif
168 
169 extern __MANGLE__ int	_cmd_init __PROTO__((int, char**, __V_*, const char*, int));
170 
171 #undef __MANGLE__
172 #define __MANGLE__ __LINKAGE__
173 
174 #endif
175 
176 #endif
177