📄 sds_glob.c
字号:
/* $Header: /cvsroot/sourcenav/src/snavigator/demo/c++_demo/sds/sds_glob.c,v 1.1.1.1 2002/04/18 23:35:31 mdejong Exp $*/#include "Sds/sdsgen.h"#include "Sds/sds_errstrings.h"#include "Sds/sds_externs.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#if !defined(VXWORKS)#include <sys/time.h>#endif#include <sys/types.h>#include <unistd.h>#if defined(__SUN5)#define OPEN_MAX FOPEN_MAX#else#if defined(__linux__)#include <i386/fpu_control.h> /* See note in sds_global_init() below */#include <linux/limits.h>#else#if defined(VXWORKS)#include <types/vxParams.h>#define OPEN_MAX _PARM_FOPEN_MAX#else#include <sys/param.h>#define OPEN_MAX NOFILE#endif#endif#endif#if !defined(VXWORKS)#if !defined(__MSDOS__) #include <malloc.h>#include <memory.h>#else#include <alloc.h>#include <mem.h>#endif#endif/* This for backward compatibility with the old error system */int sds_error;/* forwards..... */struct sds_control_p * sds_new_scp(VOIDDEF);#if defined(__STDC__)void printoutprog(int);void printout(int);#elsevoid printoutprog();void printout();#endifextern void sds_cleanc(rescon *);/* The sizes of all the primitive types on the current architecture, in bytes */static char sds_sizes[NPRIMITIVES] = { (char)0, /* struct */ (char)sizeof(char), /* pad - unused */ (char)sizeof(char), /* byte */ (char)sizeof(char), /* unsigned byte */ (char)sizeof(short), /* word */ (char)sizeof(short), /* unsigned word */#if (SDS_BIGADDR == 1) /* 8-byte address and long */ (char)sizeof(int), /* 4-byte integer */ (char)sizeof(int), /* unsigned 4-byte integer */#else /* 4-byte address and long */ (char)sizeof(long), /* 4-byte integer */ (char)sizeof(long), /* unsigned 4-byte integer */#endif (char)sizeof(float), /* float */ (char)sizeof(double), /* double */ (char)sizeof(float), /* vax float */ (char)sizeof(double), /* vax D-double */ (char)sizeof(double), /* vax G-double */ (char)1, /* C string - zero terminated */ (char)sizeof(struct direc), /* direc structure */ (char)2*sizeof(float), /* complex */ (char)2*sizeof(double), /* double complex */ (char)2*sizeof(float), /* vax complex */ (char)2*sizeof(double), /* vax D-double complex */ (char)2*sizeof(double), /* vax G-double complex */ (char)sizeof(char), /* logical byte */ (char)sizeof(short), /* logical word */#if (SDS_BIGADDR == 1) /* 8-byte address and long */ (char)sizeof(int), /* logical 4-byte */#else (char)sizeof(long), /* logical 4-byte */#endif (char)sizeof(char*), /* pointer */ (char)2*sizeof(long), /* time (eg sybase time ) */ (char)0, /* Sds */ (char)1, /* fixed length string, no terminator */#if (SDS_BIGADDR == 1) /* 8-byte address and long */ (char)sizeof(int), /* size modifier */#else (char)sizeof(long), /* size modifier */#endif (char)sizeof(void*), /* Glish value */#if (SDS_BIGADDR == 1) /* 8-byte address and long */ (char)sizeof(int), /* Unix time */#else (char)sizeof(long), /* Unix time */#endif (char)0, /* bitfield */#if (SDS_BIGADDR == 1) /* 8-byte address and long */ (char)sizeof(long), /* internal pointer */ (char)sizeof(long), /* 8-byte integer */#else (char)sizeof(int), /* internal pointer */ (char)2*sizeof(long), /* 8-byte integer */#endif (char)0, /* End bitfield */ (char)sizeof(char), /* byte bitfield */ (char)sizeof(short), /* word bitfield */#if (SDS_BIGADDR == 1) /* 8-byte address and long */ (char)sizeof(int), /* 4-byte bitfield */ (char)sizeof(long), /* 8-byte bitfield */ (char)sizeof(long), /* 8-byte unsigned long */#else (char)sizeof(long), /* 4-byte bitfield */ (char)2*sizeof(long), /* 8-byte bitfield */ (char)2*sizeof(long), /* 8-byte unsigned long */#endif };/* ...and the corresponding names */static char type_name[NTYPES + 1][22] = { "Structure", "Pad", "Byte", "Uns Byte", "Word", "Uns Word", "Long32", "Uns Long32", "Float", "Double", "Vax Float", "Vax D-Double", "Vax G-Double", "C-String", "Direc", "Complex", "Complex Double", "Vax Complex", "Vax Complex D-Double", "Vax Complex G-Double", "Logical Byte", "Logical Word", "Logical Long32", "Pointer", "Time", "Sds", "F-String", "Size Modifier", "Glish Value", "Unix Time", "Bitfield", "Internal Pointer", "Long64", "End Bitfield", "Char Bitfield", "Short Bitfield", "Long32 Bitfield", "Long64 Bitfield", "UnsLong64", "Unknown Type" };static char c_type_name[NTYPES + 1][22] = { "struct", "char", "char", "unsigned char", "short", "unsigned short", "long", "unsigned long", "float", "double", "float", "double", "double", "char", "struct direc", "Complex", "Complex Double", "Vax Complex", "Vax Complex D-Double", "Vax Complex G-Double", "unsigned char", "unsigned short", "unsigned long", "char *", "time_t", "Sds", "char", "Size Modifier", "Glish Value", "long", "Bitfield", "Internal Pointer", "long long", "End Bitfield", "Char Bitfield", "Short Bitfield", "Long32 Bitfield", "Long64 Bitfield", "UnsLong64", "Unknown Type" };char *sds_typename(code)sds_code(code);/* return the name of a given primitive type code, or 'Unknown Type' if the thing is complex */{ return code > NPRIMITIVES?type_name[NPRIMITIVES]:type_name[code]; }char *sds_c_typename(code)sds_code(code);{ return code > NPRIMITIVES?c_type_name[NPRIMITIVES]:c_type_name[code]; }char sds_psize(code)sds_code code;/* return the primitive size of a given type code, or 0 if the thing is complex */{ return code > NPRIMITIVES?(char)0:sds_sizes[code]; }/* See sds_mdep.h: most restrictive byte boundary for each architecture*/static char sds_rbytes[NARCS] = { 2,8,1,8,4};/* The following gives alignment for different SDS_XXX *//* Note that there is a special code for SDS_BITFIELD whose alignment is only there to pad the array correctly - its alignment depends on where it is in its integer or short or whatever. SDS_BITFIELD types modify whatever integer type they follow. Here their alignment is marked '0'. */static char sds_arcs[NARCS][NPRIMITIVES] = { {2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 680x0 */ 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2, 2, 0, 2, 2, 0, 1, 2, 2, 2, 2}, {8, 1, 1, 1, 2, 2, 4, 4, 4, 8, 4, 8, 8, /* SUN, HP MIPS RISC */ 1, 4, 4, 8, 4, 8, 8, 1, 2, 4, 4, 4, 1, 1, 4, 4, 4, 0, 4, 4, 0, 1, 2, 4, 4, 4}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* VAX VMS */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1}, {8, 1, 1, 1, 2, 2, 4, 4, 4, 8, 4, 8, 8, /* Alpha.8byte long,addr */ 1, 8, 4, 8, 4, 8, 8, 1, 2, 4, 8, 4, 1, 1, 4, 8, 4, 0, 8, 8, 0, 1, 2, 4, 8, 8}, {4, 1, 1, 1, 2, 2, 4, 4, 4, 4, 4, 4, 4, /* ultrix, hypercube */ 1, 4, 4, 4, 4, 4, 4, 1, 2, 4, 4, 4, 1, 1, 4, 4, 4, 0, 4, 4, 0, 1, 2, 4, 4, 4} };/* The single pointer through which all SDS globals are referenced */static struct sds_sys_control *ssc = NULL;/* The following calls return information about the current, or other, architectures; they are here so that the data is not directly accessed*/char sds_palign(code)sds_code code;{ return code > NPRIMITIVES?(char)0:sds_arcs[SDS_ARC][code]; }char sds_arc_palign(arc, code)int arc;sds_code code;{ return arc < 0 || arc > NARCS || code > NPRIMITIVES? (char)0:sds_arcs[arc][code];}char sds_arc_rbyte(arc)int arc;{ return sds_rbytes[arc]; }char sds_rbyte(VOIDDEF){ return sds_rbytes[SDS_ARC]; }char *sds_arc_aligns(arc)int arc;{ return sds_arcs[arc]; }/* end of architecture information calls *//* Check to see if an sds handle refers to a valid dataset. Return 1 for a good handle referring to a real dataset. Return 0 and set error to SDS_NO_SUCH_SDS if handle is out-of-range. Return 0, do not set error if handle is usable (ie in range but not referring to a real dataset).*/intsds_dataset_check(sds)sds_handle sds;{ if (!ssc) { fprintf(stderr,"Sds must be initialised with sds_init()"); exit(1); } if ((sds > sds_max()) || (sds <= 0L)) { sds_push_error(SDS_NO_SUCH_SDS, SDS_RETURN, "Invalid sds handle when accessing system tables"); return 0; } if (!ssc->sds_cp[sds-1]) return 0; return 1;}/* The following calls return control structures for global SDS manipulations.*/struct sds_control_p *sds_control(sds)sds_handle sds;{ #if !defined(SDS_GO_FAST) return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]: (struct sds_control_p *)0;#else return ssc->sds_cp[(int)sds - 1];#endif}struct sds_saverestore *sds_saver(VOIDDEF){ return &ssc->sr; }int sds_maxbufsize(VOIDDEF){ return ssc->maxbufsize; }void sds_setmaxbuf(int size){ ssc->maxbufsize = size; }int sds_fd_buffer(VOIDDEF){ return ssc->fd_buffer; }void sds_setfd_buffer(int fd_buffer){ ssc->fd_buffer = fd_buffer; }intsds_initialised(VOIDDEF){ return ssc == 0?0:1; }intsds_initialise_enabled(VOIDDEF){ return ssc?ssc->re_init:1; }void sds_reinit_enable(VOIDDEF){ if (ssc) ssc->re_init = 1; }intsds_genarc(sds)sds_handle sds;#if !defined(SDS_GO_FAST){ return sds_dataset_check(sds)?(int)ssc->sds_cp[(int)sds - 1]->genarc:-1; }#else{ return (int)ssc->sds_cp[(int)sds - 1]->genarc; }#endifintsds_stream(sds)sds_handle sds;#if !defined(SDS_GO_FAST){ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->stream:0; }#else{ return ssc->sds_cp[(int)sds - 1]->stream; }#endifintsds_source(sds)sds_handle sds;#if !defined(SDS_GO_FAST){ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->source:0; }#else{ return ssc->sds_cp[(int)sds - 1]->source; }#endifintsds_heap_size(sds)sds_handle sds;{ int size, psize; if (!sds_dataset_check(sds)) return 0; size = ssc->sds_cp[(int)sds - 1]->current_heap - ssc->sds_cp[(int)sds -1]->heap; psize = align_delta(size,4); if (psize) memset(ssc->sds_cp[(int)sds - 1]->current_heap, 0, psize); return size + psize;}intsds_direc_size(sds)sds_handle sds;{ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->direc_size:0; }int **sds_varel(sds)sds_handle sds;{ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds-1]->varel_count:0; }sds_handle *sds_dup_size(sds)sds_handle sds;{ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->dup_size:0; }char *sds_loadname(sds)sds_handle sds;{ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->load_name:0;}voidsds_trap_bigint_overflow(int tf){ if (tf) ssc->controlbits |= SDS_TRAP_DOUBLE_LONG_OVERFLOW; else ssc->controlbits &= ~SDS_TRAP_DOUBLE_LONG_OVERFLOW;}voidsds_bigint_trap(void *generalpointer){ sds_perror("Conversion overflow 64-bit integer to 32-bit integer");}voidsds_truncate_bigints(){ ssc->controlbits &= ~SDS_DOUBLE_LONG_MASK; ssc->controlbits |= SDS_TRUNCATE_DOUBLE_LONGS;}voidsds_float_bigints(){ ssc->controlbits &= ~SDS_DOUBLE_LONG_MASK; ssc->controlbits |= SDS_FLOAT_DOUBLE_LONGS;}voidsds_pack_bigints(){ ssc->controlbits &= ~SDS_DOUBLE_LONG_MASK; ssc->controlbits |= SDS_DOUBLE_LONGS_IN_LONGS;}int sds_query_truncate_b(void) { return ssc->controlbits & SDS_TRUNCATE_DOUBLE_LONGS;}int sds_query_trap_b(void) { return ssc->controlbits & SDS_TRAP_DOUBLE_LONG_OVERFLOW;}int sds_query_float_b(void) { return ssc->controlbits & SDS_FLOAT_DOUBLE_LONGS;}int sds_query_pack_b(void) { return ssc->controlbits & SDS_DOUBLE_LONGS_IN_LONGS;}char *sds_heap(sds)sds_handle sds;{#if !defined(SDS_GO_FAST) return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->heap:0; #else return ssc->sds_cp[(int)sds - 1]->heap; #endif}char *sds_current_heap(sds)sds_handle sds;{ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds-1]->current_heap:0;}char ***sds_estart(sds)sds_handle sds;{ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->element_start:0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -