Added functions to allow access to what functions and variables the ioc shell has registered.
This commit is contained in:
committed by
Michael Davidsaver
parent
c6910decfc
commit
daad3c6995
+34
-26
@@ -4,7 +4,7 @@
|
||||
* Copyright (c) 2002 The Regents of the University of California, as
|
||||
* Operator of Los Alamos National Laboratory.
|
||||
* EPICS BASE is distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/* iocsh.cpp */
|
||||
/* Author: Marty Kraimer Date: 27APR2000 */
|
||||
@@ -41,17 +41,8 @@ epicsShareDef struct dbBase **iocshPpdbbase;
|
||||
/*
|
||||
* File-local information
|
||||
*/
|
||||
struct iocshCommand {
|
||||
iocshFuncDef const *pFuncDef;
|
||||
iocshCallFunc func;
|
||||
struct iocshCommand *next;
|
||||
};
|
||||
static struct iocshCommand *iocshCommandHead;
|
||||
static char iocshCmdID[] = "iocshCmd";
|
||||
struct iocshVariable {
|
||||
iocshVarDef const *pVarDef;
|
||||
struct iocshVariable *next;
|
||||
};
|
||||
static struct iocshVariable *iocshVariableHead;
|
||||
static char iocshVarID[] = "iocshVar";
|
||||
extern "C" { static void varCallFunc(const iocshArgBuf *); }
|
||||
@@ -146,6 +137,15 @@ void epicsShareAPI iocshRegister (const iocshFuncDef *piocshFuncDef,
|
||||
iocshTableUnlock ();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Retrieves a previously registered function with the given name.
|
||||
*/
|
||||
struct iocshCommand * epicsShareAPI iocshFind(const char *name)
|
||||
{
|
||||
return (iocshCommand *) registryFind(iocshCmdID, name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Register the "var" command and any variable(s)
|
||||
*/
|
||||
@@ -204,10 +204,18 @@ void epicsShareAPI iocshRegisterVariable (const iocshVarDef *piocshVarDef)
|
||||
iocshTableUnlock ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieves a previously registered variable with the given name.
|
||||
*/
|
||||
struct iocshVariable * epicsShareAPI iocshFindVariable(const char *name)
|
||||
{
|
||||
return (iocshVariable *) registryFind(iocshVarID, name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Free storage created by iocshRegister/iocshRegisterVariable
|
||||
*/
|
||||
void epicsShareAPI iocshFree(void)
|
||||
void epicsShareAPI iocshFree(void)
|
||||
{
|
||||
struct iocshCommand *pc;
|
||||
struct iocshVariable *pv;
|
||||
@@ -507,7 +515,7 @@ iocshBody (const char *pathname, const char *commandLine, const char *macros)
|
||||
static const char * pairs[] = {"", "environ", NULL, NULL};
|
||||
MAC_HANDLE *handle;
|
||||
char ** defines = NULL;
|
||||
|
||||
|
||||
iocshInit();
|
||||
|
||||
/*
|
||||
@@ -551,37 +559,37 @@ iocshBody (const char *pathname, const char *commandLine, const char *macros)
|
||||
fprintf(epicsGetStderr(), "Out of memory!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Parse macro definitions, this check occurs before creating the
|
||||
* macro handle to simplify cleanup.
|
||||
*/
|
||||
|
||||
|
||||
if (macros) {
|
||||
if (macParseDefns(NULL, macros, &defines) < 0) {
|
||||
free(redirects);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Check for existing macro context or construct a new one.
|
||||
*/
|
||||
handle = (MAC_HANDLE *) epicsThreadPrivateGet(iocshMacroHandleId);
|
||||
|
||||
|
||||
if (handle == NULL) {
|
||||
if (macCreateHandle(&handle, pairs)) {
|
||||
errlogMessage("iocsh: macCreateHandle failed.");
|
||||
free(redirects);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
epicsThreadPrivateSet(iocshMacroHandleId, (void *) handle);
|
||||
}
|
||||
|
||||
|
||||
macPushScope(handle);
|
||||
macInstallMacros(handle, defines);
|
||||
|
||||
|
||||
/*
|
||||
* Read commands till EOF or exit
|
||||
*/
|
||||
@@ -853,7 +861,7 @@ iocshBody (const char *pathname, const char *commandLine, const char *macros)
|
||||
stopRedirect(filename, lineno, redirects);
|
||||
}
|
||||
macPopScope(handle);
|
||||
|
||||
|
||||
if (handle->level == 0) {
|
||||
macDeleteHandle(handle);
|
||||
epicsThreadPrivateSet(iocshMacroHandleId, NULL);
|
||||
@@ -909,11 +917,11 @@ iocshRun(const char *cmd, const char *macros)
|
||||
* Needed to work around the necessary limitations of macLib and
|
||||
* environment variables. In every other case of macro expansion
|
||||
* it is the expected outcome that defined macros override any
|
||||
* environment variables.
|
||||
* environment variables.
|
||||
*
|
||||
* iocshLoad/Run turn this on its head as it is very likely that
|
||||
* an epicsEnvSet command may be run within the context of their
|
||||
* calls. Thus, it would be expected that the new value would be
|
||||
* iocshLoad/Run turn this on its head as it is very likely that
|
||||
* an epicsEnvSet command may be run within the context of their
|
||||
* calls. Thus, it would be expected that the new value would be
|
||||
* returned in any future macro expansion.
|
||||
*
|
||||
* To do so, the epicsEnvSet command needs to be able to access
|
||||
@@ -924,10 +932,10 @@ void epicsShareAPI
|
||||
iocshEnvClear(const char *name)
|
||||
{
|
||||
MAC_HANDLE *handle;
|
||||
|
||||
|
||||
if (iocshMacroHandleId) {
|
||||
handle = (MAC_HANDLE *) epicsThreadPrivateGet(iocshMacroHandleId);
|
||||
|
||||
|
||||
if (handle != NULL) {
|
||||
macPutValue(handle, name, NULL);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Operator of Los Alamos National Laboratory.
|
||||
* EPICS BASE Versions 3.13.7
|
||||
* and higher are distributed subject to a Software License Agreement found
|
||||
* in file LICENSE that is included with this distribution.
|
||||
* in file LICENSE that is included with this distribution.
|
||||
\*************************************************************************/
|
||||
/* iocsh.h ioc: call registered function*/
|
||||
/* Author: Marty Kraimer Date: 27APR2000 */
|
||||
@@ -59,10 +59,25 @@ typedef struct iocshFuncDef {
|
||||
|
||||
typedef void (*iocshCallFunc)(const iocshArgBuf *argBuf);
|
||||
|
||||
struct iocshCommand {
|
||||
iocshFuncDef const *pFuncDef;
|
||||
iocshCallFunc func;
|
||||
struct iocshCommand *next;
|
||||
};
|
||||
|
||||
struct iocshVariable {
|
||||
iocshVarDef const *pVarDef;
|
||||
struct iocshVariable *next;
|
||||
};
|
||||
|
||||
epicsShareFunc void epicsShareAPI iocshRegister(
|
||||
const iocshFuncDef *piocshFuncDef, iocshCallFunc func);
|
||||
epicsShareFunc void epicsShareAPI iocshRegisterVariable (
|
||||
const iocshVarDef *piocshVarDef);
|
||||
epicsShareFunc struct iocshCommand* epicsShareAPI iocshFind(
|
||||
const char* name);
|
||||
epicsShareFunc struct iocshVariable* epicsShareAPI iocshFindVariable(
|
||||
const char* name);
|
||||
|
||||
/* iocshFree frees storage used by iocshRegister*/
|
||||
/* This should only be called when iocsh is no longer needed*/
|
||||
|
||||
Reference in New Issue
Block a user