📄 sds_assem.c
字号:
/* $Header: /cvsroot/sourcenav/src/snavigator/demo/c++_demo/sds/sds_assem.c,v 1.1.1.1 2002/04/18 23:35:30 mdejong Exp $ *//************************************************************************** * ****** ISTK Release 1.2 ***** * * * * * * This code has been produced by numerous authors at the CERN centre for * * high energy physics, Geneve, Switzerland, at the SSC laboratory in * * Dallas, Texas, USA and at the Lawrence Berekeley Laboratory in * * California, USA. * * The latter two institutions perform work under US Government contract. * * The intent of the work is to provide useful code for people who need * * it, with an emphasis on free and collaborative exchange of ideas, * * techniques and implementations. * * Please read the disclaimer and copyright notices contained in the ISTK * * distribution and in distributed applications. * * * **************************************************************************//* Reference release Aug 10 1991 - C G Saltmarsh *//* Has the basics used at CDG & SSC 1988-1991, plus vxworks support*/#include <string.h>#include <stdlib.h>#include <fcntl.h>#ifndef VXWORKS#include <values.h>#else#define BITSPERBYTE 8#define BITS(type) (BITSPERBYTE * (int)sizeof(type))#endif#ifndef vms#include <unistd.h>#ifndef VXWORKS#include <memory.h>#endif#endif#if defined(vms)#include "sdsgen.h"#include "sds_externs.h"#else#include "Sds/sdsgen.h"#include "Sds/sds_externs.h"#endif#ifdef MEMMAP#include <sys/mman.h>#endif#define SDS_INC_DIREC 32#define SDS_INC_SUBS 32#define SDS_INC_HEAP 256#define SDS_FIXED -1extern char *strncpy();#if !defined(hpux) && !defined(VXWORKS) && !defined(mips)#if !defined(vms)#if ! defined (__GCC_2__)#if defined(__GNUC__)#if __GNUC__ != 2extern char *memcpy();#endif#endif#endif#endif#endif/* Forward declarations */#ifndef VXWORKSoff_t lseek();#endifextern void sds_delete_scp(struct sds_control_p *);extern sds_handle next_sds();void sds_fixbits(struct type_list *);sds_handle sds_prepads(struct direc *, sds_handle);char **sds_saverestore(sds_handle, struct direc *, int);sds_handle sds_type_duplicate_def(sds_handle, sds_handle, sds_code);sds_handle sds_start_heap(sds_handle);sds_handle sds_inc_heap(sds_handle, int);long tlist_len(struct type_list *);struct direc * sds_inc_direc_size(sds_handle);sds_handle sds_pname(sds_handle,sds_code,char *);/*********************************************************************/sds_handlesds_dup(old_sds,name)sds_handle old_sds;char *name;/*********************************************************************/{ sds_handle new_sds; sds_code object,typecode; struct direc *dptr,*old_dptr; struct sds_control_p *scp; if (!sds_initialised()) { fprintf(stderr,"Sds must be initialised with sds_init()"); exit(1); } if ((old_dptr = sds_direc(old_sds)) == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Dataset to be duplicated"); return 0L; } if ((new_sds = good_sds(name))) { sds_push_error(SDS_DEJA_LA,SDS_WARNING,"Trying to make duplicate"); return 0L; } if ((new_sds = sds_new(name)) == 0) { sds_push_error(SDS_NO_SPC,SDS_WARNING,"Trying to make duplicate"); return 0L; } scp = sds_control(new_sds); scp->dup_size = (sds_handle *)sds_malloc(old_dptr[0].nelems * sizeof(long)); for (object = 1;object < old_dptr[0].nelems; object++) { scp->dup_size[object] = old_dptr[object].nelems; sds_cleanup(old_sds); if ((typecode = old_dptr[object].elemcod) & SDS_INDLIST) typecode = sds_duplicate_def(old_sds,new_sds,object); sds_declare_structure(new_sds, sds_obind2ptr(old_sds,object), sds_obind2name(old_sds,object), old_dptr[object].nelems, typecode); dptr = sds_direc(new_sds); dptr[object].structype = old_dptr[object].structype; if (old_dptr[object].illoca == SDS_DISJOINT_OBJECT) dptr[object].illoca = SDS_DISJOINT_OBJECT; } return new_sds;}/*********************************************************************/sds_handlesds_duplicate_def(source_sds,new_sds,object)sds_handle source_sds,new_sds;sds_code object;/*********************************************************************/{ struct direc *dptr = sds_direc(source_sds); sds_code typecode = dptr[object].elemcod; return sds_type_duplicate_def(source_sds,new_sds,typecode);}/*********************************************************************/voidsds_put_name(sds,object,name)sds_handle sds;sds_code object;char *name;/*********************************************************************/{ char *oname = sds_obind2name(sds,object); int len = strlen(oname); strncpy(oname,name,len);}/*********************************************************************/sds_handlesds_pname(sds,object,name)sds_handle sds;sds_code object;char *name;/*********************************************************************/{ struct direc* dptr = sds_direc(sds); dptr[object].obj_name = sds_add_to_heap(sds,name,','); return dptr[object].obj_name;}/*********************************************************************/char *sds_obind2name(sds,object)sds_handle sds;sds_code object;/*********************************************************************/{ return(sds_oname(sds,object,SDS_GEN_NAME));}/*********************************************************************/sds_handlesds_named_elements(sds,object)sds_handle sds;sds_code object;/************************************************************************/{ struct direc *dptr = sds_direc(sds); if (dptr == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,""); return 0L; } return((sds_handle)(dptr[object].obj_name >> 16));} /*********************************************************************/char *sds_oname(sds,object,elem)sds_handle sds;sds_code elem,object;/*********************************************************************/{ struct direc *dptr = sds_direc(sds); char *cptr; elem++; if (dptr == DNULL) { sds_push_error(SDS_NO_SUCH_SDS, SDS_ERROR," Finding object name"); return (char *)0; } if (elem > (dptr[object].obj_name >> 16)) { sds_push_error(SDS_NO_SUCH_OBJ,SDS_ERROR,"Finding object name"); return (char *)0; } cptr = (sds_heap(sds) + (dptr[object].obj_name & 0xffff)); cptr = sds_jstr(cptr,elem); return(cptr);}/*********************************************************************/sds_handlesds_new(name)char *name;/*********************************************************************/{ struct direc *ddptr; sds_handle sds; struct sds_control_p *scp; sds_handle heap_place; if (!sds_initialised()) { fprintf(stderr,"Sds must be initialised with sds_init()"); exit(1); } if ((sds = good_sds(name))) { sds_push_error(SDS_DEJA_LA,SDS_WARNING,"Trying to make new dataset"); return sds; } if (!(sds = next_sds())) return 0L; scp = sds_control(sds);/* Start-up space for the directory */ ddptr = scp->dptr = (struct direc *)sds_calloc((unsigned int)SDS_INC_DIREC, (unsigned int)sizeof(struct direc)); if (ddptr == 0 ) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Trying to make new dataset"); return 0L; } scp->allofl = SDS_DPTR_ALLOC; scp->direc_size = SDS_INC_DIREC;/* Initialise direc[0]: the directory entry */ ddptr[0].nelems = (unsigned long)1; ddptr[0].elemsz = sizeof(struct direc); ddptr[0].align_type = sds_palign(SDS_DIRECTORY_STRUCTURE); ddptr[0].offst = SDS_NOT_ASSEMBLED; ddptr[0].structype = (short)0; ddptr[0].illoca = (unsigned char)0; scp->tlist = TNULL; scp->shead = HNULL; heap_place = sds_add_to_heap(sds,name,0); if (heap_place < 0) { ddptr[0].obj_name = (sds_code)heap_place; return 0L; }/* And timestamp it for the hell of it */ sds_tstamp(sds,SDS_TIMESTAMP_ALL); return(sds);}/*********************************************************************/sds_handlesds_access(source_name,source_type,mode)char *source_name;sds_code source_type,mode;/* get access to an (alleged?) SDS outside process memory. Unless this involves attaching to shared memory, this means I load into process memory.*//*********************************************************************/{ struct direc *dptr = 0; sds_handle sds = SDS_NO_SUCH_SDS; int obj; struct sds_control_p *scp; int success = 0; char *temprpt = malloc(strlen(source_name) + 32); sprintf(temprpt,"Dataset %s", source_name); if (!sds_initialised()) { fprintf(stderr,"Sds must be initialised with sds_init()"); exit(1); } if (source_type & SDS_PROC_MEM) { free(temprpt); return good_sds(source_name); } if ((source_type & SDS_FILE) || (source_type == SDS_SEQUENTIAL)) { if ((source_type & SDS_DIREC_ONLY) || (source_type == SDS_SEQUENTIAL)) { int fd; sds_handle orig_state,sdsn; struct sds_header head; sdsn = sds = next_sds(); if ((fd = sds_open_file(source_name, O_RDONLY | O_BINARY)) >= 0) { if ((sds = sds_cload_direc(sds,fd,&orig_state, &head)) != 0) { dptr = sds_direc(sds); success = 1; if (source_type == SDS_SEQUENTIAL) dptr[0].offst = SDS_NOT_ASSEMBLED; } else { if (sds_last_return() == SDS_GOOD_FORMAT) { if ((sds = sds_load_direc(sdsn,fd, &head))) { dptr = sds_direc(sds); success = 1; if (source_type == SDS_SEQUENTIAL) dptr[0].offst = SDS_NOT_ASSEMBLED; } } } sds_close_fd(fd); } } else { if ((sds = sds_load_conv(source_name))) { dptr = sds_direc(sds); success = 1; } } }#ifdef SHMEM else if (source_type & SDS_SHARED_MEM) { if (shm_q(source_name)) { /* it exists! */ if ((sds = next_sds()) < 0) return(sds); if (mode & SDS_READ) dptr = (struct direc *)shm_attr(source_name); else dptr = (struct direc *)shm_attw(source_name); if (dptr != 0) { success = 1; set_sys_vars(sds,dptr); } } else sds_push_error(SDS_NO_SUCH_SDS, SDS_ERROR, "Attach to shared mem"); }#endif else sds_push_error(SDS_NO_SUCH_SDS, SDS_ERROR, "undefined sds source type"); if (!success) { sds_push_error(sds_last_error(), SDS_ERROR, temprpt); free(temprpt); return 0L; } free(temprpt); scp = sds_control(sds); scp->source = source_type; scp->load_name = malloc(strlen(source_name) + 1); strcpy(scp->load_name, source_name); scp->is_proto = 0; /* clean up in case allocation flags have been left in file (not nice) */ if (!(source_type & SDS_SHARED_MEM)) for (obj = 0;obj < dptr[0].nelems; obj++) dptr[obj].illoca &= ~(SDS_WAS_ALLOCATED | SDS_EXTERNAL_OBJECT | SDS_REALLOC); return(sds);}/*********************************************************************/voidset_sys_vars(sds,dptr)sds_handle sds;struct direc *dptr;/*********************************************************************/{ struct sds_control_p *scp = sds_control(sds); scp->dptr = dptr; scp->direc_size = SDS_FIXED; scp->shead = (struct sds_header *)((char *)dptr - dptr[0].offst); scp->tlist = scp->shead->list_size? (struct type_list *)((char *)scp->shead + BASE_OFFSET):TNULL; scp->heap = (char *)scp->shead + (int)scp->shead->list_size
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -