⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sds_offil.c

📁 This Source-Navigator, an IDE for C/C++/Fortran/Java/Tcl/PHP/Python and a host of other languages.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Header: /cvsroot/sourcenav/src/snavigator/demo/c++_demo/sds/sds_offil.c,v 1.1.1.1 2002/04/18 23:35:32 mdejong Exp $ */#if !defined(VXWORKS) && !defined(vms)#include "malloc.h"#include <memory.h>#endif#if defined(vms)#include "sdsgen.h"#include "sds_externs.h"#else#include "Sds/sdsgen.h"#include "Sds/sds_externs.h"#endifextern char  *strstr();/************* forward declarations */int CheckVarLength(sds_handle ,sds_handle,char **,int);int FillBaseAddress(sds_handle ,sds_handle,char **,int);int ScanFortranFile(sds_handle ,sds_handle,char **,int);int LoadFromHeader(sds_handle ,sds_handle,char **,int);int allocate_data_pointers(sds_handle,sds_handle,int);/* The arguments passed to offil need some explanation.   The sds handle is fairly simple, and if this is a normal dataset   without externally mapped objects ("DISJOINT") the story ends there:   offsets from the start  of the dataset are calculated from object   sizes as defined in the header.   If, however, we have objects mapped in there are two main possiblities:   1. All data objects come from the same mapped region: that is, the only      alignment to be calculated differently is that between the header and      the first data object.   2. A mixture of objects from the header and from mapped region(s) are      present; offsets are somewhat more complex.   (1) is a subset of (2) but likely to be common so the interface is    simplified. In the case of (1), the NAddr value is 1, DataAddr points   to the single mapped region, and DataSize points to the single size   value (note: if sizes are set to 0, SDS will try to get a rational   size by stat'ing the file or calculating from header definitions. The   size parameter is there primarily for when hardware devices need to be   mapped.)   In the more complex case where data objects   may reside with the header, and one or more objects may be in each   region, NAddr should match the number of objects (if not it will be   assumed that all unmarked objects run on from the last marked data   region). DataAddr[0] MUST be nil, as should all DataAddr entries   referring to objects residing in the header file. Other DataAddr entries   will point to the data region for the corresponding object EXCEPT if   sizes[object] is negative; for sizes[object] = -n, the object will be   assumed to run on from the data region of object 'n'.   In the case of variable-size data, two strategies are presently   supprorted. Firstly, explicitly named counts may be present in the data   objects. In this case, a top-level object <mystruct> may contain an   integer or short field named <mystruct.tot_avail>: this implies that   the following object has a multiplicity of the value of <mystruct.tot_avail>.  (Note: for SDC, the object "Number of Channels" is also searched for)   Next, a field <mystruct.varstruct_count> within a top level object    <mystruct> implies that there is a variable number of structures called   <mystruct.varstruct at> the end of each instance of <mystruct>.   The second strategy is that employed by fortran writes. This is more   limited and compiler dependant so many potholes exist to fall into, but   is   probably quite consistent across Unix at least. Here one has a number of   'records', each of the same structure, contained in 'events'. The   'events' are delimited at each end by the number of bytes within the   event, EXCLUDING the two bytecount integers. Thus, knowing the record   size one can scan a file and split the data hierarchically into a number   of events each containing a different number of records.   In both cases, SDS will scan the datafiles and generate a pointer array   for the top-level objects, each pointer being associated with the number   of variable things - 'vatstruct's' or 'records' - within each instance   of the high level thing.When these data address pointer arrays have been   built, they may be saved with the header information so that scanning is   not necessary every time - or at least scanning can being where it left   off last time if, for instance, the data file has been appended to. *//* These statics will hold information about yyyy_count numbers,   to be matched against yyyy[] arrays if they are found... */static char *count_base;static int count,precount,presize;static int countoff;static int is_short;static int countbits;static char *varname = NULL;sds_handle offil(sds, DataAddr, NAddr, DataSize)sds_handle sds;char **DataAddr;int    NAddr;off_t   *DataSize;{  unsigned long    i,lhsize,offset, offsetbase;  unsigned long    hoffset, doffset = 0;  struct direc *dptr = sds_direc(sds);  struct sds_odesc *thing;  char name[256];  int next_nelems = -1;  int topvarlen = 0;  int osize;  int NElems = dptr[0].nelems;  char **DA;  char **old_addresses;  off_t *S;  int allocated;  int padding;  if (NAddr > NElems)  {    fprintf(stderr,"Number of map addresses exceeds number of objects\n");    fprintf(stderr,"Bailing out from dataset %s\n",sds_obind2name(sds,0));    exit(1);  }  old_addresses = (char **)sds_malloc(NElems * sizeof(char *));  for (i=0;i<NElems;i++)    old_addresses[i] = sds_obind2ptr(sds,i);  if (NElems > 0 && NAddr != NElems)  {    DA = (char **)sds_malloc(NElems * sizeof(char *));    S = (long *)sds_malloc(NElems * sizeof(int));    allocated = 1;    if (NAddr > 0)    {      memcpy(DA,DataAddr,NAddr * sizeof(char *));      memcpy(S,DataSize,NAddr * sizeof(int));    }    else    {      memset((char *)DA,0,NElems * sizeof(char *));      memset((char *)S,0,NElems * sizeof(int));    }  }  else  {    DA = DataAddr;    S = DataSize;    allocated = 0;  }  lhsize = (unsigned long )(tlist_size(sds_tlist(sds)) +            sds_heap_size(sds));  lhsize += align_delta(lhsize+BASE_OFFSET,sds_palign(SDS_DIRECTORY_STRUCTURE));       dptr[0].elemsz = (unsigned long)sizeof(struct direc);  dptr[0].elemcod = SDS_DIRECTORY_STRUCTURE;       dptr[0].align_type = sds_palign(SDS_DIRECTORY_STRUCTURE);  if (dptr[0].structype & SDS_VARIABLE_LENGTH)    topvarlen = 1;       offsetbase = BASE_OFFSET + lhsize;  dptr[0].offst = (sds_off_t)offsetbase;  hoffset = offset = offsetbase + dptr[0].nelems*dptr[0].elemsz;/* Find my base addresses and sizes */  for ( i = 1; i< NElems ; i++ )   {    if (next_nelems > 0)    {/* If I have previously found the number of elements, load it in */      if (dptr[i].structype & SDS_EXTERNAL_LENGTH)         dptr[i].nelems = next_nelems;      /* next_nelems = -1; */    }    if (!(dptr[i].illoca & SDS_DISJOINT_OBJECT))    {      offset = hoffset;      padding = align_delta(offset,dptr[i].align_type);      offset += padding;      S[i-1] += padding;      dptr[i].offst = (sds_off_t)offset;      osize = dptr[i].nelems*dptr[i].elemsz;      hoffset = offset = (unsigned long)dptr[i].offst + osize;      S[i] = osize;      DA[i] = DA[i-1] + S[i-1];    }    else    {      if (DA[i] != NULL)      {        dptr[i].offst = (sds_off_t)offsetbase +                ((unsigned long)DataAddr[i] - (unsigned long)dptr);        if ((osize = CheckVarLength(sds,i,old_addresses,S[i])) == -1)          osize = dptr[i].nelems * dptr[i].elemsz;        doffset = (long)dptr[i].offst + osize;        S[i] = osize;      }      else if (doffset != 0)      {        offset = doffset;        padding = align_delta(offset,dptr[i].align_type);        S[i-1] += padding;        offset += padding;        dptr[i].offst = (sds_off_t)offset;        if ((osize = CheckVarLength(sds,i,old_addresses,S[i])) == -1)          osize = dptr[i].nelems * dptr[i].elemsz;        DA[i] = DA[i-1] + S[i-1];        doffset = offset = (long)dptr[i].offst + osize;        S[i] = osize;      }      else      {        dptr[i].offst = SDS_IMPOSSIBLE_ADDRESS;        S[i] = 0;      }    }    if (topvarlen && dptr[i].offst != SDS_IMPOSSIBLE_ADDRESS)     {      char * oaddr = sds_obind2ptr(sds,i);/* Find the number of elements of the next object */      if (!strcmp(sds_obind2name(sds,i), "Number of Channels"))        next_nelems = *(int *)(oaddr);      else      {        sprintf(name,"%s.tot_avail", sds_obind2name(sds, i));        if (sds_find_thing(sds, name, &thing) >= 0)           next_nelems = *(int *)(DA[i] + (long)thing->address - (long)oaddr);        sds_cleanup(sds);      }    }  }  if (allocated)  {    free(DA);    free(S);  }  free(old_addresses);  return 1L;}voidScanForPreCount(sds,object)sds_handle sds,object;{  struct   sds_odesc *thing;  struct direc *dptr = sds_direc(sds);  char *temp;  int level;  sds_cleanup(sds);  while ((level = sds_describe(sds,object,&thing)) >= 0)   {    if (((thing[level].elemcod == SDS_INT) ||         (thing[level].elemcod == SDS_SHORT)) &&         (strstr(thing[level].name, "_count")) != NULL)    {      count_base = sds_obind2ptr(sds, object);      countoff = thing[level].address - count_base;      presize = dptr[object].elemsz;      if (varname != NULL)      {        free(varname);        varname = NULL;      }      varname = sds_malloc(strlen(thing[level].name) + 1);      strcpy(varname,thing[level].name);      temp = strstr(varname, "_count");      if (thing[level].elemcod == SDS_SHORT)      {        is_short = 1;        count = (int)*(short *)thing[level].address;      }      else      {        is_short = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -