📄 uerfdbc.c
字号:
#ifndef lintstatic char sccsid[] = "@(#)uerfdbc.c 4.2 (ULTRIX) 10/16/90";#endif lint#include <stdio.h>#include "generic_dsd.h"struct std_item { struct std_item *next; char *name; int id; int type; int class; int size; char *label; int label_type; struct std_index *map_index; /* pointer to index list */ int map_index_count; struct std_reg_field *map_reg; /* pointer to register_field list */ int map_reg_count; char *doc; /* comments */};struct std_index { struct std_index *next; unsigned long value; /* (position in list, for old style assignment) */ char *name; char *label; char *label_plain; /* this one doesn't have convert_toupper done */};struct std_reg_field { struct std_reg_field *next; int class; int size; char *label; int label_type; struct std_reg_field_index *map_std_reg_field_index; int map_std_reg_field_index_count; char *doc;};struct std_reg_field_index { struct std_reg_field_index *next; unsigned long value; char *label;};struct std_segment { struct std_segment *next; int type; /* ID field 1 (e.g., CDS, ADS,...) */ int type_id; /* ID field 2 (e.g., 65, 67, 15, ...) */ char *name; char *label; char *doc; struct std_segment_element *elements; int elements_count;};struct std_segment_element { struct std_segment_element *next; char *name; int id; /* id of the std_item with name. */};struct os_item { struct os_item *next; int id; char *name; int type; int class; int size; char *doc; struct os_index *map; int map_count;};struct os_index { struct os_index *next; unsigned long os_value; unsigned long std_value; char * std_name;}; /* for translating strings into values */extern struct dx_struct { int value; char *string;} df_table[], dt_table[], dc_table[], seg_table[];char *ep_malloc(), *malloc();char *strpbrk();char *readline();unsigned long find_id_of_index();extern char *std_h_fixed1[], *std_h_fixed2[], *std_h_fixed3[];extern char *os_h_fixed1[], *os_h_fixed2[];char *encode_type(); /* current pointers */struct std_item *sitem, *last_sitem, *first_sitem;struct std_reg_field *sreg, *last_sreg, *first_sreg;struct std_segment *sseg, *last_sseg, *first_sseg;struct os_item *oitem, *last_oitem, *first_oitem;struct std_segment_element *sse, *last_sse, *first_sse;FILE *std_h, *os_h, *bin_out;int lineno = 0; /* current line number of input */int cnt_std_items, cnt_std_segs, cnt_os_items; /* globals set by readline() */#define LINEBUF_SIZ 800char linebuf[LINEBUF_SIZ+2];#define WORD1_SIZ 50char word1[WORD1_SIZ+2];char *ls; /* line start - beginning of line after skipping whitespace */int indented; /* indented line ? 1 or 0 */int reread; /* just read previous line again */char *cp, *cp2;int opt_d = 0; /* debug option */int opt_i = 0; /* use old method of index value assignment (by position) */int opt_j = 0; /* issue warning if input index value differs from position */int opt_auto_assign = 0;/* auto assignment of id numbers */#define BIN_NAME "ultrix_dsd.bin"#define STD_H_NAME "std_dsd.h"#define OS_H_NAME "os_dsd.h"char *cmd_name; /* command name used to invoke this program */char **db_files = 0; /* list of database input files */char *in_name = 0;/* current input database file name */FILE *db_fp = 0; /* FILE * for current input database file */ /* for automatic assignment of id numbers */int next_sitem_id = 1;#define MAX_SEG_INDEX 7int next_sseg_type_id[MAX_SEG_INDEX+2]; /* +1 for zero element, +1 safety */int next_oitem_id = 1;int uerf_version = 0; /* version to keep uerf program in sync with database */int errval = 0; /* error code return value */main(argc, argv, arge)int argc;char **argv, arge;{ int same_block = 0; /* for unrecognized line, we only output the first unrecognized line in a block of lines */ init_vars(); /* initialize some vars */ process_args(argc, argv, arge); while(readline()) { if(!strlen(ls)) { same_block = 0; continue; } if( !strcasecmp(word1, "sitem") ) { same_block = 0; read_std_item(); } else if( !strcasecmp(word1, "sseg") ) { same_block = 0; read_std_segment(); } else if( !strcasecmp(word1, "oitem") ) { same_block = 0; read_os_item(); } else if( !strcasecmp(word1, "version") ) { same_block = 0; read_version(); } else { if( same_block ) continue; print_where(); fprintf(stderr, " Error, Unrecognized keyword or not in an item or segment\n"); errval = 1; same_block = 1; } } check_data(); output_data(); /* output the data file */ output_h(); /* output the include files */ /* output_all(); */ exit(errval);}init_vars(){ int i; sitem = last_sitem = first_sitem = 0; sreg = last_sreg = first_sreg = 0; sseg = last_sseg = first_sseg = 0; oitem = last_oitem = first_oitem = 0; sse = last_sse = first_sse = 0; for(i=1; i<= MAX_SEG_INDEX; i++) next_sseg_type_id[i] = 1; } /* read next line from input file(s) */ /* INPUT parameter: if reread is set, re-read the previous line. OUTPUT values: ls points to first non-null char in line. word1 array contains a copy of the first word from line. indented is true if line begins with whitespace. returns pointer to word1 array. */char *readline(){ if( reread ) { reread = 0; return(word1); }reget: /* we 'goto' here only when had comment line, to get a new line */ strcpy(word1, ""); ls = 0; indented = 0; /* get a line into linebuf */ while( !db_fp || NULL == fgets(linebuf, LINEBUF_SIZ, db_fp) ) { /* need to get open next file */ if( !*db_files ) return(0); /* there is no next file */ in_name = *db_files++; lineno = 0; if( NULL == (db_fp=fopen(in_name, "r")) ) { fprintf(stderr, "Error, Unable to open file %s\n", in_name); errval = 1; } } lineno++; if(opt_d) fprintf(stderr, "File %s, line %d: %s", in_name, lineno, linebuf); /* remove trailing newline and whitespace */ for( cp= &linebuf[strlen(linebuf)-1]; *cp && cp >= linebuf && (*cp == '\n' || *cp == ' ' || *cp == '\t'); cp--) *cp = 0; if( linebuf[strlen(linebuf)] == '\n' ) linebuf[strlen(linebuf)] = '\0'; /* skip white space */ for(ls=linebuf; *ls && (*ls == ' ' || *ls == '\t'); ls++ ) indented=1; if( *ls == '#' ) /* comment line ? */ goto reget; /* pick up first word into 'word1' */ for( cp=word1, cp2=ls; *cp2 && cp-word1 < WORD1_SIZ && *cp2 != ' ' && *cp2 != '\t'; cp2++) *cp++ = *cp2; *cp = '\0'; return(word1);} /* read in the version number of the db */read_version(){ if(sscanf(ls, "version %d", &uerf_version) != 1 ) { print_where(); fprintf(stderr, "Error, bad version number\n"); errval = 1; }}read_std_item(){ /* allocate a std_item */ sitem = (struct std_item *)ep_malloc(sizeof(struct std_item)); cnt_std_items++; if( last_sitem ) last_sitem->next = sitem; last_sitem = sitem; if( !first_sitem ) first_sitem = sitem; /* register fields are local to a std_item */ /* so dont carry over from previous std_items */ sreg = last_sreg = first_sreg = 0; /* clear fields here */ sitem->next = 0; sitem->name = ""; if( opt_auto_assign ) sitem->id = next_sitem_id++; else sitem->id = -1; sitem->type = -1; sitem->class = -1; sitem->size = -1; sitem->label = ""; sitem->label_type = -1; sitem->map_index = 0; sitem->map_index_count = 0; sitem->map_reg = 0; sitem->map_reg_count = 0; sitem->doc = 0; while(readline()) { if(!strlen(ls)) { /* null line ends this std item */ 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 ) /* ignore ID if prog assigns id's */ if(sscanf(ls, "%*[Ii]%*[Dd] %d", &sitem->id) != 1 ) err("sitem", "ID"); } else if( !strcasecmp(word1, "NAME") ) { sitem->name = ep_malloc(strlen(ls)); if(sscanf(ls, "%*[Nn]%*[Aa]%*[Mm]%*[Ee] %s", sitem->name) != 1 ) err("sitem", "NAME"); } else if( !strcasecmp(word1, "TYPE") ) { sitem->type = decode_type(ls+strlen("TYPE"), dt_table); } else if( !strcasecmp(word1, "CLASS") ) { sitem->class = decode_type(ls+strlen("CLASS"), dc_table); } else if( !strcasecmp(word1, "SIZE") ) { if(sscanf(ls, "%*[Ss]%*[Ii]%*[Zz]%*[Ee] %d", &sitem->size) != 1 ) err("sitem", "SIZE"); } else if( !strcasecmp(word1, "LABEL") ) { sitem->label = ep_malloc(strlen(ls)); if(!copy_quote_str(sitem->label, ls+strlen("LABEL"), 0)) err("sitem", "LABEL"); } else if( !strcasecmp(word1, "DISPLAY") ) { sitem->label_type = decode_type(ls+strlen("DISPLAY"), df_table); } else if( !strcasecmp(word1, "doc") ) { sitem->doc = ep_malloc(strlen(ls)); if(!copy_quote_str(sitem->doc, ls+strlen("doc"), 0)) err("sitem", "doc"); } else if( !strcasecmp(word1, "MAP") ) { if( sitem->type == DT_SHORT_INDEX || sitem->type == DT_INDEXED ){ while(readline()) { if(!strlen(ls)) return; /* null line ends this std item */#ifdef OLD_ if(word1[0] == ':') { reread=1; break; }#endif { char *cp; struct std_index *cp_m, *si; int tcount; /* allocate and link in std_index struct */ cp_m = (struct std_index *) ep_malloc(sizeof(struct std_index)); if(!sitem->map_index) { sitem->map_index = cp_m; } else { tcount = 0; /* get to last one on list */ for(si=sitem->map_index; si && si->next; si=si->next) tcount++; /* the following check is unnecessary. It was intended as an extra safety against programming errors. */ if( !si || tcount != sitem->map_index_count -1 ) { print_where(); errval = 1; fprintf(stderr, " Error, internal map_index loop failure "); fprintf(stderr, " tcount=%d map_index_count=%d\n", tcount, sitem->map_index_count); break; } si->next = cp_m; } sitem->map_index_count++; cp_m->next = 0; /* if option 'i', then we use the old method, which is to determine the value by the position of the entry in the list (first is one, second is two, etc.). Also, we allow, but do not require the presence of nor use, an assignment number in the line. if NOT option 'i', then we get the number from the line itself. Further, if option 'j', we issue a warning if the number in the line is not the same as the number that we would have assigned using the old method (value by position). */ /* pick up and interpret the number, if found. */ /* Bump ls past this, and over to the next field */ cp_m->value = 0; sscanf(ls, "%d", &cp_m->value); while( (*ls >= '0' && *ls <= '9') || *ls == ' ' || *ls == '\t') ls++; if( opt_i ) cp_m->value = (long)sitem->map_index_count; else { if(!cp_m->value) { print_where(); errval = 1; fprintf(stderr, " Error, missing or bad index value\n"); } if( opt_j && cp_m->value != sitem->map_index_count ){ print_where(); fprintf(stderr," warning: index value(%d) inconsistent with input line position(%d)\n", cp_m->value, sitem->map_index_count); } } cp_m->name = ep_malloc(strlen(ls)); if (sscanf(ls, "%s", cp_m->name) != 1) { err("sitem", ls); break;} cp_m->label = ep_malloc(strlen(ls)); if( !copy_quote_str(cp_m->label, ls+strlen(cp_m->name), 0) ) err("sitem", ls); cp_m->label_plain = ep_malloc(strlen(ls)); if( !copy_quote_str(cp_m->label_plain, ls+strlen(cp_m->name), 0) ) err("sitem", ls); } } } } else if( !strcasecmp(word1, "field") ) {reg_field: /* start register field */ sreg = (struct std_reg_field *) ep_malloc(sizeof(struct std_reg_field)); if( last_sreg ) last_sreg->next = sreg; last_sreg = sreg; if( !first_sreg ) first_sreg = sreg; /* link into the current standard item */ if( !sitem ) { print_where(); fprintf(stderr,"Error, no current std item\n"); errval = 1; break; } if( !sitem->map_reg ) { sitem->map_reg = sreg; sitem->map_reg_count = 0; } sitem->map_reg_count++; sreg->next = 0; /* clear fields */ sreg->class = -1; sreg->size = -1; sreg->label = ""; sreg->label_type = -1; sreg->map_std_reg_field_index = 0; sreg->map_std_reg_field_index_count = 0; sreg->doc = 0; while(readline()) { if(!strlen(ls)) return;reg_field_b:#ifdef REQUIRE_INDENTED if( !indented ) { reread=1; break; }#endif if( !strcasecmp(word1, "CLASS") ) { sreg->class = decode_type(ls+strlen("CLASS"),dc_table); } else if( !strcasecmp(word1, "SIZE") ) { if(sscanf(ls, "%*[Ss]%*[Ii]%*[Zz]%*[Ee] %d", &sreg->size) != 1 ) err("sitem", "SIZE");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -