xref: /titanic_44/usr/src/lib/libcmd/amd64/include/ast/cmd.h (revision 55553f719b521a0bb4deab6efc944cd30c1a56aa)
1 
2 /* : : generated by proto : : */
3 /***********************************************************************
4 *                                                                      *
5 *               This software is part of the ast package               *
6 *           Copyright (c) 1992-2007 AT&T Knowledge Ventures            *
7 *                      and is licensed under the                       *
8 *                  Common Public License, Version 1.0                  *
9 *                      by AT&T Knowledge Ventures                      *
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 
44 #define cmdinit			_cmd_init
45 #define cmdquit()		0
46 
47 #if _BLD_cmd && defined(__EXPORT__)
48 #undef __MANGLE__
49 #define __MANGLE__ __LINKAGE__		__EXPORT__
50 #endif
51 
52 #include <cmdext.h>
53 
54 #undef __MANGLE__
55 #define __MANGLE__ __LINKAGE__
56 
57 #if defined(CMD_BUILTIN) && !defined(CMD_STANDALONE)
58 #define CMD_STANDALONE	CMD_BUILTIN
59 #endif
60 
61 #ifdef CMD_STANDALONE
62 
63 #if CMD_DYNAMIC
64 
65 #include <dlldefs.h>
66 
67 typedef int (*Builtin_f) __PROTO__((int, char**, __V_*));
68 
69 #else
70 
71 extern __MANGLE__ int CMD_STANDALONE __PROTO__((int, char**, __V_*));
72 
73 #endif
74 
75 #ifndef CMD_BUILTIN
76 
77 /*
78  * command initialization
79  */
80 
81 static int
82 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;){
83 	register char*	cp;
84 	register char*	pp;
85 
86 	if (cp = strrchr(argv[0], '/'))
87 		cp++;
88 	else
89 		cp = argv[0];
90 	if (pp = strrchr(cp, '_'))
91 		cp = pp + 1;
92 	error_info.id = cp;
93 	if (!error_info.catalog)
94 		error_info.catalog = (char*)catalog;
95 	opt_info.index = 0;
96 	if (context)
97 		error_info.flags |= flags;
98 	return 0;
99 }
100 
101 #endif
102 
103 int
104 main __PARAM__((int argc, char** argv), (argc, argv)) __OTORP__(int argc; char** argv;){
105 #if CMD_DYNAMIC
106 	register char*	s;
107 	register char*	t;
108 	__V_*		dll;
109 	Builtin_f	fun;
110 	char		buf[64];
111 
112 	if (s = strrchr(argv[0], '/'))
113 		s++;
114 	else if (!(s = argv[0]))
115 		return 127;
116 	if ((t = strrchr(s, '_')) && *++t)
117 		s = t;
118 	buf[0] = '_';
119 	buf[1] = 'b';
120 	buf[2] = '_';
121 	strncpy(buf + 3, s, sizeof(buf) - 4);
122 	buf[sizeof(buf) - 1] = 0;
123 	if (t = strchr(buf, '.'))
124 		*t = 0;
125 	for (;;)
126 	{
127 		if (dll = dlopen(NiL, RTLD_LAZY))
128 		{
129 			if (fun = (Builtin_f)dlsym(dll, buf + 1))
130 				break;
131 			if (fun = (Builtin_f)dlsym(dll, buf))
132 				break;
133 		}
134 		if (dll = dllfind("cmd", NiL, RTLD_LAZY))
135 		{
136 			if (fun = (Builtin_f)dlsym(dll, buf + 1))
137 				break;
138 			if (fun = (Builtin_f)dlsym(dll, buf))
139 				break;
140 		}
141 		return 127;
142 	}
143 	return (*fun)(argc, argv, NiL);
144 #else
145 	return CMD_STANDALONE(argc, argv, NiL);
146 #endif
147 }
148 
149 #else
150 
151 #undef	cmdinit
152 #define cmdinit(a,b,c,d,e)	do{if(_cmd_init(a,b,c,d,e))return -1;}while(0)
153 
154 #ifndef CMD_BUILTIN
155 
156 #undef	cmdquit
157 #define cmdquit()		(_cmd_quit)
158 
159 #if _BLD_cmd && defined(__EXPORT__)
160 #undef __MANGLE__
161 #define __MANGLE__ __LINKAGE__ __EXPORT__
162 #endif
163 #if !_BLD_cmd && defined(__IMPORT__)
164 #undef __MANGLE__
165 #define __MANGLE__ __LINKAGE__ __IMPORT__
166 #endif
167 
168 extern __MANGLE__ int	_cmd_quit;
169 
170 #undef __MANGLE__
171 #define __MANGLE__ __LINKAGE__
172 
173 #endif
174 
175 #if _BLD_cmd && defined(__EXPORT__)
176 #undef __MANGLE__
177 #define __MANGLE__ __LINKAGE__ __EXPORT__
178 #endif
179 
180 extern __MANGLE__ int	_cmd_init __PROTO__((int, char**, __V_*, const char*, int));
181 
182 #undef __MANGLE__
183 #define __MANGLE__ __LINKAGE__
184 
185 #endif
186 
187 #endif
188