- added new scriptcontext with devser
This commit is contained in:
77
logreader.c
77
logreader.c
@ -11,6 +11,8 @@
|
||||
#define LOGGER_NAN -999999.
|
||||
#define ONE_YEAR (366*24*3600)
|
||||
#define LLEN 1024
|
||||
/* max. number of dirs in path */
|
||||
#define MAX_DIRS 16
|
||||
|
||||
typedef enum { NUMERIC, TEXT } CompType;
|
||||
|
||||
@ -36,8 +38,8 @@ typedef struct {
|
||||
int omitEqual;
|
||||
} Compressor;
|
||||
|
||||
static char *dir = NULL;
|
||||
static char *dir2 = NULL;
|
||||
static char *dirs[MAX_DIRS] = {NULL};
|
||||
static int ndirs=0;
|
||||
|
||||
static void InitCompressor(Compressor *c, SConnection *pCon, time_t step) {
|
||||
c->pCon = pCon;
|
||||
@ -127,7 +129,7 @@ static void PutFinish(Compressor *c, time_t now) {
|
||||
if (c->tlim != 0) { /* there is data already */
|
||||
c->omitEqual = 0;
|
||||
if (c->type == NUMERIC) {
|
||||
if (now > c->last.t) { /* copy last value to the actual time */
|
||||
if (now > c->last.t + c->period) { /* copy last value to the actual time */
|
||||
if (c->last.y != LOGGER_NAN) {
|
||||
snprintf(value, sizeof value, "%g", c->last.y);
|
||||
PutValue(c, now, value);
|
||||
@ -214,7 +216,7 @@ static int LogReader(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
*/
|
||||
time_t from, to, step, xs, lastt;
|
||||
char *p, *varp;
|
||||
int i, j, iarg, l, iret, loss, np;
|
||||
int i, j, iarg, pathLen, iret, loss, np;
|
||||
int inRange;
|
||||
int yday=0;
|
||||
time_t t, startim;
|
||||
@ -229,8 +231,12 @@ static int LogReader(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
char *opt;
|
||||
int isdst;
|
||||
int overflow;
|
||||
time_t now, now1, now2, nowi;
|
||||
time_t now, nows[MAX_DIRS], nowi;
|
||||
char var[256];
|
||||
char dirPathBuffer[1024];
|
||||
char *dirPath;
|
||||
int idir;
|
||||
char *colon;
|
||||
|
||||
/* argtolower(argc, argv); */
|
||||
if (argc < 4) goto illarg;
|
||||
@ -288,22 +294,39 @@ static int LogReader(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
snprintf(line, sizeof line, "%ld\n", (long)now);
|
||||
SCWrite(pCon, line, eWarning);
|
||||
|
||||
if (dir == NULL) {
|
||||
dir = IFindOption(pSICSOptions, "LoggerDir");
|
||||
if (dir == NULL) {
|
||||
SCWrite(pCon, "ERROR: LoggerDir not found", eError);
|
||||
dirPath = IFindOption(pSICSOptions, "LogReaderPath");
|
||||
if (dirPath == NULL) { /* for compatibility, check */
|
||||
dirs[0] = IFindOption(pSICSOptions, "LoggerDir");
|
||||
if (dirs[0] == NULL) {
|
||||
SCWrite(pCon, "ERROR: LoggerPath not found", eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (dir2 == NULL) {
|
||||
dir2 = IFindOption(pSICSOptions, "LoggerDir2");
|
||||
if (dir2 == NULL) {
|
||||
dir2="";
|
||||
nows[0] = LoggerGetLastLife(NULL);
|
||||
if (dirs[1] == NULL) {
|
||||
dirs[1] = IFindOption(pSICSOptions, "LoggerDir2");
|
||||
nows[1] = LoggerGetLastLife(dirs[1]);
|
||||
}
|
||||
} else {
|
||||
snprintf(dirPathBuffer, sizeof dirPathBuffer, "%s", dirPath);
|
||||
dirPath = dirPathBuffer;
|
||||
for (ndirs = 0; ndirs < MAX_DIRS; ndirs++) {
|
||||
dirs[ndirs] = dirPath;
|
||||
colon = strchr(dirPath, ':');
|
||||
if (colon != NULL) {
|
||||
*colon = '\0';
|
||||
}
|
||||
if (ndirs == 0) {
|
||||
nows[0] = LoggerGetLastLife(NULL);
|
||||
} else {
|
||||
nows[ndirs] = LoggerGetLastLife(dirPath);
|
||||
}
|
||||
if (colon == NULL) {
|
||||
ndirs++;
|
||||
break;
|
||||
}
|
||||
dirPath = colon + 1;
|
||||
}
|
||||
}
|
||||
now1 = LoggerGetLastLife(NULL);
|
||||
if (now1 == 0) now1 = now;
|
||||
now2 = 0;
|
||||
|
||||
loss = 0;
|
||||
overflow = 0;
|
||||
@ -331,21 +354,15 @@ static int LogReader(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
var[j] = '\0';
|
||||
c.type = type0;
|
||||
c.np = np;
|
||||
l = LoggerVarPath(dir, path, sizeof path, var);
|
||||
dr = opendir(path);
|
||||
if (dr) {
|
||||
nowi = now1;
|
||||
closedir(dr);
|
||||
} else {
|
||||
if (now2 == 0) {
|
||||
now2 = LoggerGetLastLife(dir2);
|
||||
if (now2 == 0) now2 = now;
|
||||
}
|
||||
l = LoggerVarPath(dir2, path, sizeof path, var);
|
||||
nowi = now2;
|
||||
tm = *localtime(&from);
|
||||
pathLen = 0;
|
||||
for (idir = 0; idir < ndirs; idir++) {
|
||||
pathLen = LoggerVarPath(dirs[idir], path, sizeof path, var, &tm);
|
||||
dr = opendir(path);
|
||||
if (dr) {
|
||||
nowi = nows[idir];
|
||||
closedir(dr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -361,7 +378,7 @@ static int LogReader(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}
|
||||
if (fil == NULL) {
|
||||
yday = tm.tm_yday;
|
||||
strftime(path + l, sizeof path - l, "%m-%d.log", &tm);
|
||||
strftime(path + pathLen, sizeof path - pathLen, "%m-%d.log", &tm);
|
||||
fil = fopen(path, "r");
|
||||
if (fil != NULL) { /* check if file is from the given year */
|
||||
strftime(stim, sizeof stim, "#%Y-%m-%d", &tm);
|
||||
|
Reference in New Issue
Block a user