xref: /titanic_41/usr/src/lib/libcmd/amd64/include/ast/cmd.h (revision bda1f129971950880940a17bab0bf096d5744b0c)
1 
2 /* : : generated by proto : : */
3 /***********************************************************************
4 *                                                                      *
5 *               This software is part of the ast package               *
6 *          Copyright (c) 1992-2008 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 #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 #define CMD_CONTEXT(c)		((Shbltin_t*)0)
64 
65 #if CMD_DYNAMIC
66 
67 #include <dlldefs.h>
68 
69 typedef int (*Shbltin_f) __PROTO__((int, char**, __V_*));
70 
71 #else
72 
73 extern __MANGLE__ int CMD_STANDALONE __PROTO__((int, char**, __V_*));
74 
75 #endif
76 
77 #ifndef CMD_BUILTIN
78 
79 /*
80  * command initialization
81  */
82 
83 static int
84 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;){
85 	register char*	cp;
86 	register char*	pp;
87 
88 	if (cp = strrchr(argv[0], '/'))
89 		cp++;
90 	else
91 		cp = argv[0];
92 	if (pp = strrchr(cp, '_'))
93 		cp = pp + 1;
94 	error_info.id = cp;
95 	if (!error_info.catalog)
96 		error_info.catalog = (char*)catalog;
97 	opt_info.index = 0;
98 	if (context)
99 		error_info.flags |= flags;
100 	return 0;
101 }
102 
103 #endif
104 
105 int
106 main __PARAM__((int argc, char** argv), (argc, argv)) __OTORP__(int argc; char** argv;){
107 #if CMD_DYNAMIC
108 	register char*	s;
109 	register char*	t;
110 	__V_*		dll;
111 	Shbltin_f	fun;
112 	char		buf[64];
113 
114 	if (s = strrchr(argv[0], '/'))
115 		s++;
116 	else if (!(s = argv[0]))
117 		return 127;
118 	if ((t = strrchr(s, '_')) && *++t)
119 		s = t;
120 	buf[0] = '_';
121 	buf[1] = 'b';
122 	buf[2] = '_';
123 	strncpy(buf + 3, s, sizeof(buf) - 4);
124 	buf[sizeof(buf) - 1] = 0;
125 	if (t = strchr(buf, '.'))
126 		*t = 0;
127 	for (;;)
128 	{
129 		if (dll = dlopen(NiL, RTLD_LAZY))
130 		{
131 			if (fun = (Shbltin_f)dlsym(dll, buf + 1))
132 				break;
133 			if (fun = (Shbltin_f)dlsym(dll, buf))
134 				break;
135 		}
136 		if (dll = dllfind("cmd", NiL, RTLD_LAZY))
137 		{
138 			if (fun = (Shbltin_f)dlsym(dll, buf + 1))
139 				break;
140 			if (fun = (Shbltin_f)dlsym(dll, buf))
141 				break;
142 		}
143 		return 127;
144 	}
145 	return (*fun)(argc, argv, NiL);
146 #else
147 	return CMD_STANDALONE(argc, argv, NiL);
148 #endif
149 }
150 
151 #else
152 
153 #undef	cmdinit
154 #ifdef _MSC_VER
155 #define CMD_CONTEXT(p)		((Shbltin_t*)(p))
156 #define cmdinit(a,b,c,d,e)	do{if(_cmd_init(a,b,c,d,e))return -1;}while(0)
157 #else
158 #define CMD_CONTEXT(p)		(((p)&&((Shbltin_t*)(p))->version>=20071012&&((Shbltin_t*)(p))->version<20350101)?((Shbltin_t*)(p)):0)
159 #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)
160 #endif
161 
162 #if _BLD_cmd && defined(__EXPORT__)
163 #undef __MANGLE__
164 #define __MANGLE__ __LINKAGE__ __EXPORT__
165 #endif
166 
167 extern __MANGLE__ int	_cmd_init __PROTO__((int, char**, __V_*, const char*, int));
168 
169 #undef __MANGLE__
170 #define __MANGLE__ __LINKAGE__
171 
172 #endif
173 
174 #endif
175