📄 sds_glob.c
字号:
rescon *sds_new_rescon(){ rescon *c = (rescon *)sds_calloc(1,sizeof(rescon)); c->stack_size = 0; c->start_stack = 0; sds_cleanc(c); return c;}void sds_delete_rescon(rescon *c){ if (c) { sds_cleanc(c); free((char *)c); }}struct sds_res_control *sds_src(sds)sds_handle sds;{ if (!sds_dataset_check(sds)) return 0; if (!(ssc->sds_cp[(int)sds - 1]->src)) { ssc->sds_cp[(int)sds - 1]->src = sds_new_rescon(); } return ssc->sds_cp[(int)sds - 1]->src;}/***********************************************************************/voidsds_cleanup(sds_handle sds)/***********************************************************************/{ struct sds_res_control *c = sds_src(sds); if (c) sds_cleanc(c); else sds_push_error(SDS_NO_SUCH_OBJ,SDS_ERROR,"Initialise res stack with sds_rinit()"); return;}struct sds_header *sds_head(sds_handle sds){#if !defined(SDS_GO_FAST) return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->shead:0; #else return ssc->sds_cp[(int)sds - 1]->shead;#endif}intsds_set_riscpad(sds_handle sds){ struct sds_header *h = sds_head(sds); if (h) h->controlbits |= SDS_IS_RISCY; return h?1:0;}struct direc *sds_direc(sds)sds_handle sds;{ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->dptr:0; }/* for backward compatibility with V1 */struct direc *sds_direc_ptr(sds)sds_handle sds;{ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->dptr:0; }struct type_list *sds_tlist(sds)sds_handle sds;{#if !defined(SDS_GO_FAST) return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->tlist:0; #else return ssc->sds_cp[(int)sds - 1]->tlist;#endif}shortsds_alloflag(sds)sds_handle sds;{ return sds_dataset_check(sds)?ssc->sds_cp[(int)sds - 1]->allofl:0;}/*********************************************************************/voidsds_init(VOIDDEF)/*********************************************************************/{ sds_global_init(MAX_SDS,ERRSTACK);}voidsds_global_init(maxsds,errstack)int maxsds,errstack;{ int i; struct tes { char a; double b; }; if (sds_initialised() && !sds_initialise_enabled()) return; if (!ssc) { ssc = (struct sds_sys_control *)malloc(sizeof(struct sds_sys_control)); ssc->controlbits = SDS_DOUBLE_LONGS_IN_LONGS; ssc->fd_buffer = 0; ssc->sds_cp = (struct sds_control_p **)malloc(maxsds * sizeof(struct sds_control_p *)); ssc->maxsds = maxsds; ssc->maxbufsize = SDS_DEFAULT_BUFSIZE; ssc->sec = (struct sds_error_control *)malloc(sizeof(struct sds_error_control)); ssc->sec->errstack = errstack; ssc->sec->se = (struct sds_err *)malloc(sizeof(struct sds_err) * errstack); } ssc->re_init = 0; if ((sizeof(struct tes) == 9 && (SDS_ARC != SDS_VAXARC)) || (sizeof(struct tes) == 10 && (SDS_ARC != SDS_SUN3ARC))) { fprintf(stderr, "Sds is using the wrong architecture!\n"); fprintf(stderr, "At present the only know way of this happening is if you \n"); fprintf(stderr,"are running on a DOS machine and have used the \n"); fprintf(stderr,"alignment switches on the complier and have not\n"); fprintf(stderr,"told sds; eg if the -a switch is used on the TurboC\n"); fprintf(stderr,"compiler you must also define TURBOWORD\n"); exit(1); }#if defined(__linux__) /* WHY? For Pete's sake? Well, the default Linux exception handling is not ieee, so one sets it or lots of things will die. Commaster also does this... */ __setfpucw(_FPU_IEEE);#endif for (i=0;i<sds_max();i++) ssc->sds_cp[i] = NULL; /****** Error stack initialisation *****//* This is where I am in the stack: -1 means no errors so the first push will take it to 0 */ ssc->sec->stack_level = -1;/* if a FATAL error is encountered, should the system exit? */ ssc->sec->exit_on_fatal = 1; ssc->sec->stack_overwritten = 0;/* Do I immediately output error reports ( >0 ) or not? */ ssc->sec->output_level = SDS_BE_QUIET; ssc->sec->proginfo = 0;}int sds_max(VOIDDEF){ return ssc->maxsds; }int sds_errstack(){ return ssc->sec->errstack; }/*********************************************************************/sds_handlenext_sds(VOIDDEF)/*********************************************************************/{ sds_handle sds = 0L; while (ssc->sds_cp[sds] != NULL) { if (sds == sds_max() - 1L) { sds_push_error(SDS_NO_SPC,SDS_ERROR, "Searching for free system table space"); return 0L; } sds++; } ssc->sds_cp[sds] = sds_new_scp(); return sds + 1L;}/* Make and initialise a new control structure */struct sds_control_p *sds_new_scp(VOIDDEF){ struct sds_control_p *scp = (struct sds_control_p *)malloc(sizeof(struct sds_control_p)); scp->allofl = (short)0; scp->stream = SDS_FILE_OP; scp->source = 0; scp->heap_size = 0; scp->direc_size = 0; scp->tree = 0; scp->file_offsets = (sds_handle *)0; scp->varel_count = (int **)0; scp->dup_size = 0L; scp->load_name = (char *)0; scp->target_name = (char *)0; scp->heap = (char *)0; scp->current_heap = (char *)0; scp->element_start = (char ***)0; scp->shead = (struct sds_header *)0; scp->tlist = (struct type_list *)0; scp->dptr = (struct direc *)0; scp->src = 0; scp->genarc = SDS_ARC; /*Lets assume it's native until we discover otherwise*/ scp->is_proto = 1; return scp;}/* ...and delete everything (Stuff inside already deleted) */voidsds_delete_scp(scp)struct sds_control_p *scp;{ char *tmp; int sds = 0L; while (ssc->sds_cp[sds++] != scp) if (sds == sds_max()) return; sds--; tmp = (char *)scp; ssc->sds_cp[sds] = NULL; free(tmp);}/*********************************************************************/sds_handlegood_sds(name)char *name;/*********************************************************************/{ int sds; if (!sds_initialised()) { fprintf(stderr,"Sds must be initialised with sds_init()"); exit(1); } else if (strcmp(name,"")) { for (sds = 0;sds < sds_max(); sds++) { if (sds_control(sds)) if (sds_control(sds)->dptr != NULL && !strcmp(name,sds_obind2name(sds,0L))) return (sds_handle)sds; } } return 0L;}/************* Error stack code *******************************************/voidshiftdown(VOIDDEF){ int i; ssc->sec->stack_overwritten = 1; for (i=1; i < sds_errstack(); i++) memcpy((char *)(&ssc->sec->se[i - 1]), (char *)(&ssc->sec->se[i]), sizeof(struct sds_err)); return;}/**************************************************************************//* Print out program info for the i'th entry on the stack */voidprintoutprog(i)int i;{ if (ssc->sec->se[i].line != -1) { fprintf(stderr, " From file %s line %d:\n", ssc->sec->se[i].filename, ssc->sec->se[i].line); if (errno != 0) { perror("Last system error"); errno = 0; } } return;}/**************************************************************************//* Print out the i'th entry on the stack */voidprintout(i)int i;{ if (i <= ssc->sec->stack_level) { if (ssc->sec->proginfo) printoutprog(i); fprintf(stderr,"%d: %s: %s (%s)\n", i, sds_error_levels[ssc->sec->se[i].errlevel], ssc->sec->se[i].errstring, sds_error_string[-ssc->sec->se[i].errcode]); if (ssc->sec->exit_on_fatal && ssc->sec->se[i].errlevel == SDS_FATAL) { fprintf(stderr, "Error reporting instructs exit\n"); exit(ssc->sec->exit_on_fatal & 0xff); } } return;}/**************************************************************************//* Push a new error onto the stack. We assume that errstring is zero terminated, but check to see if it is NULL*/intsds_push_lerror(errcode, errlevel, errstring, line, filename)int errcode,errlevel;char *errstring;int line;char *filename;{ /* A couple of safties first */ char temp = 0; if (errstring == (char *)0) /* Just in case */ errstring = &temp; if (errlevel >= SDS_ERROR) sds_error = errcode; /* for backward compatibility */ if (-errcode > SDS_MAX_ERR) /* This makes no sense for Sds */ { errcode = SDS_BAD_ERROR_REGISTERED; errlevel = SDS_FATAL; } /* If I'm at the end of the stack, I shift every entry down, thus loosing the deepest one. Otherwise I can increment the stack level */ if (ssc->sec->stack_level == sds_errstack() - 1) shiftdown(); else ssc->sec->stack_level++; /* OK, load the stack */ ssc->sec->se[ssc->sec->stack_level].errcode = errcode; ssc->sec->se[ssc->sec->stack_level].errlevel = errlevel; ssc->sec->se[ssc->sec->stack_level].line = line; strncpy(ssc->sec->se[ssc->sec->stack_level].errstring, errstring, ERRSTRINGLEN - 1); ssc->sec->se[ssc->sec->stack_level].errstring[ERRSTRINGLEN-1] = 0; strncpy(ssc->sec->se[ssc->sec->stack_level].filename, filename,ERRSTRINGLEN - 1); ssc->sec->se[ssc->sec->stack_level].filename[ERRSTRINGLEN-1] = 0; /* Verbose or not ? */ if (ssc->sec->output_level != SDS_BE_QUIET && errlevel >= ssc->sec->output_level) printout(ssc->sec->stack_level); /* And I say how deep the stack is now */ return ssc->sec->stack_level;}/**************************************************************************//* To put a user mark in the program */intsds_lmark(comment, line, filename)char *comment;int line;char *filename;{ return sds_push_lerror(SDS_USER_MARK, 0, comment, line, filename); }/**************************************************************************/int sds_last_error(VOIDDEF){ int i; if (ssc->sec->stack_level != -1) { for (i=ssc->sec->stack_level; i >= 0; i--) if (ssc->sec->se[i].errlevel == SDS_ERROR) return ssc->sec->se[i].errcode; } return 0;}/**************************************************************************/int sds_last_warning(VOIDDEF){ int i; if (ssc->sec->stack_level != -1) { for (i=ssc->sec->stack_level; i >= 0; i--) if (ssc->sec->se[i].errlevel == SDS_WARNING) return ssc->sec->se[i].errcode; } return 0;}/**************************************************************************/int sds_last_return(VOIDDEF){ if (ssc->sec->stack_level != -1) return ssc->sec->se[ssc->sec->stack_level].errcode; return 0;}/**************************************************************************/intsds_pop_error(errlevel, errstring)int *errlevel;char **errstring;{ int tempcode; if (ssc->sec->stack_level == -1) /* No errors */ return 0; *errlevel = ssc->sec->se[ssc->sec->stack_level].errlevel; tempcode = ssc->sec->se[ssc->sec->stack_level].errcode; *errstring = ssc->sec->se[ssc->sec->stack_level].errstring; ssc->sec->stack_level--; return tempcode;}/**************************************************************************/void sds_output_proginfo(truefalse)int truefalse;{ ssc->sec->proginfo = truefalse; }/**************************************************************************/void sds_exit_on_fatal(truefalse)int truefalse;{ ssc->sec->exit_on_fatal = truefalse; }/**************************************************************************/void sds_clear_errors(VOIDDEF){ ssc->sec->stack_level = -1; ssc->sec->stack_overwritten = 0; sds_error = 0; return;}/**************************************************************************/void sds_output_errors(level)int level;{ ssc->sec->output_level = level; }/**************************************************************************/void sds_perror(comment)char *comment;{ int i; if (ssc->sec->stack_overwritten) fprintf(stderr,"Warning: the stack grew too big, some errors lost\n\n"); fprintf(stderr,"\n%s", comment); if (ssc->sec->stack_level != -1) { fprintf(stderr,"\nError stack, last error first:\n"); for (i=sds_errstack() -1 ;i >= 0;i--) printout(i); } else { fprintf(stderr, "\nSds error stack is clear\n"); } if (errno != 0) { fprintf(stderr,"******** ********\n"); perror("Last system error"); } return;}/**************************************************************************/voidsds_stop_if_error(comment)char *comment;{ if (sds_last_error()) { sds_exit_on_fatal(0); sds_output_proginfo(1); sds_perror(comment); exit(1); } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -