- Fixed a bug in napi5.c
This commit is contained in:
63
histmem.c
63
histmem.c
@ -388,6 +388,7 @@
|
||||
{
|
||||
pHistMem pNew = NULL;
|
||||
pSite site = NULL;
|
||||
pStringDict pOption;
|
||||
|
||||
/* make memory */
|
||||
pNew = (pHistMem)malloc(sizeof(HistMem));
|
||||
@ -432,24 +433,24 @@
|
||||
pNew->pCountInt->Continue = HistContinue;
|
||||
|
||||
/* initialise options dictionary */
|
||||
pNew->pOption = CreateStringDict();
|
||||
if(!pNew->pOption)
|
||||
pOption = CreateStringDict();
|
||||
if(!pOption)
|
||||
{
|
||||
DeleteDescriptor(pNew->pDes);
|
||||
free(pNew);
|
||||
return NULL;
|
||||
}
|
||||
StringDictAddPair(pNew->pOption,"driver",driver);
|
||||
StringDictAddPair(pNew->pOption,"update","0");
|
||||
StringDictAddPair(pOption,"driver",driver);
|
||||
StringDictAddPair(pOption,"update","0");
|
||||
|
||||
/* initialise driver */
|
||||
if(strcmp(driver,"sim") == 0)
|
||||
{
|
||||
pNew->pDriv = CreateSIMHM(pNew->pOption);
|
||||
pNew->pDriv = CreateSIMHM(pOption);
|
||||
}
|
||||
else if(strcmp(driver,"mcstas") == 0)
|
||||
{
|
||||
pNew->pDriv = NewMcStasHM(pNew->pOption);
|
||||
pNew->pDriv = NewMcStasHM(pOption);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -457,20 +458,21 @@
|
||||
if(site != NULL)
|
||||
{
|
||||
pNew->pDriv = site->CreateHistogramMemoryDriver(driver,
|
||||
pNew->pOption);
|
||||
pOption);
|
||||
}
|
||||
}
|
||||
|
||||
if(pNew->pDriv == NULL)
|
||||
{
|
||||
DeleteDescriptor(pNew->pDes);
|
||||
DeleteStringDict(pNew->pOption);
|
||||
DeleteStringDict(pOption);
|
||||
free(pNew);
|
||||
return NULL;
|
||||
}
|
||||
pNew->iAccess = usUser;
|
||||
pNew->iExponent = 0;
|
||||
pNew->iInit = 0;
|
||||
pNew->pDriv->pOption = pOption;
|
||||
|
||||
return pNew;
|
||||
}
|
||||
@ -500,10 +502,6 @@
|
||||
{
|
||||
DeleteCallBackInterface(self->pCall);
|
||||
}
|
||||
if(self->pOption)
|
||||
{
|
||||
DeleteStringDict(self->pOption);
|
||||
}
|
||||
free(self);
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
@ -533,7 +531,7 @@
|
||||
return 0;
|
||||
}
|
||||
|
||||
StringDictAddPair(pNew->pOption,"name",argv[1]);
|
||||
StringDictAddPair(pNew->pDriv->pOption,"name",argv[1]);
|
||||
|
||||
/* install HM as command */
|
||||
iRet = AddCommand(pSics,argv[1],HistAction,DeleteHistMemory,(void *)pNew);
|
||||
@ -551,7 +549,7 @@
|
||||
{
|
||||
assert(self);
|
||||
strtolower(name);
|
||||
return StringDictGet(self->pOption,name, result,iLen);
|
||||
return StringDictGet(self->pDriv->pOption,name, result,iLen);
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int HistSetOption(pHistMem self, char *name, char *value)
|
||||
@ -561,10 +559,10 @@
|
||||
assert(self);
|
||||
self->iInit = 1;
|
||||
strtolower(name);
|
||||
status = StringDictUpdate(self->pOption,name, value);
|
||||
status = StringDictUpdate(self->pDriv->pOption,name, value);
|
||||
if(status == 0)
|
||||
{
|
||||
return StringDictAddPair(self->pOption,name, value);
|
||||
return StringDictAddPair(self->pDriv->pOption,name, value);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -577,13 +575,13 @@
|
||||
assert(self);
|
||||
assert(pCon);
|
||||
|
||||
iRet = HistDriverConfig(self->pDriv,self->pOption,pCon);
|
||||
iRet = HistDriverConfig(self->pDriv,self->pDriv->pOption,pCon);
|
||||
if(!iRet)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: failed to configure histogram memory",eError);
|
||||
return 0;
|
||||
}
|
||||
iRet = self->pDriv->Configure(self->pDriv,pCon, self->pOption,pSics);
|
||||
iRet = self->pDriv->Configure(self->pDriv,pCon, self->pDriv->pOption,pSics);
|
||||
if(!iRet)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: failed to configure histogram memory",eError);
|
||||
@ -974,17 +972,17 @@ static int checkHMEnd(pHistMem self, char *text){
|
||||
memset(pValue, 0, sizeof(pValue));
|
||||
memset(name, 0, sizeof(name));
|
||||
|
||||
iRet = StringDictGet(self->pOption,"name",name,19);
|
||||
iRet = StringDictGet(self->pDriv->pOption,"name",name,19);
|
||||
if(0==iRet) {
|
||||
strcpy(name,"*");
|
||||
}
|
||||
iRet = StringDictGet(self->pOption,"driver",pValue,sizeof(pValue)-1);
|
||||
iRet = StringDictGet(self->pDriv->pOption,"driver",pValue,sizeof(pValue)-1);
|
||||
if(0<iRet) {
|
||||
sprintf(pBuffer,"%s.driver = %s",name,pValue);
|
||||
SCWrite(pCon,pBuffer,eStatus);
|
||||
}
|
||||
|
||||
iRet = StringDictGetAsNumber(self->pOption,"update",&fVal);
|
||||
iRet = StringDictGetAsNumber(self->pDriv->pOption,"update",&fVal);
|
||||
if(0<iRet) {
|
||||
sprintf(pBuffer,"%s.update = %d",name,(int)rint(fVal));
|
||||
} else {
|
||||
@ -992,7 +990,7 @@ static int checkHMEnd(pHistMem self, char *text){
|
||||
}
|
||||
SCWrite(pCon,pBuffer,eStatus);
|
||||
|
||||
iRet = StringDictGetAsNumber(self->pOption,"rank",&fVal);
|
||||
iRet = StringDictGetAsNumber(self->pDriv->pOption,"rank",&fVal);
|
||||
if(0<iRet) {
|
||||
iRank = (int)rint(fVal);
|
||||
sprintf(pBuffer,"%s.rank = %d",name,iRank);
|
||||
@ -1002,14 +1000,14 @@ static int checkHMEnd(pHistMem self, char *text){
|
||||
}
|
||||
for(i=0; i<iRank; i++){
|
||||
sprintf(pValue,"dim%1.1d",i);
|
||||
iRet = StringDictGetAsNumber(self->pOption,pValue,&fVal);
|
||||
iRet = StringDictGetAsNumber(self->pDriv->pOption,pValue,&fVal);
|
||||
if(0<iRet){
|
||||
sprintf(pBuffer,"%s.dim%1.1d = %d",name,i,(int)rint(fVal));
|
||||
SCWrite(pCon,pBuffer,eStatus);
|
||||
}
|
||||
}
|
||||
|
||||
pKey = StringDictGetNext(self->pOption,pValue,sizeof(pValue)-1);
|
||||
pKey = StringDictGetNext(self->pDriv->pOption,pValue,sizeof(pValue)-1);
|
||||
while(pKey != NULL) {
|
||||
iDiscard=0;
|
||||
if(0==strcmp("name",pKey)) iDiscard=1;
|
||||
@ -1021,7 +1019,7 @@ static int checkHMEnd(pHistMem self, char *text){
|
||||
snprintf(pBuffer,511,"%s.%s = %s",name,pKey,pValue);
|
||||
SCWrite(pCon,pBuffer,eStatus);
|
||||
}
|
||||
pKey = StringDictGetNext(self->pOption,pValue,sizeof(pValue)-1);
|
||||
pKey = StringDictGetNext(self->pDriv->pOption,pValue,sizeof(pValue)-1);
|
||||
}
|
||||
|
||||
/* Display Count Mode */
|
||||
@ -1259,6 +1257,16 @@ static int checkHMEnd(pHistMem self, char *text){
|
||||
HMListOption(self,pCon);
|
||||
return 1;
|
||||
}
|
||||
/* stop */
|
||||
else if(strcmp(argv[1],"stop") == 0)
|
||||
{ if(!SCMatchRights(pCon,usUser))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
self->pDriv->Halt(self->pDriv);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/* normal counting*/
|
||||
else if(strcmp(argv[1],"count") == 0)
|
||||
{
|
||||
@ -1693,11 +1701,6 @@ static int checkHMEnd(pHistMem self, char *text){
|
||||
}
|
||||
}
|
||||
lVal = HistSum(self,pCon,iaStart,iaEnd);
|
||||
if(lVal < 0)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: summing failed",eError);
|
||||
return 0;
|
||||
}
|
||||
sprintf(pBueffel,"%s.sum = %ld",argv[0],lVal);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user