1/*********************************************************************** 2* * 3* This software is part of the ast package * 4* Copyright (c) 1985-2012 AT&T Intellectual Property * 5* and is licensed under the * 6* Eclipse Public License, Version 1.0 * 7* by AT&T Intellectual Property * 8* * 9* A copy of the License is available at * 10* http://www.eclipse.org/org/documents/epl-v10.html * 11* (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12* * 13* Information and Software Systems Research * 14* AT&T Research * 15* Florham Park NJ * 16* * 17* Glenn Fowler <gsf@research.att.com> * 18* David Korn <dgk@research.att.com> * 19* Phong Vo <kpv@research.att.com> * 20* * 21***********************************************************************/ 22#pragma prototyped 23 24/* 25 * ksh builtin command api 26 */ 27 28#ifndef _SHCMD_H 29#define _SHCMD_H 1 30 31#ifndef AST_PLUGIN_VERSION 32#define AST_PLUGIN_VERSION(v) (v) 33#endif 34#define SH_PLUGIN_VERSION AST_PLUGIN_VERSION(20111111L) 35 36#if __STDC__ 37#define SHLIB(m) unsigned long plugin_version(void) { return SH_PLUGIN_VERSION; } 38#else 39#define SHLIB(m) unsigned long plugin_version() { return SH_PLUGIN_VERSION; } 40#endif 41 42#ifndef SH_VERSION 43# define Shell_t void 44#endif 45#ifndef NV_DEFAULT 46# define Namval_t void 47#endif 48 49#undef Shbltin_t 50struct Shbltin_s; 51typedef struct Shbltin_s Shbltin_t; 52 53#ifdef _SHTABLE_H /* pre-ksh93u+ -- obsolete */ 54typedef int (*Shbltin_f)(int, char**, void*); 55#else 56typedef int (*Shbltin_f)(int, char**, Shbltin_t*); 57#endif /* _SHTABLE_H */ 58 59struct Shbltin_s 60{ 61 Shell_t* shp; 62 void* ptr; 63 int version; 64 int (*shrun)(int, char**); 65 int (*shtrap)(const char*, int); 66 void (*shexit)(int); 67 Namval_t* (*shbltin)(const char*, Shbltin_f, void*); 68 unsigned char notify; 69 unsigned char sigset; 70 unsigned char nosfio; 71 Namval_t* bnode; 72 Namval_t* vnode; 73 char* data; 74 int flags; 75 char* (*shgetenv)(const char*); 76 char* (*shsetenv)(const char*); 77 int invariant; 78}; 79 80#if defined(SH_VERSION) || defined(_SH_PRIVATE) 81# undef Shell_t 82# undef Namval_t 83#else 84# define sh_context(c) ((Shbltin_t*)(c)) 85# define sh_run(c, ac, av) ((c)?(*sh_context(c)->shrun)(ac,av):-1) 86# define sh_system(c,str) ((c)?(*sh_context(c)->shtrap)(str,0):system(str)) 87# define sh_exit(c,n) ((c)?(*sh_context(c)->shexit)(n):exit(n)) 88# define sh_checksig(c) ((c) && sh_context(c)->sigset) 89# define sh_builtin(c,n,f,p) ((c)?(*sh_context(c)->shbltin)(n,(Shbltin_f)(f),sh_context(p)):0) 90# if defined(SFIO_VERSION) || defined(_AST_H) 91# define LIB_INIT(c) 92# else 93# define LIB_INIT(c) ((c) && (sh_context(c)->nosfio = 1)) 94# endif 95# ifndef _CMD_H 96# ifndef ERROR_NOTIFY 97# define ERROR_NOTIFY 1 98# endif 99# define cmdinit(ac,av,c,cat,flg) do { if((ac)<=0) return(0); \ 100 (sh_context(c)->notify = ((flg)&ERROR_NOTIFY)?1:0);} while(0) 101# endif 102#endif 103 104#if _BLD_ast && defined(__EXPORT__) 105#define extern __EXPORT__ 106#endif 107 108extern int astintercept(Shbltin_t*, int); 109 110#undef extern 111 112#endif 113