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