This is Unofficial EPICS BASE Doxygen Site
iocsh.h File Reference
#include <stdio.h>
#include "compilerDependencies.h"
#include "libComAPI.h"
+ Include dependency graph for iocsh.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  iocshArgBuf
 
struct  iocshVarDef
 
struct  iocshArg
 
struct  iocshFuncDef
 
struct  iocshCmdDef
 

Macros

#define IOCSH_STATIC_FUNC   static EPICS_ALWAYS_INLINE
 
#define IOCSHFUNCDEF_HAS_USAGE
 

Typedefs

typedef union iocshArgBuf iocshArgBuf
 
typedef struct iocshVarDef iocshVarDef
 
typedef struct iocshArg iocshArg
 
typedef struct iocshFuncDef iocshFuncDef
 
typedef void(* iocshCallFunc) (const iocshArgBuf *argBuf)
 
typedef struct iocshCmdDef iocshCmdDef
 

Enumerations

enum  iocshArgType {
  iocshArgInt, iocshArgDouble, iocshArgString, iocshArgPdbbase,
  iocshArgArgv, iocshArgPersistentString
}
 

Functions

LIBCOM_API void epicsStdCall iocshRegister (const iocshFuncDef *piocshFuncDef, iocshCallFunc func)
 
LIBCOM_API void epicsStdCall iocshRegisterVariable (const iocshVarDef *piocshVarDef)
 
LIBCOM_API const iocshCmdDef *epicsStdCall iocshFindCommand (const char *name) EPICS_DEPRECATED
 
LIBCOM_API const iocshVarDef *epicsStdCall iocshFindVariable (const char *name)
 
LIBCOM_API void epicsStdCall iocshFree (void)
 
LIBCOM_API int epicsStdCall iocsh (const char *pathname)
 
LIBCOM_API int epicsStdCall iocshCmd (const char *cmd)
 
LIBCOM_API int epicsStdCall iocshLoad (const char *pathname, const char *macros)
 
LIBCOM_API int epicsStdCall iocshRun (const char *cmd, const char *macros)
 
LIBCOM_API int iocshSetError (int err)
 Signal error from an IOC shell function. More...
 
LIBCOM_API void epicsStdCall iocshEnvClear (const char *name)
 

Variables

LIBCOM_API struct dbBase ** iocshPpdbbase
 

Macro Definition Documentation

#define IOCSH_STATIC_FUNC   static EPICS_ALWAYS_INLINE

Definition at line 23 of file iocsh.h.

#define IOCSHFUNCDEF_HAS_USAGE

Definition at line 67 of file iocsh.h.

Typedef Documentation

typedef struct iocshArg iocshArg
typedef union iocshArgBuf iocshArgBuf
typedef void(* iocshCallFunc) (const iocshArgBuf *argBuf)

Definition at line 69 of file iocsh.h.

typedef struct iocshCmdDef iocshCmdDef
typedef struct iocshFuncDef iocshFuncDef
typedef struct iocshVarDef iocshVarDef

Enumeration Type Documentation

Enumerator
iocshArgInt 
iocshArgDouble 
iocshArgString 
iocshArgPdbbase 
iocshArgArgv 
iocshArgPersistentString 

Definition at line 30 of file iocsh.h.

Function Documentation

LIBCOM_API int epicsStdCall iocsh ( const char *  pathname)

shorthand for

1 iocshLoad(pathname, NULL)

Definition at line 1011 of file iocsh.cpp.

1012 {
1013  return iocshLoad(pathname, NULL);
1014 }
#define NULL
Definition: catime.c:38
int epicsStdCall iocshLoad(const char *pathname, const char *macros)
Definition: iocsh.cpp:1023
LIBCOM_API int epicsStdCall iocshCmd ( const char *  cmd)

shorthand for

1 iocshRun(cmd, NULL)

Definition at line 1017 of file iocsh.cpp.

1018 {
1019  return iocshRun(cmd, NULL);
1020 }
int epicsStdCall iocshRun(const char *cmd, const char *macros)
Definition: iocsh.cpp:1031
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall iocshEnvClear ( const char *  name)

Definition at line 1054 of file iocsh.cpp.

1055 {
1056  iocshContext *context;
1057 
1058  if (iocshContextId) {
1059  context = (iocshContext *) epicsThreadPrivateGet(iocshContextId);
1060 
1061  if (context != NULL) {
1062  macPutValue(context->handle, name, NULL);
1063  }
1064  }
1065 }
MAC_HANDLE * handle
Definition: iocsh.cpp:532
LIBCOM_API void *epicsStdCall epicsThreadPrivateGet(epicsThreadPrivateId)
Definition: osdThread.c:973
#define NULL
Definition: catime.c:38
long epicsStdCall macPutValue(MAC_HANDLE *handle, const char *name, const char *value)
Sets the value of a specific macro.
Definition: macCore.c:233
LIBCOM_API const iocshCmdDef* epicsStdCall iocshFindCommand ( const char *  name)

Definition at line 154 of file iocsh.cpp.

155 {
156  return (iocshCmdDef *) registryFind(iocshCmdID, name);
157 }
LIBCOM_API void *epicsStdCall registryFind(void *registryID, const char *name)
Definition: registry.c:67
LIBCOM_API const iocshVarDef* epicsStdCall iocshFindVariable ( const char *  name)

Definition at line 222 of file iocsh.cpp.

223 {
224  struct iocshVariable *temp = (iocshVariable *) registryFind(iocshVarID, name);
225  return temp ? temp->pVarDef : 0;
226 }
LIBCOM_API void *epicsStdCall registryFind(void *registryID, const char *name)
Definition: registry.c:67
iocshVarDef const * pVarDef
Definition: iocsh.cpp:53
LIBCOM_API void epicsStdCall iocshFree ( void  )

Definition at line 231 of file iocsh.cpp.

232 {
233  struct iocshCommand *pc;
234  struct iocshVariable *pv;
235 
236  iocshTableLock ();
237  for (pc = iocshCommandHead ; pc != NULL ; ) {
238  struct iocshCommand * nc = pc->next;
239  free (pc);
240  pc = nc;
241  }
242  for (pv = iocshVariableHead ; pv != NULL ; ) {
243  struct iocshVariable *nv = pv->next;
244  free (pv);
245  pv = nv;
246  }
247  iocshCommandHead = NULL;
248  iocshVariableHead = NULL;
249  iocshTableUnlock ();
250 }
Definition: tool_lib.h:67
#define NULL
Definition: catime.c:38
struct iocshVariable * next
Definition: iocsh.cpp:54
struct iocshCommand * next
Definition: iocsh.cpp:48
LIBCOM_API int epicsStdCall iocshLoad ( const char *  pathname,
const char *  macros 
)

Read and evaluate IOC shell commands from the given file.

Parameters
pathnamePath to script file
macrosNULL or a comma seperated list of macro definitions. eg. "VAR1=x,VAR2=y"
Returns
0 on success, non-zero on error

Definition at line 1023 of file iocsh.cpp.

1024 {
1025  if (pathname)
1026  epicsEnvSet("IOCSH_STARTUP_SCRIPT", pathname);
1027  return iocshBody(pathname, NULL, macros);
1028 }
#define NULL
Definition: catime.c:38
LIBCOM_API void epicsStdCall epicsEnvSet(const char *name, const char *value)
Set an environment variable&#39;s value.
Definition: osdEnv.c:35
LIBCOM_API void epicsStdCall iocshRegister ( const iocshFuncDef piocshFuncDef,
iocshCallFunc  func 
)

Definition at line 111 of file iocsh.cpp.

113 {
114  struct iocshCommand *l, *p, *n;
115  int i;
116 
117  iocshTableLock ();
118  for (l = NULL, p = iocshCommandHead ; p != NULL ; l = p, p = p->next) {
119  i = strcmp (piocshFuncDef->name, p->def.pFuncDef->name);
120  if (i == 0) {
121  p->def.pFuncDef = piocshFuncDef;
122  p->def.func = func;
123  iocshTableUnlock ();
124  return;
125  }
126  if (i < 0)
127  break;
128  }
129  n = (struct iocshCommand *) callocMustSucceed (1, sizeof *n,
130  "iocshRegister");
131  if (!registryAdd(iocshCmdID, piocshFuncDef->name, (void *)n)) {
132  free (n);
133  iocshTableUnlock ();
134  errlogPrintf ("iocshRegister failed to add %s\n", piocshFuncDef->name);
135  return;
136  }
137  if (l == NULL) {
138  n->next = iocshCommandHead;
139  iocshCommandHead = n;
140  }
141  else {
142  n->next = l->next;
143  l->next = n;
144  }
145  n->def.pFuncDef = piocshFuncDef;
146  n->def.func = func;
147  iocshTableUnlock ();
148 }
iocshCallFunc func
Definition: iocsh.h:73
LIBCOM_API int epicsStdCall registryAdd(void *registryID, const char *name, void *data)
Definition: registry.c:45
iocshFuncDef const * pFuncDef
Definition: iocsh.h:72
int i
Definition: scan.c:967
#define NULL
Definition: catime.c:38
iocshCmdDef def
Definition: iocsh.cpp:47
struct iocshCommand * next
Definition: iocsh.cpp:48
const char * name
Definition: iocsh.h:62
LIBCOM_API void * callocMustSucceed(size_t count, size_t size, const char *msg)
A calloc() that never returns NULL.
Definition: cantProceed.c:22
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
LIBCOM_API void epicsStdCall iocshRegisterVariable ( const iocshVarDef piocshVarDef)

Definition at line 167 of file iocsh.cpp.

168 {
169  struct iocshVariable *l, *p, *n;
170  int i;
171  int found;
172 
173  iocshTableLock ();
174  while ((piocshVarDef != NULL)
175  && (piocshVarDef->name != NULL)
176  && (*piocshVarDef->name != '\0')) {
177  if (iocshVariableHead == NULL)
178  iocshRegister(&varFuncDef,varCallFunc);
179  found = 0;
180  for (l = NULL, p = iocshVariableHead ; p != NULL ; l = p, p = p->next) {
181  i = strcmp (piocshVarDef->name, p->pVarDef->name);
182  if (i == 0) {
183  if (p->pVarDef != piocshVarDef) {
184  errlogPrintf("Warning: iocshRegisterVariable redefining %s.\n",
185  piocshVarDef->name);
186  p->pVarDef = piocshVarDef;
187  }
188  found = 1;
189  break;
190  }
191  if (i < 0)
192  break;
193  }
194  if (!found) {
195  n = (struct iocshVariable *) callocMustSucceed(1, sizeof *n,
196  "iocshRegisterVariable");
197  if (!registryAdd(iocshVarID, piocshVarDef->name, (void *)n)) {
198  free(n);
199  iocshTableUnlock();
200  errlogPrintf("iocshRegisterVariable failed to add %s.\n",
201  piocshVarDef->name);
202  return;
203  }
204  if (l == NULL) {
205  n->next = iocshVariableHead;
206  iocshVariableHead = n;
207  }
208  else {
209  n->next = l->next;
210  l->next = n;
211  }
212  n->pVarDef = piocshVarDef;
213  }
214  piocshVarDef++;
215  }
216  iocshTableUnlock ();
217 }
LIBCOM_API int epicsStdCall registryAdd(void *registryID, const char *name, void *data)
Definition: registry.c:45
int i
Definition: scan.c:967
void epicsStdCall iocshRegister(const iocshFuncDef *piocshFuncDef, iocshCallFunc func)
Definition: iocsh.cpp:111
#define NULL
Definition: catime.c:38
struct iocshVariable * next
Definition: iocsh.cpp:54
const char * name
Definition: iocsh.h:51
LIBCOM_API void * callocMustSucceed(size_t count, size_t size, const char *msg)
A calloc() that never returns NULL.
Definition: cantProceed.c:22
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
iocshVarDef const * pVarDef
Definition: iocsh.cpp:53
LIBCOM_API int epicsStdCall iocshRun ( const char *  cmd,
const char *  macros 
)

Evaluate a single IOC shell command

Parameters
cmdCommand string. eg. "echo \"something or other"" \param macros NULL or a comma seperated list of macro definitions. eg. "VAR1=x,VAR2=y"
Returns
0 on success, non-zero on error

Definition at line 1031 of file iocsh.cpp.

1032 {
1033  if (cmd == NULL)
1034  return 0;
1035  return iocshBody(NULL, cmd, macros);
1036 }
#define NULL
Definition: catime.c:38
LIBCOM_API int iocshSetError ( int  err)

Signal error from an IOC shell function.

Parameters
err0 - success (no op), !=0 - error
Returns
The err argument value.

Definition at line 536 of file iocsh.cpp.

537 {
538  iocshContext *ctxt;
539  if (err && iocshContextId) {
540  ctxt = (iocshContext *) epicsThreadPrivateGet(iocshContextId);
541 
542  if(ctxt && ctxt->scope) ctxt->scope->errored = 1;
543  }
544  return err;
545 }
LIBCOM_API void *epicsStdCall epicsThreadPrivateGet(epicsThreadPrivateId)
Definition: osdThread.c:973
bool errored
Definition: iocsh.cpp:525
iocshScope * scope
Definition: iocsh.cpp:533

Variable Documentation

LIBCOM_API struct dbBase** iocshPpdbbase

Definition at line 41 of file iocsh.cpp.