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

📄 gen_collate.c

📁 一个嵌入式的C++库
💻 C
📖 第 1 页 / 共 5 页
字号:
								if (*t == '"') {									assert(!t[1]);									break;								}								n = is_ucode(t);								assert(n);								printf("%.*s", n, t);							} while (1);							printf("   collating-element %s\n", s);						} else {							printf("%6d: %s  (collating-symbol)\n", final_index, s);						}					}				}			}		}#endif		++final_index;	}}static int final_index_val0(const char *s){	ENTRY *p;	ENTRY e;	e.key = (char *) s;	if (!(p = hsearch(e, FIND))) {	/* not in the table */		return 0;	}	return (int)(p->data);}static int final_index_val(const char *s){	ENTRY *p;	ENTRY e;	e.key = (char *) s;	if (!(p = hsearch(e, FIND))) {	/* not in the table */		error_msg("can't find final index: %s", s);	}	return (int)(p->data);}static size_t num_tree_nodes;static void count_nodes(const void *ptr, VISIT order, int level){    if ((order == postorder) || (order == leaf))  {		++num_tree_nodes;    }}static size_t tnumnodes(const void *root){	num_tree_nodes = 0;	twalk(root, count_nodes);	return num_tree_nodes;}static ll_item_t *find_wi_index(const char *sym, col_locale_t *cl){	weighted_item_t w;	ll_item_t l;	void *p;	w.symbol = sym;	l.data = &w;	l.data_type = DT_WEIGHTED;	p = tfind(&l, &cl->root_wi_index, wi_index_cmp);	if (p) {		p = *(ll_item_t **)p;	}	return (ll_item_t *) p;}static void mark_reordered(const char *sym){	ll_item_t *lli;	lli = find_wi_index(sym, cur_base);	if (lli) {		if (!tsearch(lli, &cur_base->root_wi_index_reordered, wi_index_cmp)) {			error_msg("OUT OF MEMORY!");		}	}}static ll_item_t *find_wi_index_reordered(const char *sym){	weighted_item_t w;	ll_item_t l;	void *p;	w.symbol = sym;	l.data = &w;	l.data_type = DT_WEIGHTED;	p = tfind(&l, &cur_base->root_wi_index_reordered, wi_index_cmp);	if (p) {		p = *(ll_item_t **)p;	}	return (ll_item_t *) p;}static ll_item_t *init_comm_ptr(void){	assert(cur_base);	assert(cur_base->section_list);	/* at the moment, only support one section in comm */	assert(cur_base->section_list->next == NULL);	comm_cur_ptr = ((section_t *)(cur_base->section_list->data))->itm_list;	while (comm_cur_ptr && (comm_cur_ptr->data_type & DT_REORDER)) {		comm_cur_ptr = comm_cur_ptr->next;	}#warning devel code/* 	{ *//* 		ll_item_t *p = comm_cur_ptr; *//* 		fprintf(stderr, "init_comm_ptr\n"); *//* 		while (p != comm_cur_ptr) { *//* 			if (p->data_type & DT_WEIGHTED) { *//* 				fprintf(stderr, "%s", ((weighted_item_t *)p)->symbol); *//* 			} *//* 			p = p->next; *//* 		} *//* 	} */	assert(comm_cur_ptr);/* 	fprintf(stderr, "init_comm_ptr -- %s %p %p %p %d\n", *//* 			((weighted_item_t *)(comm_cur_ptr->data))->symbol, *//* 			comm_cur_ptr, comm_cur_ptr->prev, comm_cur_ptr->next, *//* 			ll_len(comm_cur_ptr)); */	comm_prev_ptr = NULL;	return comm_cur_ptr;}static ll_item_t *next_comm_ptr(void){	/* at the moment, only support one section in comm */	assert(cur_base->section_list->next == NULL);	comm_prev_ptr = comm_cur_ptr;    while (comm_cur_ptr && ((comm_cur_ptr = comm_cur_ptr->next) != NULL)) {		if (!(comm_cur_ptr->data_type & DT_REORDER)) {			break;		}	}	return comm_cur_ptr;}static int dump_count;#if 0static void dump_section(section_t *s, int mask, col_locale_t *der){	ll_item_t *lli;	ll_item_t *lli0;	weighted_item_t *w;	weight_t *p;	int i;	lli0 = lli = s->itm_list;	if (!lli0) {		return;	}	do {		if (!(lli->data_type & mask)) {			lli = lli->next;			continue;		}		if (lli->data_type & DT_WEIGHTED) {			++dump_count;			w = (weighted_item_t *)(lli->data);			p = w->weight;			printf("%6d: %s (%d) ", dump_count, w->symbol, p->num_weights);			for (i = 0 ; i < p->num_weights ; i++) {				if (p->rule[i] & R_FORWARD) {					printf("F");				}				if (p->rule[i] & R_BACKWARD) {					printf("B");				}				if (p->rule[i] & R_POSITION) {					printf("P");				}				printf(",");			}			for (i = 0 ; i < p->num_weights ; i++) {				printf("   %s", p->colitem[i]);			}			printf("\n");		} else if (lli->data_type & (DT_SECTION|DT_REORDER)) {			if (lli->data_type == DT_REORDER) {				assert(der);				if (strncmp(((section_t *)(lli->data))->name, der->name, strlen(der->name))) {					lli = lli->next;					continue;				}			}			if (lli->data_type & DT_SECTION) {				printf("SECTION -----------------\n");			} else {				printf("REORDER -----------------\n");			}			dump_section((section_t *)(lli->data), mask, der);			printf("DONE --------------------\n");		}		lli = lli->next;	} while (lli != lli0);}#elsestatic int in_reorder_section = 0;static void dump_section(section_t *s, int mask, col_locale_t *der){	ll_item_t *lli;	ll_item_t *lli0;	weighted_item_t *w;	weight_t *p;	int i;	lli0 = lli = s->itm_list;	if (!lli0) {		return;	}	do {		if (!(lli->data_type & mask)) {			lli = lli->next;			continue;		}		if (lli->data_type & DT_WEIGHTED) {			++dump_count;			w = (weighted_item_t *)(lli->data);			p = w->weight;#if 1			if (in_reorder_section) {				printf(" %p", w);			}#else			printf("%6d: %s (%d) ", dump_count, w->symbol, p->num_weights);			for (i = 0 ; i < p->num_weights ; i++) {				if (p->rule[i] & R_FORWARD) {					printf("F");				}				if (p->rule[i] & R_BACKWARD) {					printf("B");				}				if (p->rule[i] & R_POSITION) {					printf("P");				}				printf(",");			}			for (i = 0 ; i < p->num_weights ; i++) {				printf("   %s", p->colitem[i]);			}			printf("\n");#endif		} else if (lli->data_type & (DT_SECTION|DT_REORDER)) {			if (lli->data_type == DT_REORDER) {				assert(der);				if (strncmp(((section_t *)(lli->data))->name, der->name, strlen(der->name))) {					lli = lli->next;					continue;				}			}			if (lli->data_type & DT_SECTION) {/* 				printf("SECTION -----------------\n"); */				assert(0);			} else {/* 				printf("REORDER -----------------\n"); */				in_reorder_section = 1;			}			dump_section((section_t *)(lli->data), mask, der);/* 			printf("DONE --------------------\n"); */			printf("\n");			in_reorder_section = 0;		}		lli = lli->next;	} while (lli != lli0);}#endifstatic void dump_weights(const char *name){	ll_item_t *lli;	col_locale_t *base;	col_locale_t *der;	col_locale_t cl;	void *p;	assert(name);	if (!*name) {				/* use last */		base = cur_base;		der = cur_derived;	} else {		cl.name = (char *) name;		if (!(p = tfind(&cl, &root_col_locale, col_locale_cmp))) {			error_msg("unknown locale: %s", name);		}		base = *((col_locale_t **) p);		der = NULL;		if (base->base_locale) { /* oops... really derived */			der = base;			base = der->base_locale;		}	}	dump_count = 0;	if (base) {/* 		printf("BASE - %s\n", base->name); */		for (lli = base->section_list ; lli ; lli = lli->next) {/* 			printf("SECTION %s\n", ((section_t *)(lli->data))->name); */			dump_section((section_t *)(lli->data), ~0, der);		}	}	assert(der != base);	if (der) {/* 		printf("DERIVED - %s\n", der->name); */		for (lli = der->section_list ; lli ; lli = lli->next) {			if (lli->data_type == DT_SECTION) {				dump_section((section_t *)(lli->data), DT_WEIGHTED, der);			}		}	}/* 	printf("DONE\n"); */}static void print_starter_node(const void *ptr, VISIT order, int level){    if (order == postorder || order == leaf)  {		fprintf(stderr, "   %s\n", *(const char **) ptr);    }}static void finalize_base(void){	ll_item_t *s;	ll_item_t *h;	ll_item_t *lli;	ll_item_t *h2;	ll_item_t *l2;	ll_item_t *cli;	ll_item_t *rli = NULL;	weighted_item_t *w;	weight_t *p;	int i, n, mr, r, mi;	col_locale_t *cl;	void *mm;	int num_invariant = 0;	int num_varying = 0;	int max_weight;	int index2weight_len_inc = 1;	assert(cur_base);	assert(base_locale_len+1 < BASE_LOCALE_LEN);	base_locale_array[base_locale_len].name = cur_base->name;	base_locale_array[base_locale_len].num_weights = 1;	base_locale_array[base_locale_len].index2weight_offset = index2weight_len;	base_locale_array[base_locale_len].index2ruleidx_offset = index2ruleidx_len;	if (!strcmp(cur_base->name,"ja_JP") || !strcmp(cur_base->name,"ko_KR")) {#warning fix the index2weight check!!		index2weight_len_inc = 0;	}/* 	printf("%s -- index2weight_len = %d\n", cur_base->name, index2weight_len); */	if (!hcreate(30000)) {		error_msg("OUT OF MEMORY!");	}	/* first pass ... set the fixed indexes */	final_index = i = 1;	mr = 0;	for (s = cur_base->section_list ; s ; s = s->next) {#if 1		if (s->data_type & DT_REORDER) { /* a reordered section */			fprintf(stderr, "pass1: reordered section %s - xxx\n", ((section_t *)(s->data))->name);			lli = ((section_t *)(s->data))->itm_list;			r = 0;			if (lli) {/* 				r = ll_len( ((section_t *)(lli->data))->itm_list ); */				r = ll_len(lli) + 1;			}			if (r > mr) {				mr = r;			}			fprintf(stderr, "pass1: reordered section %s - %d\n", ((section_t *)(s->data))->name, r);			continue;		}#endif		h = lli = ((section_t *)(s->data))->itm_list;		if (!lli) {			continue;		}		do {			if (lli->data_type & DT_RANGE) {				i += mr;				mr = 0;#warning check ko_kR and 9/* 				++i; */				lli->idx = i;				assert(!rli);				rli = lli;				fprintf(stderr, "range pre = %d  after = ", i);				i += ((range_item_t *)(lli->data))->length + 1;#warning check ko_kR and 9/* 				++i; */				fprintf(stderr, "%d\n", i);				if (!index2weight_len_inc) { /* ko_KR hack */					final_index += ((range_item_t *)(lli->data))->length + 1;				}/* 				add_final_col_index("RANGE"); */			} else if (lli->data_type & DT_WEIGHTED) {				i += mr;				mr = 0;				w = (weighted_item_t *)(lli->data);				if (find_wi_index_reordered(w->symbol)) { /* reordered symbol so skip on first pass */					++num_varying;					++i;					continue;				}				++num_invariant;				index2weight_buffer[index2weight_len] = lli->idx = i++;				index2weight_len += index2weight_len_inc;				add_final_col_index(w->symbol);							} else {				assert(lli->data_type & DT_REORDER);				r = ll_len( ((section_t *)(lli->data))->itm_list );#warning check ko_kR and 9				if (r > mr) {					mr = r;				}/* 				r = 0; */			}		} while ((lli = lli->next) != h);	}	/* second pass ... set the reordered indexes */	mi = i + mr;	mr = i = 0;	for (s = cur_base->section_list ; s ; s = s->next) {		h = lli = ((section_t *)(s->data))->itm_list;		if (!lli) {			continue;		}		do {			if (lli->data_type & DT_RANGE) {				i += mr;				mr = 0;				i = lli->idx + ((range_item_t *)(lli->data))->length + 1;#warning check			} else if ((lli->data_type & DT_WEIGHTED) && !(s->data_type & DT_REORDER)) {				i += mr;				mr = 0;				w = (weighted_item_t *)(lli->data);				if (find_wi_index_reordered(w->symbol) /* reordered symbol skipped on first pass */#if 0					|| (s->data_type & DT_REORDER) /* or in a reordered section */#endif					) {					assert(!(s->data_type & DT_REORDER));					index2weight_buffer[index2weight_len] = lli->idx = ++i;					index2weight_len += index2weight_len_inc;					add_final_col_index(w->symbol);/* 					fprintf(stdout, "%11s: r %6d %6d %s\n", *//* 							cur_base->name, lli->idx, final_index_val(w->symbol), w->symbol); */					continue;				}				i = lli->idx;/* 				fprintf(stdout, "%11s: w %6d %6d %s\n", *//* 						cur_base->name, lli->idx, final_index_val(w->symbol), w->symbol); */			} else {/* 				fprintf(stderr, "section: %s  %d  %d\n", ((section_t *)(s->data))->name, *//* 						s->data_type, lli->data_type); *//* 					assert(!(s->data_type & DT_REORDER)); *//* 				assert(lli->data_type & DT_REORDER); */#if 1				if (s->data_type & DT_REORDER) {					h2 = l2 = lli;					if (!h2) {						continue;					}				} else {					assert(s->data_type & DT_SECTION);					h2 = l2 = ((section_t *)(lli->data))->itm_list;					if (!h2) {						continue;					}				}#else				h2 = l2 = ((section_t *)(lli->data))->itm_list;				if (!h2) {					continue;				}#endif				r = 0;				do {					assert(l2->data_type & DT_WEIGHTED);					++r;					l2->idx = i + r;/* 					fprintf(stdout, "%s: R %6d        %s\n", *//* 							((section_t *)(lli->data))->name, l2->idx, ((weighted_item_t *)(l2->data))->symbol); */				} while ((l2 = l2->next) != h2);				if (r > mr) {					mr = r;				}			}		} while ((lli = ll

⌨️ 快捷键说明

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