- introduced logsetup and savehdb
- moved logger.c and logreader.c for sics/psi/ to sics/ - make comments in status file
This commit is contained in:
91
savehdb.c
Normal file
91
savehdb.c
Normal file
@ -0,0 +1,91 @@
|
||||
#include <stdio.h>
|
||||
#include "dynstring.h"
|
||||
#include "sicshipadaba.h"
|
||||
|
||||
static pDummy creationCommands = NULL;
|
||||
static int saveit = 0;
|
||||
|
||||
static void SaveHdbBranch(pHdb node, FILE *fil) {
|
||||
pHdb child;
|
||||
char prop[16];
|
||||
pDynString dyn;
|
||||
char path[1024];
|
||||
|
||||
if (GetHdbProperty(node, "save", prop, sizeof prop)) {
|
||||
if (strcmp(prop, "me") == 0) {
|
||||
dyn = formatValue(node->value, node);
|
||||
GetHdbPath(node, path, sizeof path);
|
||||
fprintf(fil, "hupdate %s %s\n", path, GetCharArray(dyn));
|
||||
DeleteDynString(dyn);
|
||||
}
|
||||
for (child = node->child; child != NULL; child = child->next) {
|
||||
SaveHdbBranch(child, fil);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int SaveHdbTree(void *object, char *name, FILE *fil) {
|
||||
pHdb node;
|
||||
|
||||
SaveHdbBranch(GetHipadabaRoot(), fil);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int SaveHdbCallback(void *user, void *conn, pHdb node, hdbValue value) {
|
||||
saveit = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int SaveHdbEnable(SConnection *con, SicsInterp *sics,
|
||||
void *data, int argc, char *argv[]) {
|
||||
pHdb node;
|
||||
char prop[16];
|
||||
pHdbCallback cb;
|
||||
|
||||
if (argc < 2) {
|
||||
SCPrintf(con, eError, "ERROR: should be: %s <path>", argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
node = FindHdbNode(NULL, argv[1], con);
|
||||
if (!node) {
|
||||
SCPrintf(con, eError, "ERROR: %s not found", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
cb = MakeHipadabaCallback(SaveHdbCallback, NULL, NULL, -1, NULL);
|
||||
assert(cb);
|
||||
AppendHipadabaCallback(node, HCBUPDATE, cb);
|
||||
|
||||
SetHdbProperty(node, "save", "me");
|
||||
for (node = node->mama; node != NULL; node = node->mama) {
|
||||
if (!GetHdbProperty(node, "save", prop, sizeof prop)) {
|
||||
SetHdbProperty(node, "save", "kids");
|
||||
}
|
||||
}
|
||||
saveit = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SaveHdbTask(void *data) {
|
||||
char *pFile = NULL;
|
||||
|
||||
if (saveit) {
|
||||
saveit = 0;
|
||||
|
||||
assert(pServ->pSics);
|
||||
pFile = IFindOption(pSICSOptions,"statusfile");
|
||||
if (pFile) {
|
||||
WriteSicsStatus(pServ->pSics,pFile,0);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void SaveHdbInit(void) {
|
||||
pDummy hs = NULL;
|
||||
|
||||
hs = CreateDummy("hdb saver");
|
||||
hs->pDescriptor->SaveStatus = SaveHdbTree;
|
||||
AddCommandWithFlag(pServ->pSics, "hsave", SaveHdbEnable, KillDummy, hs, 0);
|
||||
TaskRegister(pServ->pTasker, SaveHdbTask, NULL, NULL, NULL, 0);
|
||||
}
|
Reference in New Issue
Block a user