Add FileEvalGlob command for multipath config files
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
-----------------------------------------------------------------------*/
|
-----------------------------------------------------------------------*/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <glob.h>
|
||||||
#include <fortify.h>
|
#include <fortify.h>
|
||||||
#include <sics.h>
|
#include <sics.h>
|
||||||
#include <motor.h>
|
#include <motor.h>
|
||||||
@@ -24,6 +25,8 @@
|
|||||||
|
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "sicslist.h"
|
#include "sicslist.h"
|
||||||
|
#include "macro.h"
|
||||||
|
#include "status.h"
|
||||||
/* site-specific driver header files */
|
/* site-specific driver header files */
|
||||||
#include "motor_dmc2280.h"
|
#include "motor_dmc2280.h"
|
||||||
#include "motor_asim.h"
|
#include "motor_asim.h"
|
||||||
@@ -102,6 +105,66 @@ int SICS_Revision(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, c
|
|||||||
return OKOK;
|
return OKOK;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int MacroFileEvalGlob(SConnection * pCon, SicsInterp * pInter, void *pData,
|
||||||
|
int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int rv;
|
||||||
|
int flags;
|
||||||
|
Status eOld;
|
||||||
|
glob_t globbuf;
|
||||||
|
char *args[3];
|
||||||
|
|
||||||
|
assert(pCon);
|
||||||
|
assert(pInter);
|
||||||
|
|
||||||
|
/* check authorisation: only users permitted here */
|
||||||
|
if (!SCMatchRights(pCon, usUser)) {
|
||||||
|
SCWrite(pCon, "ERROR: Insufficient Privilege to do FileEval", eError);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check enough arguments */
|
||||||
|
if (argc < 2) {
|
||||||
|
SCWrite(pCon, "ERROR: No filename specified ", eError);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* handle status first */
|
||||||
|
eOld = GetStatus();
|
||||||
|
SetStatus(eBatch);
|
||||||
|
|
||||||
|
flags = GLOB_NOSORT;
|
||||||
|
#if defined(GLOB_BRACE)
|
||||||
|
flags |= GLOB_BRACE;
|
||||||
|
#endif
|
||||||
|
#if defined(GLOB_TILDE_CHECK)
|
||||||
|
flags |= GLOB_TILDE_CHECK;
|
||||||
|
#endif
|
||||||
|
memset(&globbuf, 0, sizeof(globbuf));
|
||||||
|
for (i = 1; i < argc; ++i) {
|
||||||
|
glob(argv[i], flags, NULL, &globbuf);
|
||||||
|
flags |= GLOB_APPEND;
|
||||||
|
}
|
||||||
|
args[0] = "fileeval";
|
||||||
|
args[2] = NULL;
|
||||||
|
rv = 1;
|
||||||
|
for (i = 0; i < (int) globbuf.gl_pathc; ++i) {
|
||||||
|
args[1] = globbuf.gl_pathv[i];
|
||||||
|
SCPrintf(pCon, eStatus, "fileeval %s", args[1]);
|
||||||
|
if (0 == MacroFileEval(pCon, pInter, pData, 2, args))
|
||||||
|
rv = 0;
|
||||||
|
}
|
||||||
|
if (0 == globbuf.gl_pathc) {
|
||||||
|
SCWrite(pCon, "ERROR: No file(s) found in FileEvalGlob", eError);
|
||||||
|
rv = 0;
|
||||||
|
}
|
||||||
|
globfree(&globbuf);
|
||||||
|
SetStatus(eOld);
|
||||||
|
if (1 == rv)
|
||||||
|
SCSendOK(pCon);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
void SiteInit(void) {
|
void SiteInit(void) {
|
||||||
int NetWatchInit(void);
|
int NetWatchInit(void);
|
||||||
NetWatchInit();
|
NetWatchInit();
|
||||||
@@ -151,6 +214,7 @@ static void AddCommands(SicsInterp *pInter)
|
|||||||
AddCommand(pInter,"SICS_Version",SICS_Version,NULL,NULL);
|
AddCommand(pInter,"SICS_Version",SICS_Version,NULL,NULL);
|
||||||
AddCommand(pInter,"SICS_Revision",SICS_Revision,NULL,NULL);
|
AddCommand(pInter,"SICS_Revision",SICS_Revision,NULL,NULL);
|
||||||
AddCommand(pInter, "sicslist", SicsList, NULL, NULL);
|
AddCommand(pInter, "sicslist", SicsList, NULL, NULL);
|
||||||
|
AddCommand(pInter, "FileEvalGlob", MacroFileEvalGlob, NULL, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tcl 8.5 has implemented the clock command in tcl rather then C.
|
* Tcl 8.5 has implemented the clock command in tcl rather then C.
|
||||||
|
|||||||
Reference in New Issue
Block a user