5 #if defined(MODULE_EMBED) 15 #define _RPMTCL_INTERNAL 27 static int dlopened = 0;
28 static rpmtcl (*rpmtclNew_p) (
char ** av, uint32_t flags);
29 static rpmRC (*rpmtclRunFile_p) (
rpmtcl tcl,
const char * fn,
const char ** resultp);
30 static rpmRC (*rpmtclRun_p) (
rpmtcl tcl,
const char * str,
const char ** resultp);
39 #if defined(MODULE_EMBED) 40 Tcl_DeleteInterp((Tcl_Interp *)tcl->I);
56 if (_rpmtclPool == NULL) {
64 #if defined(MODULE_EMBED) 65 static int rpmtclIOclose(ClientData CD, Tcl_Interp *I)
69 fprintf(stderr,
"==> %s(%p, %p)\n", __FUNCTION__, CD, I);
73 static int rpmtclIOread(ClientData CD,
char *b,
int nb,
int *errnop)
77 fprintf(stderr,
"==> %s(%p, %p[%d], %p)\n", __FUNCTION__, CD, b, nb, errnop);
82 static int rpmtclIOwrite(ClientData CD,
const char *b,
int nb,
int *errnop)
87 fprintf(stderr,
"==> %s(%p, %p[%d], %p)\n", __FUNCTION__, CD, b, nb, errnop);
98 static int rpmtclIOseek(ClientData CD,
long off,
int mode,
int *errnop)
102 fprintf(stderr,
"==> %s(%p, %ld, %d, %p)\n", __FUNCTION__, CD, off, mode, errnop);
107 static Tcl_ChannelType rpmtclIO = {
109 TCL_CHANNEL_VERSION_2,
124 #
if TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION > 4
139 #if defined(WITH_TCL) 140 static void loadModule(
void) {
141 const char librpmtcl[] =
"rpmtcl.so";
144 h = dlopen (librpmtcl, RTLD_NOW|RTLD_GLOBAL);
148 "embedded tcl will not be available\n"),
149 librpmtcl, dlerror());
151 else if(!((rpmtclNew_p = dlsym(h,
"rpmtclNew"))
152 && (rpmtclRunFile_p = dlsym(h,
"rpmtclRunFile"))
153 && (rpmtclRun_p = dlsym(h,
"rpmtclRun")))) {
155 "embedded tcl will not be available\n"),
156 librpmtcl, dlerror());
167 #if defined(WITH_TCL) 168 if (!dlopened) loadModule();
169 if (dlopened)
return rpmtclNew_p(av, flags);
171 rpmtcl tcl = (flags & 0x80000000)
174 #if defined(MODULE_EMBED) 175 static char * _av[] = {
"rpmtcl", NULL };
176 Tcl_Interp * tclI = Tcl_CreateInterp();
180 if (av == NULL) av = _av;
183 Tcl_SetVar(tclI,
"argv", Tcl_Merge(ac-1, (
const char *
const *)av+1), TCL_GLOBAL_ONLY);
184 (void)sprintf(b,
"%d", ac-1);
185 Tcl_SetVar(tclI,
"argc", b, TCL_GLOBAL_ONLY);
186 Tcl_SetVar(tclI,
"argv0", av[0], TCL_GLOBAL_ONLY);
187 Tcl_SetVar(tclI,
"tcl_interactive",
"0", TCL_GLOBAL_ONLY);
190 { Tcl_Channel tclout = Tcl_GetStdChannel(TCL_STDOUT);
191 Tcl_SetChannelOption(tclI, tclout,
"-translation",
"auto");
192 Tcl_StackChannel(tclI, &rpmtclIO, tcl, TCL_WRITABLE, tclout);
193 tcl->tclout = (
void *) tclout;
196 #if !defined(WITH_TCL) 205 #if defined(WITH_TCL) 206 if (dlopened)
return rpmtclRunFile_p(tcl, fn, resultp);
211 fprintf(stderr,
"==> %s(%p,%s)\n", __FUNCTION__, tcl, fn);
213 if (tcl == NULL) tcl =
rpmtclI();
215 #if defined(MODULE_EMBED) 216 if (fn != NULL && Tcl_EvalFile((Tcl_Interp *)tcl->I, fn) == TCL_OK) {
227 #if defined(WITH_TCL) 228 if (dlopened)
return rpmtclRun_p(tcl, str, resultp);
233 fprintf(stderr,
"==> %s(%p,%s)\n", __FUNCTION__, tcl, str);
235 if (tcl == NULL) tcl =
rpmtclI();
237 #if defined(MODULE_EMBED) 238 if (str != NULL && Tcl_Eval((Tcl_Interp *)tcl->I, str) == TCL_OK) {
rpmtcl rpmtclLink(rpmtcl tcl)
Reference a tcl interpreter instance.
static void rpmtclFini(void *_tcl)
rpmiob rpmiobFree(rpmiob iob)
Destroy a I/O buffer instance.
static void rpmlog(int code, const char *fmt,...)
rpmiob rpmiobAppend(rpmiob iob, const char *s, size_t nl)
Append string to I/O buffer.
Yet Another syslog(3) API clone.
rpmRC rpmtclRunFile(rpmtcl tcl, const char *fn, const char **resultp)
Execute tcl from a file.
static rpmtcl rpmtclI(void)
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
int argvCount(const ARGV_t argv)
Return no.
rpmiob rpmiobNew(size_t len)
Create an I/O buffer.
enum rpmRC_e rpmRC
RPM return codes.
char * rpmiobStr(rpmiob iob)
Return I/O buffer (as string).
static rpmtcl rpmtclGetPool(rpmioPool pool)
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
rpmtcl rpmtclNew(char **av, uint32_t flags)
Create and load a tcl interpreter.
rpmRC rpmtclRun(rpmtcl tcl, const char *str, const char **resultp)
Execute tcl string.