This is Unofficial EPICS BASE Doxygen Site
iocsh.cpp File Reference
#include <exception>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include "epicsMath.h"
#include "errlog.h"
#include "macLib.h"
#include "epicsStdio.h"
#include "epicsString.h"
#include "epicsStdlib.h"
#include "epicsThread.h"
#include "epicsMutex.h"
#include "envDefs.h"
#include "registry.h"
#include "epicsReadline.h"
#include "cantProceed.h"
#include "iocsh.h"
+ Include dependency graph for iocsh.cpp:

Go to the source code of this file.

Classes

struct  iocshCommand
 
struct  iocshVariable
 
struct  iocshRedirect
 
struct  iocshScope
 
struct  iocshContext
 
class  IocshRegister
 

Macros

#define NREDIRECTS   5
 
#define USAGE()   fprintf(epicsGetStderr(), "Usage: on error [continue | break | halt | wait <delay>]\n")
 

Enumerations

enum  OnError { Continue, Break, Halt }
 

Functions

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

Variables

struct dbBase ** iocshPpdbbase
 

Macro Definition Documentation

#define NREDIRECTS   5

Definition at line 66 of file iocsh.cpp.

#define USAGE ( )    fprintf(epicsGetStderr(), "Usage: on error [continue | break | halt | wait <delay>]\n")

Enumeration Type Documentation

enum OnError
Enumerator
Continue 
Break 
Halt 

Definition at line 514 of file iocsh.cpp.

514  {
515  Continue,
516  Break,
517  Halt
518 } OnError;
Definition: iocsh.cpp:516
Definition: iocsh.cpp:517
OnError
Definition: iocsh.cpp:514

Function Documentation

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
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
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
char * name
Definition: flexdef.h:287
#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
const iocshCmdDef* epicsStdCall iocshFindCommand ( const char *  name)

Definition at line 154 of file iocsh.cpp.

155 {
156  return (iocshCmdDef *) registryFind(iocshCmdID, name);
157 }
char * name
Definition: flexdef.h:287
LIBCOM_API void *epicsStdCall registryFind(void *registryID, const char *name)
Definition: registry.c:67
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
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
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
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
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
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
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

struct dbBase** iocshPpdbbase

Definition at line 41 of file iocsh.cpp.