1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1992-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
20 ***********************************************************************/
25 * builtin cmd definitions
36 #define cmdinit _cmd_init
38 #define ERROR_CALLBACK ERROR_SET
40 #if _BLD_cmd && defined(__EXPORT__)
41 #define extern __EXPORT__
48 #if defined(CMD_BUILTIN) && !defined(CMD_STANDALONE)
49 #define CMD_STANDALONE CMD_BUILTIN
54 #define CMD_CONTEXT(c) ((Shbltin_t*)0)
62 extern int CMD_STANDALONE(int, char**, void*);
69 * command initialization
73 cmdinit(int argc
, register char** argv
, void* context
, const char* catalog
, int flags
)
78 if (cp
= strrchr(argv
[0], '/'))
82 if (pp
= strrchr(cp
, '_'))
85 if (!error_info
.catalog
)
86 error_info
.catalog
= (char*)catalog
;
89 error_info
.flags
|= flags
& ~(ERROR_CALLBACK
|ERROR_NOTIFY
);
96 main(int argc
, char** argv
)
105 if (s
= strrchr(argv
[0], '/'))
107 else if (!(s
= argv
[0]))
109 if ((t
= strrchr(s
, '_')) && *++t
)
114 strncpy(buf
+ 3, s
, sizeof(buf
) - 4);
115 buf
[sizeof(buf
) - 1] = 0;
116 if (t
= strchr(buf
, '.'))
120 if (dll
= dlopen(NiL
, RTLD_LAZY
))
122 if (fun
= (Shbltin_f
)dlsym(dll
, buf
+ 1))
124 if (fun
= (Shbltin_f
)dlsym(dll
, buf
))
127 if (dll
= dllplug(NiL
, "cmd", NiL
, RTLD_LAZY
, NiL
, 0))
129 if (fun
= (Shbltin_f
)dlsym(dll
, buf
+ 1))
131 if (fun
= (Shbltin_f
)dlsym(dll
, buf
))
136 return (*fun
)(argc
, argv
, NiL
);
138 return CMD_STANDALONE(argc
, argv
, NiL
);
146 #define CMD_CONTEXT(p) ((Shbltin_t*)(p))
147 #define cmdinit(a,b,c,d,e) do{if(_cmd_init(a,b,c,d,e))return -1;}while(0)
149 #define CMD_CONTEXT(p) (((p)&&((Shbltin_t*)(p))->version>=20071012&&((Shbltin_t*)(p))->version<20350101)?((Shbltin_t*)(p)):0)
150 #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)
153 #if _BLD_cmd && defined(__EXPORT__)
154 #define extern extern __EXPORT__
157 extern int _cmd_init(int, char**, void*, const char*, int);