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

📄 uerfdbc.c

📁 <B>Digital的Unix操作系统VAX 4.2源码</B>
💻 C
📖 第 1 页 / 共 4 页
字号:
				} else if( !strcasecmp(word1, "LABEL") ) {					sreg->label = ep_malloc(strlen(ls));					strcpy(sreg->label, "");					if(!copy_quote_str(sreg->label, ls+strlen("LABEL"), 0))						err("sitem", "LABEL");				} else if( !strcasecmp(word1, "DISPLAY") ) {						sreg->label_type =							decode_type(ls+strlen("DISPLAY"), df_table);				} else if( !strcasecmp(word1, "MAP") ) {					while(readline()) {						if(!strlen(ls))							return;						if( !strcasecmp(word1, "field") )							{ reread =1 ; break; }#ifdef REQUIRE_INDENTED						if(!indented) /* register map fields must be indented */							{ reread =1 ; goto reg_field_b; }#endif#ifdef OLD_						if( word1[0] == ':' )							{ reread =1 ; break; }#endif						{						char *cp;						struct std_reg_field_index *cp_m, *sr;						int tcount;						cp_m = (struct std_reg_field_index *)								ep_malloc(sizeof(struct std_reg_field_index));						if(!sreg->map_std_reg_field_index) {							sreg->map_std_reg_field_index = cp_m;						} else {							tcount = 0;								/* find last on list */							for(sr=sreg->map_std_reg_field_index;								sr && sr->next; sr=sr->next)									tcount++;				/* the following check is unnecessary.					It was intended as an extra safety					against programming errors. */if( !sr || tcount != sreg->map_std_reg_field_index_count -1 ) {	print_where();	errval = 1;	fprintf(stderr,"  Error, internal map_std_reg_field_index loop failure \n");	fprintf(stderr,"  tcount=%d map_std_reg_field_index_count=%d\n",			tcount, sreg->map_std_reg_field_index_count); 	break;}							sr->next = cp_m;						}						sreg->map_std_reg_field_index_count++;						cp_m->next = 0;									/* pick up value */						if (sscanf(ls, "%lu", &cp_m->value) != 1)								{ err("sitem", ls); break;}												cp_m->label = ep_malloc(strlen(ls));						cp = ls + strspn(ls, "0123456789");									/* pick up label */						if( !copy_quote_str(cp_m->label, cp, 0) )							err("sitem", ls);						}					}				} else if( !strcasecmp(word1, "doc") ) {					sreg->doc = ep_malloc(strlen(ls));					if(!copy_quote_str(sreg->doc,ls+strlen("doc"),0))						err("sitem", "doc");				} else if( !strcasecmp(word1, "field") ) {					{ goto reg_field; }				} else {					print_where();					errval = 1;					fprintf(stderr, "Error, unrecognized reg field line\n");				}			}		} else {			reread=1; return;		}	}}read_std_segment(){	int state_reading_elements = 0;	/* true while reading elements */	sseg = (struct std_segment *)ep_malloc(sizeof(struct std_segment));	cnt_std_segs++;	if( last_sseg )		last_sseg->next = sseg;	last_sseg = sseg;	if( !first_sseg )		first_sseg = sseg;		/* clear fields here */	sseg->next = 0;	sseg->type = -1;	sseg->type_id = -1;	sseg->name = "";	sseg->label = "";	sseg->doc = "";	sseg->elements = 0;	sseg->elements_count = 0;	state_reading_elements = 0;	while(readline()) {		char tbuf[12];		if(!strlen(ls))			return;		if( !indented && strcasecmp(word1, "ELEMENTS") )			state_reading_elements = 0;	/* no longer reading elements */		if( !strcasecmp(word1, "ID") ) {			if( opt_auto_assign ) {				if(sscanf(ls, "%*[Ii]%*[Dd] %10s", tbuf) != 1 ) 					err("sseg", "ID");			} else {				if(sscanf(ls, "%*[Ii]%*[Dd] %10s %d", tbuf, &sseg->type_id) != 2 ) 					err("sseg", "ID");			}			sseg->type = decode_type(tbuf, seg_table);			if( sseg->type > MAX_SEG_INDEX ) {				fprintf(stderr, "Error, sseg->type (%d) too large\n", sseg->type);				errval = 1;			} else if( opt_auto_assign ) {				sseg->type_id = next_sseg_type_id[sseg->type]++;			}		} else if( !strcasecmp(word1, "NAME") ) {			sseg->name = ep_malloc(strlen(ls));			if(sscanf(ls, "%*[Nn]%*[Aa]%*[Mm]%*[Ee] %s", sseg->name) != 1 )				err("sseg", "NAME");		} else if( !strcasecmp(word1, "LABEL") ) {			sseg->label = ep_malloc(strlen(ls));			if(!copy_quote_str(sseg->label, ls+strlen("LABEL"), 0))				err("sseg", "LABEL");		} else if( !strcasecmp(word1, "ELEMENTS") ) {			state_reading_elements = 1;		} else if( !strcasecmp(word1, "doc") ) {			sseg->doc = ep_malloc(strlen(ls));			if(!copy_quote_str(sseg->doc, ls+strlen("doc"), 1))				err("sseg", "doc");		} else {			if( state_reading_elements ) {					/* pick up each word from the line */				for(cp=ls; *cp; ) {					struct std_segment_element *se;					int len;					sse = (struct std_segment_element *)							ep_malloc(sizeof(struct std_segment_element ));					sseg->elements_count++;					if( !sseg->elements )						sseg->elements = sse;					else {						/* find last element */						for(se=sseg->elements; se && se->next; se=se->next)							;						se->next = sse;					}					sse->next = 0;					len = strcspn(cp," \t");	/* word ends at whitespace */					sse->name = ep_malloc(len+1);					strncpy(sse->name, cp, len);					sse->name[len] = '\0';					cp+=len;					while( *cp && (*cp == ' ' || *cp == '\t' ))						cp++;				}			} else {				reread=1; return;			}		}	}}read_os_item(){	oitem = (struct os_item *)ep_malloc(sizeof(struct os_item));	cnt_os_items++;	if( last_oitem )		last_oitem->next = oitem;	last_oitem = oitem;	if( !first_oitem )		first_oitem = oitem;		/* clear fields here */	oitem->next = 0;	if( opt_auto_assign )		oitem->id = next_oitem_id++;	else		oitem->id = -1;	oitem->name = "";	oitem->type = -1;	oitem->class = -1;	oitem->size = -1;	oitem->doc = 0;	oitem->map = 0;	oitem->map_count = 0;	while(readline()) {		if(!strlen(ls)) {			return;		} else if( !strcasecmp(word1, "POINTER") ) {		} else if( !strcasecmp(word1, "RANGE") ) {		} else if( !strcasecmp(word1, "LIST") ) {		} else if( !strcasecmp(word1, "DEFAULT") ) {		} else if( !strcasecmp(word1, "ID") ) {			if( !opt_auto_assign )				if(sscanf(ls, "%*[Ii]%*[Dd] %d", &oitem->id) != 1 ) 					err("sitem", "ID");		} else if( !strcasecmp(word1, "NAME") ) {			oitem->name = ep_malloc(strlen(ls));			if(sscanf(ls, "%*[Nn]%*[Aa]%*[Mm]%*[Ee] %s", oitem->name) != 1 )				err("sitem", "NAME");		} else if( !strcasecmp(word1, "TYPE") ) {			oitem->type = decode_type(ls+strlen("TYPE"), dt_table);		} else if( !strcasecmp(word1, "CLASS") ) {			oitem->class = decode_type(ls+strlen("CLASS"), dc_table);		} else if( !strcasecmp(word1, "SIZE") ) {			if(sscanf(ls, "%*[Ss]%*[Ii]%*[Zz]%*[Ee] %d", &oitem->size) != 1 )				err("sitem", "SIZE");		} else if( !strcasecmp(word1, "doc") ) {			oitem->doc = ep_malloc(strlen(ls));			if(!copy_quote_str(oitem->doc, ls+strlen("doc"), 0))				err("sitem", "doc");		} else if( !strcasecmp(word1, "MAP") ) {			if( oitem->type == DT_SHORT_INDEX || oitem->type == DT_INDEXED ||				oitem->type == DT_TINY_INDEX ){				while(readline()) {					if(!strlen(ls))						return;#ifdef OLD_					if(word1[0] == ':')						{ reread=1; break; }#endif					{					char *cp;					struct os_index *cp_m, *oi;					int tcount;					cp_m = (struct os_index *)								ep_malloc(sizeof(struct os_index));					if(!oitem->map) {						oitem->map = cp_m;					} else {						for(oi=oitem->map; oi && oi->next; oi=oi->next)							;						if( !oi ) {							print_where();			   				fprintf(stderr, "  Error, internal map loop failure ");							errval = 1;			   				break;						}						oi->next = cp_m;					}					oitem->map_count++;					cp_m->next = 0;					cp_m->std_value = 0;					cp_m->std_name = ep_malloc(strlen(ls));					if(sscanf(ls, "%lu %s", &cp_m->os_value,cp_m->std_name)!=2)							{ err("oitem", ls); break;}					}				}			}		} else {			reread=1; return;		}	}}err(state, line)char *state, *line;{	if( !strcasecmp(state, "sitem") ) {		print_where();		errval = 1;		fprintf(stderr, "  Error, error in std-item %s(%d)\n",			sitem->name, sitem->id);	} else if( !strcasecmp(state, "sseg") ) {		print_where();		errval = 1;		fprintf(stderr, "  Error, error in std-segment %s(%d-%d) \n",			sseg->name, sseg->type, sseg->type_id);	} else if( !strcasecmp(state, "oitem") ) {		print_where();		errval = 1;		fprintf(stderr, "  Error, error in os-item %s(%d)\n",			oitem->name, oitem->id);	}}struct dx_struct dt_table[] = {  { DT_SHORT, "SHORT" },  { DT_LONG, "LONG" },  { DT_STRING, "STRING" },  { DT_SHORT_INDEX, "SHORT_INDEX" },  { DT_INDEXED, "INDEXED" },  { DT_SHORT_REGISTER, "SHORT_REGISTER" },  { DT_REGISTER, "REGISTER" },  { DT_DATE, "DATE" },  { DT_BYTE_VECTOR, "BYTE_VECTOR" },  { DT_COUNTED_SHORT_VECTOR, "COUNTED_SHORT_VECTOR" },  { DT_COUNTED_LONG_VECTOR, "COUNTED_LONG_VECTOR" },  { DT_ADDR_CNT_VECTOR, "ADDR_CNT_VECTOR" },  { DT_TINY, "TINY" },  { DT_TINY_INDEX, "TINY_INDEX" },  { DT_ASCIZ, "ASCIZ" },  { DT_BIT_VECTOR, "BIT_VECTOR" },  { DT_SHORT_VECTOR, "SHORT_VECTOR" },  { DT_LONG_VECTOR, "LONG_VECTOR"},  { DT_VMS_TIME, "VMS_TIME"},  { 0, ""}};struct dx_struct dc_table[] = {  { DC_INTEGER, "INTEGER" },  { DC_FLOAT, "FLOAT" },  { DC_CODED, "CODED" },  { DC_CHARACTER, "CHARACTER" },  { DC_TIME, "TIME" },  { DC_COMPOSITE, "COMPOSITE" },  { DC_FILLER, "FILLER" },  { DC_BYTES, "BYTES" },  { DC_BITS, "BITS" },  { 0, ""}};struct dx_struct df_table[] = {  { DF_DEFAULT, "NIL"},  { DF_DECIMAL, "DECIMAL" },  { DF_HEX, "HEX" },  { DF_OCTAL, "OCTAL" },  { DF_DATE_TIME, "DATE_TIME" },  { DF_E_TIME, "E_TIME" },  { DF_HEX_DUMP, "HEX_DUMP" },  { 0, ""}};struct dx_struct seg_table[] = {	{ 1, "EIS"},          /* Event Identification Segment */	{ 2, "DIS"},          /* Device Information Segment */	{ 3, "SDS"},          /* Supporting Data Segment */	{ 4, "CDS"},          /* Correlating Data Segment */	{ 5, "ADS"},          /* Additional Data Segment */	{ 6, "SIS"},          /* Summary Information Segment */	{ 7, "CIS"},          /* Configuration Information Segment */		/* note: if extending this table, MAX_SEG_NUM must be adjusted */  { 0, ""}};	/* lookup string in table to get value */decode_type(s, table)char *s;struct dx_struct *table;{	int len;	struct dx_struct *dt;	while(*s && (*s == ' ' || *s == '\t'))		s++;	for( dt=table; len=strlen(dt->string); dt++ ) {		if( !strncasecmp(s, dt->string, len) &&			(s[len] == '\0' || s[len] == ' ' ||			 s[len] == '\t' || s[len] == '\n')) {				return(dt->value);			}	}	print_where();	errval = 1;	fprintf(stderr, "  Error, unable to decode %s\n", s);	return(-1);}	/* lookup value in table to get string */char *encode_type(a, table)int a;struct dx_struct *table;{	int len;	struct dx_struct *dt;	for( dt=table; len=strlen(dt->string); dt++ ) {		if( a == dt->value )			return(dt->string);	}	/* fprintf(stderr, "  Error, unable to encode %d\n", a); */	return("<UNKNOWN>");}	/* copy the quoted string from s to d , without the quotes */	/* Allow case of only whitespace present. */	/* Return true if ok, false if error */copy_quote_str(d, s, nil_flg)char *d, *s;int nil_flg;{	char quote_char;	*d = '\0';	while(*s && (*s == ' ' || *s == '\t'))		s++;	if( !*s )		return(1);	if( *s != '"' && *s != '\'') {				/* special case.  NILL is found once in the 					vmslisp-generated file and we want to match					that file, so we need this line here. */		if( !strncasecmp(s, "NILL", 4) ) {			strcpy(d, "NILL");			return(1);		}		if( !strncasecmp(s, "NIL", 3) ) {			if( nil_flg )				strcpy(d, "NIL");			return(1);		}		return(0);	}	quote_char = *s;	s++;	while(*s && *s != quote_char && *s != '\n') {		if( *s == '\\' )			s++;		*d++ = *s++;	}	if( *s && *s == quote_char)		return(1);	else		return(0);}	/* this function dumps the database */	/* It was used when developing this prog to check that		the database was parsed correctly, prior to writing		the code to output the .h and bin files. */	/* It may no longer serve a useful purpose. */output_all(){	int tcount =0;	struct std_index *si;	struct std_reg_field *sr;	struct std_reg_field_index *sri;	struct std_segment_element *sse;	struct os_index *oi;	printf("#std_items=%d #std_segs=%d #os_items=%d\n",			cnt_std_items, cnt_std_segs, cnt_os_items);	for(sitem = first_sitem; sitem; sitem = sitem->next) {		tcount++;		printf("std item %s (%d) type %d\n",			sitem->name, sitem->id, sitem->type);		printf("  class %d, size %d\n", sitem->class, sitem->size);		printf("  label_type %d, label=%s\n", sitem->label_type, sitem->label);		printf("  documentation=%s\n", sitem->doc);		if (sitem->type == DT_SHORT_INDEX || sitem->type == DT_INDEXED) {			for(si=sitem->map_index; si ; si=si->next) {				printf("      %lu  %s  %s\n",					si->value, si->name, si->label);			}		}		if (sitem->type == DT_SHORT_REGISTER || sitem->type == DT_REGISTER) {			for(sr=sitem->map_reg; sr; sr=sr->next) {				printf("      %s, size %d, class %d, l_type %d\n      %s\n",					sr->label? sr->label: "",					sr->size, sr->class, sr->label_type,					sr->doc? sr->doc: "");				for(sri=sr->map_std_reg_field_index; sri; sri=sri->next)					printf("         %lu \"%s\"\n", sri->value, sri->label);			}		}	}	printf("count = %d    confirm count = %d\n", cnt_std_items, tcount);

⌨️ 快捷键说明

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