📄 sds.c
字号:
/* $Header: /cvsroot/sourcenav/src/snavigator/demo/c++_demo/sds/sds.c,v 1.1.1.1 2002/04/18 23:35:29 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. * * * **************************************************************************//*s********************************************************************** * * * Copyright (C) * * Epsilon Eridani 3 Megasoft Corporation, 1986 * * * * This library contains Proprietary Information of Frogsoft * * Corporation and should not be treated as Confidential. * * * * Authors: WFH, CGS, Verklim Fartislart * * *//*e**********************************************************************//* Reference release Aug 10 1991 - C G Saltmarsh *//* Has the basics used at CDG & SSC 1988-1991, plus vxworks support*/#include <stdlib.h>#include <string.h>#include <fcntl.h>#ifndef vms#include <unistd.h>#endif#ifndef vms#include "Sds/sdsgen.h"#include "Sds/sds_externs.h"#else#include "sdsgen.h"#include "sds_externs.h"#endifextern char *sds_align;/***** forward declarations ******/#if defined(__STDC__)void pindent(int);int sds_praw_directory(sds_handle);void sds_printohead(sds_handle,sds_handle, struct sds_odesc *,int);#elsevoid pindent();int sds_praw_directory();void sds_printohead();#endif char *ctime();/***********************************************************************/voidnexpand(fullname,name)/*s********************************************************************** * * * Expands input name to full pathname for standard sd directory * * if first character = '@', will take name literally * * * * Author: CGS, WFH * * *//*e**********************************************************************/char *fullname;char *name;/***********************************************************************/{ char *temp; char *getenv();#ifdef VXWORKS char *user;#endif if (*name == '@' ) { name++; strcpy(fullname,name); } else {#ifdef VXWORKS remCurIdGet(user, NULL); strcpy(fullname,"/home/"); strcat(fullname,user);#else temp = getenv("HOME"); strcpy(fullname,temp);#endif strcat(fullname,"/shardat/"); strcat(fullname,name); } } /***********************************************************************/sds_handlesds_obind2code(sds, object_index)sds_handle object_index;sds_handle sds;/***********************************************************************/{ struct direc *dptr = sds_direc(sds); if (dptr == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Getting object code"); return 0L; } if (object_index < 1 || object_index > dptr[0].nelems) { sds_push_error(SDS_NO_SUCH_OBJ,SDS_ERROR,"Getting object code"); return 0L; } return(dptr[object_index].elemcod);}/***********************************************************************/void *sds_obind2ptr(sds,object)/*s********************************************************************** * * 1. Return pointer to object "ielem" in data area * with sds handle sds * 2. Return 0 if it is out-of-bounds or no entry ... * * Author: CGS * *//*e**********************************************************************/sds_code object;sds_handle sds;/***********************************************************************/{ struct direc *dptr = sds_direc(sds); if (dptr == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Getting object pointer"); return (void *)0; } return(sds_getp(dptr,object));}/***********************************************************************/void *sds_getp(dptr,ielem)sds_handle ielem;struct direc* dptr;/***********************************************************************/{ unsigned long jelem; char *cptr; if (ielem == (unsigned long)0) return((void *)dptr); jelem = dptr[0].nelems; if ( ielem > jelem ) { sds_push_error(SDS_NO_SUCH_OBJ,SDS_ERROR,"Getting object pointer"); return (void *)0; } if (dptr[ielem].nelems == 0 || dptr[ielem].offst == SDS_IMPOSSIBLE_ADDRESS) cptr = NULL; else if (dptr[0].offst == SDS_NOT_ASSEMBLED) cptr = (char *)dptr[ielem].offst; else cptr = (sds_addr)dptr + (long)dptr[ielem].offst - (long)dptr[0].offst; return((void*) cptr);}/***********************************************************************/sds_handlesds_get_checked(sds,object_name,type_code)sds_handle sds;char *object_name;sds_code type_code;/***********************************************************************/{ sds_handle ind; struct direc *dptr = sds_direc(sds); if (dptr == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Checking object"); return 0L; } if (!(ind = sds_name2ind(sds,object_name))) return 0L; if (dptr[ind].elemcod != type_code) { sds_push_error(SDS_WRONG_TYPE,SDS_ERROR,"Checking object"); return 0L; } return(ind);}/***********************************************************************/sds_handle sds_name2ind(sds,name)sds_handle sds;char *name;/***********************************************************************/{ sds_handle nobj; sds_code j; struct direc *dptr = sds_direc(sds); if (dptr == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Getting object index"); return 0L; } nobj = dptr[0].nelems; for (j=1;j<nobj;j++) if (!strcmp(sds_obind2name(sds,j),name)) return(j); sds_push_error(SDS_NO_SUCH_OBJ,SDS_ERROR,"Getting object index"); return 0L;}/***********************************************************************/sds_handle sds_like2ind(sds,name,start)sds_handle sds,start;char *name;/***********************************************************************/{ sds_handle nobj; sds_code j; struct direc *dptr = sds_direc(sds); if (dptr == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Getting object index"); return 0L; } nobj = dptr[0].nelems; for (j=start;j<nobj;j++) if (strstr(sds_obind2name(sds,j),name) != 0) return(j); sds_push_error(SDS_NO_SUCH_OBJ,SDS_ERROR,"Getting object index"); return 0L;}/***********************************************************************/sds_handle sds_array_size(sds,object)sds_handle sds;sds_handle object;/***********************************************************************/{ struct direc *dptr = sds_direc(sds); if (dptr == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Getting array size"); return SDS_NO_SUCH_SDS; } if (object < dptr[0].nelems && object >= 0) return(dptr[object].nelems); else { sds_push_error(SDS_NO_SUCH_OBJ,SDS_ERROR,"Getting array size"); return SDS_NO_SUCH_OBJ; }}/***********************************************************************/void *sds_obname2ptr(sds,name)sds_handle sds;char *name;/***********************************************************************/{ sds_handle object_number; struct direc *dptr = sds_direc(sds); if (dptr == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Getting object pointer"); return (void *)0; } if ((object_number = sds_name2ind(sds,name))) return(sds_getp(dptr,object_number)); else return (void *)0; }/*s************************************************** * * Stick timestamp on object obj within directory * * The directory timestamp - dptr[0].wtime - * holds Unix time (seconds since Jan 1, 1970)* while individual objects hold delta time * since directory time (in millisecinds? - to * be determined. As of now, no time info is there.) *****************************************************//***********************************************************************/sds_handlesds_tstamp(sds,obj) sds_handle sds; sds_handle obj;/***********************************************************************/{ struct direc *dptr; if ((dptr = sds_direc(sds)) == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Timestamping"); return 0L; } if ((obj == SDS_TIMESTAMP_ALL) || (obj == (unsigned long)0)) { dptr[0].wtime = (unsigned long)time(0); if (obj != (unsigned long)0) { unsigned long i; for (i=1;i<dptr[0].nelems;i++) dptr[i].wtime = i; } } else { dptr[obj].wtime = obj; } return 1L; }/***********************************************************************/long *sds_get_tstamp(sds,obj)sds_handle sds;sds_handle obj;/***********************************************************************/{ struct direc *dptr; if ((dptr = sds_direc(sds)) == DNULL) { sds_push_error(SDS_NO_SUCH_SDS,SDS_ERROR,"Getting timestamp"); return (long *)0; } if (obj < 0 || obj > dptr[0].nelems) { sds_push_error(SDS_NO_SUCH_OBJ,SDS_ERROR,"Getting timestamp"); return (long *)0; } return (long *)&dptr[obj].wtime;}/***********************************************************************/char *load_sds_file(sds_handle sds,int fd,unsigned long nbytes)/***********************************************************************/{ char *sdptr; sdptr = sds_malloc((unsigned int)nbytes); if (sds_read(fd,(int)nbytes,sdptr) != nbytes) { free(sdptr); sds_push_error(SDS_FILE_RD,SDS_ERROR,"Loading from file desc"); return (char *)0; } else return sdptr;}/*********************************************************************/sds_handlesds_header_ok(sdsh)struct sds_header *sdsh;/*********************************************************************/{ if (sdsh->magic_number != SDS_MAGIC) { if ((sdsh->magic_number & 0xffff00ff) == SDS_BASE_MAGIC) { sds_push_error(SDS_WRONG_PADS,SDS_WARNING,"Check SDS type"); if ((SDS_ARC == SDS_SPARC) && (sdsh->controlbits & SDS_IS_RISCY)) return 1; return 0L; } else { if ((sdsh->magic_number & 0xff00ffffL) == SDS_MAGIC_BYTESWAP) sds_push_error(SDS_SWAPPED_BYTES,SDS_WARNING,"Check SDS type"); else sds_push_error(SDS_NOT_SDS,SDS_ERROR,"Check SDS type"); return 0L; } } if (sdsh->version > SDS_VERSION ) { sds_push_error(SDS_BAD_VERSION,SDS_WARNING,"Check SDS type"); return 0L; } return 1L; }/*********************************************************************/unsigned longtlist_size(tlist)struct type_list *tlist;/*********************************************************************/{ unsigned long list_size = (unsigned long)0; if (tlist == TNULL) return(list_size); while((tlist++)->elemcod != SDS_ENDLIST) list_size++; list_size++; return list_size*(unsigned long)sizeof(struct type_list);}/*********************************************************************/struct direc*header_to_direc(sds_header)struct sds_header* sds_header;/*********************************************************************/{ char *cptr = (char *)sds_header; return((struct direc *)(cptr + (int)sds_header->list_size + (int)sds_header->heap_size + BASE_OFFSET));}/***********************************************************************/intsds_praw_directory(sds)sds_handle sds;/***********************************************************************/{ struct sds_odesc *thing; int indent,ts = -1,hs; struct direc *dptr = sds_direc(sds); unsigned long i,nobj = dptr[0].nelems; char *cptr,*type_ptr; struct type_list *tptr; hs = (int)sds_heap_size(sds); if (sds_head(sds) != NULL) { ts = (int)(sds_head(sds)->list_size);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -