Files
sics/sea_extra.c
zolliker 61341b52f4 various improvements
- use dig for resolving host names
- ascon.c: fix terminator parsing
- property callback: change property before callback
- logger.c:default for logger period must be the old value instead of 1
- add frappy type history writing
- increase max. logreader line length
- HIPNONE returns "null" with json protocol
- encode strings properly in formatNameValue
- fix memory leak in json2tcl
- scriptcontext: do not show debug messages when script starts with underscore or when the "send" property is empty
- scriptcontext: remove args for action timestamp
- scriptcontext: "que" function will replace an already queued action, e.g. for 'halt
- introduced updatestatus script
2021-09-16 12:26:18 +02:00

146 lines
4.5 KiB
C

/*
* Extracts from other SICS code and dummy definitions for SEA
*
* Markus Zolliker Jun 2020
*/
#include <math.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <site.h>
#include <sicsvar.h>
#include <danu.h>
pCounterDriver NewMcStasCounter(char *name) {
return NULL;
}
float GetHistPreset(pHistMem self) {return 0;};
int SetHistPreset(pHistMem self, float fVal) {return 0;};
CounterMode GetHistCountMode(pHistMem self) {return 0;};
int SetHistCountMode(pHistMem self, CounterMode eNew) {return 0;};
long GetHistMonitor(pHistMem self, int i, SConnection *pCon) {return 0;};
const float *GetHistTimeBin(pHistMem self, int *iLength) {return 0;};
int GetHistLength(pHistMem self) {return 0;};
int GetHistDim(pHistMem self, int iDim[MAXDIM], int *nDim) {return 0;};
float GetHistCountTime(pHistMem self,SConnection *pCon) {return 0;};
int GetHistogram(pHistMem self, SConnection *pCon,
int i,int iStart, int iEnd, HistInt *lData, int iDataLen) {return 0;};
HistInt *GetHistogramPointer(pHistMem self,SConnection *pCon) {return 0;};
int GetHistogramDirect(pHistMem self, SConnection *pCon,
int i, int iStart, int iEnd,
HistInt *lData, int iDataLen) {return 0;};
void HistDirty(pHistMem self) {};
HistInt *subSample(pHMdata self, char *command, char *error, int errLen) {return 0;};
int Nxinter_SafeInit(Tcl_Interp * pTcl) {return 0;};
int NXcopy_Init(Tcl_Interp * pTcl) {return 0;};
int isNXScriptWriting(void) {return 0;};
/* alternative implementation in order to avoid nexus stuff */
void SNXFormatTime(char *result, int size) {
time_t timeStamp;
time(&timeStamp);
strftime(result, size, "%Y-%m-%d %H:%M:%S", localtime(&timeStamp));
}
/* from nxscript.c: */
/*------------------------------------------------------------------------*/
char *makeFilename(SicsInterp * pSics, SConnection * pCon)
{
pSicsVariable pPath = NULL, pPref = NULL, pEnd = NULL;
char *pRes = NULL;
int iLen, iNum, iYear, thousand;
char pNumText[10], pBueffel[256];
CommandList *pCom = NULL;
DIR *dir = NULL;
/* Try, get all the Variables */
pPath = FindVariable(pSics, "sicsdatapath");
pPref = FindVariable(pSics, "sicsdataprefix");
pCom = FindCommand(pSics, "sicsdatanumber");
pEnd = FindVariable(pSics, "sicsdatapostfix");
if ((!pPath) || (!pPref) || (!pCom) || (!pEnd)) {
SCWrite(pCon,
"ERROR: cannot read variables for automatic data file name creation",
eError);
SCWrite(pCon,
"ERROR: This is a VERY, VERY, VERY serious installation problem",
eError);
SCWrite(pCon, "ERROR: your data will be dumped into emergency.hdf",
eError);
return NULL;
}
/* find length */
iLen = strlen(pPath->text) + 4; /* extra 4 for dir number */
iLen += strlen(pPref->text);
iLen += 10; /* for number + year */
iLen += strlen(pEnd->text);
iLen += 10; /* safety margin */
/* allocate memory */
pRes = (char *) malloc(iLen * sizeof(char));
if (!pRes) {
SCWrite(pCon, "ERROR: no memory in makeFilename", eError);
return NULL;
}
memset(pRes, 0, iLen);
/* increment the data file number */
iNum = IncrementDataNumber(pCom->pData, &iYear);
if (iNum < 0) {
SCWrite(pCon, "ERROR: cannot increment data number!", eError);
SCWrite(pCon, "ERROR: your data will be dumped to emergency.hdf",
eError);
free(pRes);
return NULL;
}
strcpy(pRes, pPath->text);
thousand = (int) floor(iNum / 1000.);
snprintf(pNumText, 9, "%3.3d", thousand);
strcat(pRes, pNumText);
/*
check for existence of directory and create if neccessary
*/
dir = opendir(pRes);
if (dir == NULL) {
mkdir(pRes, S_IRWXU | S_IRGRP | S_IXGRP);
snprintf(pBueffel, 255, "Creating dir: %s", pRes);
SCWrite(pCon, pBueffel, eLog);
} else {
closedir(dir);
}
/*
build the rest of the filename
*/
strcat(pRes, "/");
strcat(pRes, pPref->text);
snprintf(pNumText,sizeof(pNumText)-1, "%4.4d", iYear);
strcat(pRes, pNumText);
strcat(pRes, "n");
snprintf(pNumText,sizeof(pNumText)-1, "%6.6d", iNum);
strcat(pRes, pNumText);
strcat(pRes, pEnd->text);
return pRes;
}
/*---------------------------------------------------------------------*/
void changeExtension(char *filename, char *newExtension)
{
char *pPtr = NULL;
pPtr = strrchr(filename, (int) '.');
assert(pPtr != NULL);
pPtr++;
assert(strlen(pPtr) >= strlen(newExtension));
strcpy(pPtr, newExtension);
}