- Dokumentation updates
- Fixed bad file generated through nuweb - fixed problems in synchronize.c - New file writing scheme implemented - Changes to hkl
This commit is contained in:
99
nxscript.c
99
nxscript.c
@@ -12,13 +12,19 @@
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <tcl.h>
|
||||
#include <math.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include "fortify.h"
|
||||
#include "sics.h"
|
||||
#include "splitter.h"
|
||||
#include "HistMem.h"
|
||||
#include "motor.h"
|
||||
#include "counter.h"
|
||||
#include "sicsvar.h"
|
||||
#include "danu.h"
|
||||
#include "udpquieck.h"
|
||||
#include "nxdict.h"
|
||||
#include "nxscript.h"
|
||||
@@ -28,6 +34,85 @@ typedef struct {
|
||||
NXhandle fileHandle;
|
||||
NXdict dictHandle;
|
||||
} NXScript, *pNXScript;
|
||||
/*------------------------------------------------------------------------*/
|
||||
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 += 8; /* 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,eWarning);
|
||||
} else {
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
/*
|
||||
build the rest of the filename
|
||||
*/
|
||||
strcat(pRes,"/");
|
||||
strcat(pRes,pPref->text);
|
||||
sprintf(pNumText,"%5.5d",iNum);
|
||||
strcat(pRes,pNumText);
|
||||
sprintf(pNumText,"%4.4d",iYear);
|
||||
strcat(pRes,pNumText);
|
||||
strcat(pRes,pEnd->text);
|
||||
|
||||
return pRes;
|
||||
}
|
||||
/*======================== Action =======================================*/
|
||||
static int handleFileOperations(SConnection *pCon, pNXScript self,
|
||||
int argc, char *argv[]){
|
||||
@@ -742,7 +827,7 @@ static void makeLink(SConnection *pCon, SicsInterp *pSics,
|
||||
int NXScriptAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
pNXScript self = (pNXScript)pData;
|
||||
|
||||
char *pFile = NULL;
|
||||
/*
|
||||
preliminary checks
|
||||
*/
|
||||
@@ -756,6 +841,18 @@ int NXScriptAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
}
|
||||
strtolower(argv[1]);
|
||||
|
||||
if(strcmp(argv[1],"makefilename") == 0){
|
||||
pFile = makeFilename(pSics,pCon);
|
||||
if(pFile != NULL){
|
||||
SCWrite(pCon,pFile,eValue);
|
||||
free(pFile);
|
||||
return 1;
|
||||
} else {
|
||||
SCWrite(pCon,"ERROR: failed to create filename",eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(handleFileOperations(pCon,self,argc,argv)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user