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

📄 gen_collate.c

📁 一个嵌入式的C++库
💻 C
📖 第 1 页 / 共 5 页
字号:
	wi = xmalloc(sizeof(weighted_item_t));	wi->symbol = t;	wi->weight = register_weight(&w);	if ((i = is_ucode(t)) != 0) {		assert(!t[i]);		add_colitem(t, NULL);	}	return wi;}static void add_superset_weight(char *t){	ll_item_t *lli;	weighted_item_t *wi;	if (!comm_cur_ptr		|| (strcmp(t, ((weighted_item_t *)(comm_cur_ptr->data))->symbol) != 0)		) {						/* now out of sync */		if (superset_in_sync) {	/* need a new section */			superset_in_sync = 0;			cur_section = new_section("R");			cur_num_weights = cur_section->num_rules				= ((section_t *)(cur_base->section_list->data))->num_rules;			memcpy(cur_rule,				   ((section_t *)(cur_base->section_list->data))->rules,				   MAX_COLLATION_WEIGHTS);			memcpy(cur_section->rules,				   ((section_t *)(cur_base->section_list->data))->rules,				   MAX_COLLATION_WEIGHTS);			insque(new_ll_item(DT_REORDER, cur_section), find_ll_last(cur_col->section_list));			assert(comm_prev_ptr);			lli = new_ll_item(DT_REORDER, cur_section);			lli->prev = lli->next = lli;			insque(lli, comm_prev_ptr);/* 			fprintf(stderr, "  subsection -----------------------\n"); */		}/* 		fprintf(stderr, "     %s   %s\n", t, ((weighted_item_t *)(comm_cur_ptr->data))->symbol); */		wi = add_weight(t);		lli = new_ll_item(DT_WEIGHTED, wi);		mark_reordered(wi->symbol);		/* 			printf("reorder: %s\n", t); */		if (!cur_section->itm_list) {			cur_section->itm_list = lli;			lli->prev = lli->next = lli;			++cur_section->num_items;		} else {			insque(lli, cur_section->itm_list->prev);			++cur_section->num_items;		}		add_wi_index(lli);	} else {					/* in sync */		superset_in_sync = 1;		next_comm_ptr();	}}static void do_weight(char *t){	weighted_item_t *wi;	ll_item_t *lli;	if (superset) {		add_superset_weight(t);		return;	}	switch(order_state) {		case 0:/* 			fprintf(stdout, "no-order weight: %s\n", t); *//* 			break; */		case IN_ORDER:			/* in a section *//* 			fprintf(stdout, "weight: %s\n", t); */			wi = add_weight(t);			lli = new_ll_item(DT_WEIGHTED, wi);			if (!cur_section->itm_list) {/* 				fprintf(stdout, "creating new item list: %s  %s  %p\n", wi->symbol, cur_section->name, lli); */				cur_section->itm_list = lli;				lli->prev = lli->next = lli;				++cur_section->num_items;			} else {				insque(lli, cur_section->itm_list->prev);/* 				fprintf(stdout, "adding item to list: %d - %s  %p\n", ll_len(cur_section->itm_list), wi->symbol, lli); */				++cur_section->num_items;			}			add_wi_index(lli);			break;		case IN_REORDER:			/* std rule - but in a block with an insert-after pt */			wi = add_weight(t);			lli = new_ll_item(DT_WEIGHTED, wi);			mark_reordered(wi->symbol);/* 			fprintf(stdout, "reorder: %s  %s  %p\n", t, cur_section->name, lli); */			if (!cur_section->itm_list) {				cur_section->itm_list = lli;				lli->prev = lli->next = lli;				++cur_section->num_items;			} else {				insque(lli, cur_section->itm_list->prev);				++cur_section->num_items;			}			add_wi_index(lli);			break;		case IN_REORDER_SECTIONS:			t = xsymdup(t);			if (next_token() != NULL) {				error_msg("trailing text in reorder section item: %s", pos);			}			lli = cur_col->section_list;			do {				if (lli->data_type & DT_SECTION) {					if (!strcmp(((section_t *)(lli->data))->name, t)) {						lli->data_type = DT_REORDER;						lli = new_ll_item(DT_REORDER, (section_t *)(lli->data));						insque(lli, reorder_section_ptr);						reorder_section_ptr = lli;						return;					}				}				lli = lli->next;			} while (lli);			error_msg("reorder_sections_after for non-base item currently not supported: %s", t);/* 			fprintf(stdout, "reorder_secitons: %s\n", t); */			break;		default:			error_msg("invalid order_state %d", order_state);	}}static int col_locale_cmp(const void *n1, const void *n2){    return strcmp(((const col_locale_t *) n1)->name, ((const col_locale_t *) n2)->name);}static void processfile(void){	char *t;	const keyword_table_t *k;	order_state = 0;#warning devel code/* 	cur_num_weights = 0; *//* 	cur_num_weights = 4; *//* 	memset(cur_rule, R_FORWARD, 4); */	if (cur_col != cur_base) {		cur_col->base_locale = cur_base;		cur_col->undefined_idx = cur_base->undefined_idx;		if (!cur_base->derived_list) {			cur_base->derived_list = new_ll_item(DT_COL_LOCALE, cur_col);		} else {			insque(new_ll_item(DT_COL_LOCALE, cur_col), find_ll_last(cur_base->derived_list));		}	}	if (tfind(cur_col, &root_col_locale, col_locale_cmp)) {		error_msg("attempt to read locale: %s", cur_col->name);	}	if (!tsearch(cur_col, &root_col_locale, col_locale_cmp)) {		error_msg("OUT OF MEMORY!");	}	if (superset) {		superset_order_start_cnt = 0;		superset_in_sync = 0;		init_comm_ptr();	}	while (next_line()) {/* 		printf("%5d:", lineno[fno]); *//* 		while ((t = next_token()) != NULL) { *//* 			printf(" |%s|", t); *//* 		printf("\n"); *//* 		} */		t = next_token();		assert(t);		assert(t == pos);		if ((*t == '<') || (!strcmp(t, "UNDEFINED"))) {			do_weight(t);		} else {			for (k = keyword_table ; k->keyword ; k++) {				if (!strcmp(k->keyword, t)) {					break;				}			}			k->handler();		}	}	if (cur_base == cur_col) {		fprintf(stderr, "Base: %15s", cur_col->name);	} else {#if 1		if (!cur_col->undefined_idx) {#if 0			if (superset) {				if (superset_order_start_cnt == 1) {					--superset_order_start_cnt;	/* ugh.. hack this */				}			}#endif			/* This is an awful hack to get around the problem of unspecified UNDEFINED			 * definitions in the supported locales derived from iso14651_t1. */			if (!strcmp(cur_base->name, "iso14651_t1")) {				fprintf(stderr, "Warning: adding UNDEFINED entry for %s\n", cur_col->name);				strcpy(linebuf, "script <UNDEFINED_SECTION>\n");				pos_e = NULL;				pos = linebuf;				t = next_token();				assert(t);				assert(t == pos);				do_script();				strcpy(linebuf, "order_start <UNDEFINED_SECTION>;forward;backward;forward;forward,position\n");				pos_e = NULL;				pos = linebuf;				t = next_token();				assert(t);				assert(t == pos);				do_order_start();				strcpy(linebuf, "UNDEFINED IGNORE;IGNORE;IGNORE\n");				pos_e = NULL;				pos = linebuf;				t = next_token();				assert(t);				assert(t == pos);				do_weight(t);				strcpy(linebuf, "order_end\n");				pos_e = NULL;				pos = linebuf;				t = next_token();				assert(t);				assert(t == pos);				do_order_end();			} else {				error_msg("no definition of UNDEFINED for %s", cur_col->name);			}		}#endif		fprintf(stderr, " Der: %15s", cur_col->name);	}	{		ll_item_t *p = cur_col->section_list;		fprintf(stderr, "%6u weights", tnumnodes(cur_col->root_wi_index));		if (cur_base) {			fprintf(stderr, "  %6u der %6u reor %6u starter - %u new stubs",					tnumnodes(cur_base->root_derived_wi),					tnumnodes(cur_base->root_wi_index_reordered),					tnumnodes(cur_base->root_starter_char),					ll_count(cur_col->section_list, DT_REORDER));		}		fprintf(stderr, "\n");#if 0		while (p) {			assert(((section_t *)(p->data))->num_items ==				   ll_len(((section_t *)(p->data))->itm_list));			if (!p->next &&				((*((section_t *)(p->data))->name == 'a')				 && (((section_t *)(p->data))->num_items == 0))				) {				break;			}			if (!(p->data_type & DT_REORDER)) {				if ((*((section_t *)(p->data))->name != 'a')					|| (((section_t *)(p->data))->num_items > 0)					) {					fprintf(stderr,/* 							"\t%-15s %zu\n", */							"\t%-15s %6u\n",							((section_t *)(p->data))->name,							((section_t *)(p->data))->num_items);				}			}			p = p->next;		}#endif	}}static void print_colnode(const void *ptr, VISIT order, int level){    const colitem_t *p = *(const colitem_t **) ptr;    if (order == postorder || order == leaf)  {        printf("collating item = \"%s\"", p->string);		if (p->element) {			printf(" is %s", p->element);		}        printf("\n");    }}static void print_weight_node(const void *ptr, VISIT order, int level){    const weight_t *p = *(const weight_t **) ptr;	int i;    if (order == postorder || order == leaf)  {        printf("weight: (%d)  ", 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");    }}typedef struct {	const char *der_name;	int base_locale;} deps_t;enum {	BASE_iso14651_t1,	BASE_comm,	BASE_cs_CZ,	BASE_ar_SA,	BASE_th_TH,	BASE_ja_JP,	BASE_ko_KR,	BASE_MAX};static const char *base_name[] = {	"iso14651_t1",	"comm",	"cs_CZ",	"ar_SA",	"th_TH",	"ja_JP",	"ko_KR"};static ll_item_t *locale_list[BASE_MAX];static void init_locale_list(void){	int i;	for (i=0 ; i < BASE_MAX ; i++) {		locale_list[i] = (ll_item_t *) xmalloc(sizeof(ll_item_t));		locale_list[i]->prev = locale_list[i]->next = locale_list[i];		locale_list[i]->data = (void *) base_name[i];	}}deps_t deps[] = {	{ "af_ZA", BASE_iso14651_t1 },	{ "am_ET", BASE_iso14651_t1 },	{ "ar_AE", BASE_iso14651_t1 },	{ "ar_BH", BASE_iso14651_t1 },	{ "ar_DZ", BASE_iso14651_t1 },	{ "ar_EG", BASE_iso14651_t1 },	{ "ar_IN", BASE_iso14651_t1 },	{ "ar_IQ", BASE_iso14651_t1 },	{ "ar_JO", BASE_iso14651_t1 },	{ "ar_KW", BASE_iso14651_t1 },	{ "ar_LB", BASE_iso14651_t1 },	{ "ar_LY", BASE_iso14651_t1 },	{ "ar_MA", BASE_iso14651_t1 },	{ "ar_OM", BASE_iso14651_t1 },	{ "ar_QA", BASE_iso14651_t1 },	{ "ar_SA", BASE_ar_SA },	{ "ar_SD", BASE_iso14651_t1 },	{ "ar_SY", BASE_iso14651_t1 },	{ "ar_TN", BASE_iso14651_t1 },	{ "ar_YE", BASE_iso14651_t1 },	{ "az_AZ", BASE_iso14651_t1 },	{ "be_BY", BASE_iso14651_t1 },	{ "bg_BG", BASE_iso14651_t1 },	{ "bn_BD", BASE_iso14651_t1 },	{ "bn_IN", BASE_iso14651_t1 },	{ "br_FR", BASE_iso14651_t1 },	{ "bs_BA", BASE_iso14651_t1 },	{ "ca_ES", BASE_comm },	{ "cs_CZ", BASE_cs_CZ },	{ "cy_GB", BASE_iso14651_t1 },	{ "da_DK", BASE_comm },	{ "de_AT", BASE_iso14651_t1 },	{ "de_BE", BASE_iso14651_t1 },	{ "de_CH", BASE_iso14651_t1 },	{ "de_DE", BASE_iso14651_t1 },	{ "de_LU", BASE_iso14651_t1 },	{ "el_GR", BASE_iso14651_t1 },	{ "en_AU", BASE_iso14651_t1 },	{ "en_BW", BASE_iso14651_t1 },	{ "en_CA", BASE_comm },	{ "en_DK", BASE_iso14651_t1 },	{ "en_GB", BASE_iso14651_t1 },	{ "en_HK", BASE_iso14651_t1 },	{ "en_IE", BASE_iso14651_t1 },	{ "en_IN", BASE_iso14651_t1 },	{ "en_NZ", BASE_iso14651_t1 },	{ "en_PH", BASE_iso14651_t1 },	{ "en_SG", BASE_iso14651_t1 },	{ "en_US", BASE_iso14651_t1 },	{ "en_ZA", BASE_iso14651_t1 },	{ "en_ZW", BASE_iso14651_t1 },	{ "eo_EO", BASE_iso14651_t1 },	{ "es_AR", BASE_comm },	{ "es_BO", BASE_comm },	{ "es_CL", BASE_comm },	{ "es_CO", BASE_comm },	{ "es_CR", BASE_comm },	{ "es_DO", BASE_comm },	{ "es_EC", BASE_comm },	{ "es_ES", BASE_comm },	{ "es_GT", BASE_comm },	{ "es_HN", BASE_comm },	{ "es_MX", BASE_comm },	{ "es_NI", BASE_comm },	{ "es_PA", BASE_comm },	{ "es_PE", BASE_comm },	{ "es_PR", BASE_comm },	{ "es_PY", BASE_comm },	{ "es_SV", BASE_comm },	{ "es_US", BASE_comm },	{ "es_UY", BASE_comm },	{ "es_VE", BASE_comm },	{ "et_EE", BASE_comm },	{ "eu_ES", BASE_iso14651_t1 },	{ "fa_IR", BASE_iso14651_t1 },	{ "fi_FI", BASE_comm },	{ "fo_FO", BASE_comm },	{ "fr_BE", BASE_iso14651_t1 },	{ "fr_CA", BASE_comm },	{ "fr_CH", BASE_iso14651_t1 },	{ "fr_FR", BASE_iso14651_t1 },	{ "fr_LU", BASE_iso14651_t1 },	{ "ga_IE", BASE_iso14651_t1 },	{ "gd_GB", BASE_iso14651_t1 },	{ "gl_ES", BASE_comm },	{ "gv_GB", BASE_iso14651_t1 },	{ "he_IL", BASE_iso14651_t1 },	{ "hi_IN", BASE_iso14651_t1 },	{ "hr_HR", BASE_comm },	{ "hu_HU", BASE_iso14651_t1 },	{ "hy_AM", BASE_iso14651_t1 },	{ "id_ID", BASE_iso14651_t1 },	{ "is_IS", BASE_comm },	{ "it_CH", BASE_iso14651_t1 },	{ "it_IT", BASE_iso14651_t1 },	{ "iw_IL", BASE_iso14651_t1 },	{ "ja_JP", BASE_ja_JP },	{ "ka_GE", BASE_iso14651_t1 },	{ "kl_GL", BASE_comm },	{ "ko_KR", BASE_ko_KR },	{ "kw_GB", BASE_iso14651_t1 },	{ "lt_LT", BASE_comm },	{ "lv_LV", BASE_comm },	{ "mi_NZ", BASE_iso14651_t1 },	{ "mk_MK", BASE_iso14651_t1 },	{ "mr_IN", BASE_iso14651_t1 },	{ "ms_MY", BASE_iso14651_t1 },	{ "mt_MT", BASE_iso14651_t1 },	{ "nl_BE", BASE_iso14651_t1 },	{ "nl_NL", BASE_iso14651_t1 },	{ "nn_NO", BASE_iso14651_t1 },	{ "no_NO", BASE_comm },	{ "oc_FR", BASE_iso14651_t1 },	{ "pl_PL", BASE_comm },	{ "pt_BR", BASE_iso14651_t1 },	{ "pt_PT", BASE_iso14651_t1 },	{ "ro_RO", BASE_iso14651_t1 },	{ "ru_RU", BASE_iso14651_t1 },	{ "ru_UA", BASE_iso14651_t1 },	{ "se_NO", BASE_iso14651_t1 },	{ "sk_SK", BASE_cs_CZ },	{ "sl_SI", BASE_comm },	{ "sq_AL", BASE_iso14651_t1 },	{ "sr_YU", BASE_iso14651_t1 },	{ "sv_FI", BASE_comm },	{ "sv_SE", BASE_iso14651_t1 },	{ "ta_IN", BASE_iso14651_t1 },	{ "te_IN", BASE_iso14651_t1 },	{ "tg_TJ", BASE_iso14651_t1 },	{ "th_TH", BASE_th_TH },	{ "ti_ER", BASE_iso14651_t1 },	{ "ti_ET", BASE_iso14651_t1 },	{ "tl_PH", BASE_iso14651_t1 },	{ "tr_TR", BASE_comm },	{ "tt_RU", BASE_iso14651_t1 },	{ "uk_UA", BASE_iso14651_t1 },	{ "ur_PK", BASE_iso14651_t1 },	{ "uz_UZ", BASE_iso14651_t1 },	{ "vi_VN", BASE_iso14651_t1 },	{ "wa_BE", BASE_iso14651_t1 },	{ "yi_US", BASE_iso14651_t1 },	{ "zh_CN", BASE_iso14651_t1 },	{ "zh_HK", BASE_iso14651_t1 },	{ "zh_SG", BASE_iso14651_t1 },	{ "zh_TW", BASE_iso14651_t1 },};static int der_count[BASE_MAX];static const char *new_args[500];static int new_arg_count;static int dep_cmp(const void *s1, const void *s2){	return strcmp( (const char *) s1, ((const deps_t *) s2)->der_name);}static int old_main(int argc, char **argv);int main(int argc, char **argv){	const deps_t *p;	ll_item_t *lli;	int i;	int total;	if (argc < 2) {		return EXIT_FAILURE;	}	init_locale_list();		while (--argc) {		p = (const deps_t *) bsearch(*++argv, deps, sizeof(deps)/sizeof(deps[0]), sizeof(deps[0]), dep_cmp);		if (!p) {			if (!strcmp("C", *argv)) {				printf("ignoring C locale\n");				continue;			} else {

⌨️ 快捷键说明

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