- Fixes to make SL6 work
- New NeXus libraries - Added new raw binary transfer mode for mass data - Added a check script option to configurable virtual motor SKIPPED: psi/dumprot.c psi/make_gen psi/psi.c psi/rebin.c psi/sanslirebin.c
This commit is contained in:
113
nxstack.c
113
nxstack.c
@@ -18,7 +18,10 @@
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
For further information, see <http://www.neutron.anl.gov/NeXus/>
|
||||
For further information, see <http://www.nexusformat.org>
|
||||
|
||||
Added code to support the path stack for NXgetpath,
|
||||
Mark Koennecke, October 2009
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -33,88 +36,110 @@ typedef struct {
|
||||
pNexusFunction pDriver;
|
||||
NXlink closeID;
|
||||
char filename[1024];
|
||||
} fileStackEntry;
|
||||
}fileStackEntry;
|
||||
|
||||
|
||||
typedef struct __fileStack {
|
||||
int fileStackPointer;
|
||||
fileStackEntry fileStack[MAXEXTERNALDEPTH];
|
||||
} fileStack;
|
||||
int pathPointer;
|
||||
char pathStack[NXMAXSTACK][NX_MAXNAMELEN];
|
||||
}fileStack;
|
||||
/*---------------------------------------------------------------------*/
|
||||
pFileStack makeFileStack()
|
||||
{
|
||||
pFileStack makeFileStack(){
|
||||
pFileStack pNew = NULL;
|
||||
|
||||
pNew = malloc(sizeof(fileStack));
|
||||
if (pNew == NULL) {
|
||||
|
||||
pNew = (pFileStack)malloc(sizeof(fileStack));
|
||||
if(pNew == NULL){
|
||||
return NULL;
|
||||
}
|
||||
memset(pNew, 0, sizeof(fileStack));
|
||||
memset(pNew,0,sizeof(fileStack));
|
||||
pNew->fileStackPointer = -1;
|
||||
pNew->pathPointer = -1;
|
||||
return pNew;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
void killFileStack(pFileStack self)
|
||||
{
|
||||
if (self != NULL) {
|
||||
void killFileStack(pFileStack self){
|
||||
if(self != NULL){
|
||||
free(self);
|
||||
}
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
int getFileStackSize(){
|
||||
return sizeof(fileStack);
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
void pushFileStack(pFileStack self, pNexusFunction pDriv, char *file)
|
||||
{
|
||||
int length;
|
||||
void pushFileStack(pFileStack self, pNexusFunction pDriv, char *file){
|
||||
size_t length;
|
||||
|
||||
self->fileStackPointer++;
|
||||
self->fileStack[self->fileStackPointer].pDriver = pDriv;
|
||||
memset(&self->fileStack[self->fileStackPointer].closeID, 0,
|
||||
sizeof(NXlink));
|
||||
memset(&self->fileStack[self->fileStackPointer].closeID,0,sizeof(NXlink));
|
||||
length = strlen(file);
|
||||
if (length >= 1024) {
|
||||
if(length >= 1024){
|
||||
length = 1023;
|
||||
}
|
||||
memcpy(&self->fileStack[self->fileStackPointer].filename, file, length);
|
||||
memcpy(&self->fileStack[self->fileStackPointer].filename,file,length);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
void popFileStack(pFileStack self)
|
||||
{
|
||||
void popFileStack(pFileStack self){
|
||||
self->fileStackPointer--;
|
||||
if (self->fileStackPointer < -1) {
|
||||
if(self->fileStackPointer < -1){
|
||||
self->fileStackPointer = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
pNexusFunction peekFileOnStack(pFileStack self)
|
||||
{
|
||||
pNexusFunction peekFileOnStack(pFileStack self){
|
||||
return self->fileStack[self->fileStackPointer].pDriver;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
char *peekFilenameOnStack(pFileStack self)
|
||||
{
|
||||
char *peekFilenameOnStack(pFileStack self){
|
||||
return self->fileStack[self->fileStackPointer].filename;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
void peekIDOnStack(pFileStack self, NXlink * id)
|
||||
{
|
||||
memcpy(id, &self->fileStack[self->fileStackPointer].closeID,
|
||||
sizeof(NXlink));
|
||||
void peekIDOnStack(pFileStack self, NXlink *id){
|
||||
memcpy(id, &self->fileStack[self->fileStackPointer].closeID, sizeof(NXlink));
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
void setCloseID(pFileStack self, NXlink id)
|
||||
{
|
||||
memcpy(&self->fileStack[self->fileStackPointer].closeID, &id,
|
||||
sizeof(NXlink));
|
||||
void setCloseID(pFileStack self, NXlink id){
|
||||
memcpy(&self->fileStack[self->fileStackPointer].closeID, &id, sizeof(NXlink));
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
int fileStackDepth(pFileStack self)
|
||||
{
|
||||
int fileStackDepth(pFileStack self){
|
||||
return self->fileStackPointer;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
void pushPath(pFileStack self, const char *name){
|
||||
self->pathPointer++;
|
||||
strncpy(self->pathStack[self->pathPointer],name,NX_MAXNAMELEN-1);
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void popPath(pFileStack self){
|
||||
self->pathPointer--;
|
||||
if(self->pathPointer < -1){
|
||||
self->pathPointer = -1;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int buildPath(pFileStack self, char *path, int pathlen){
|
||||
int i;
|
||||
size_t totalPathLength;
|
||||
char *totalPath;
|
||||
|
||||
for(i = 0, totalPathLength = 5; i <= self->pathPointer; i++){
|
||||
totalPathLength += strlen(self->pathStack[i]) + 1;
|
||||
}
|
||||
totalPath = (char*)malloc(totalPathLength*sizeof(char));
|
||||
if(totalPath == NULL){
|
||||
return 0;
|
||||
}
|
||||
memset(totalPath,0,totalPathLength*sizeof(char));
|
||||
for(i = 0; i <= self->pathPointer; i++){
|
||||
strcat(totalPath,"/");
|
||||
strcat(totalPath,self->pathStack[i]);
|
||||
}
|
||||
|
||||
strncpy(path,totalPath,pathlen-1);
|
||||
free(totalPath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user