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

📄 gen_locale.c

📁 Axis 221 camera embedded programing interface
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (last + l >= buf + sizeof(buf)) {		printf("need to increase size of buf!\n");		exit(EXIT_FAILURE);	}	idx[uniq] = last;	++uniq;	strcpy(last, s);	last += l;	return idx[uniq - 1] - buf;}#define DO_LC_COMMON(CATEGORY) \	printf("buf-size=%d  uniq=%d  rows=%d\n", \		   (int)(last - buf), uniq, lc_##CATEGORY##_uniq); \	printf("total = %d + %d * %d + %d = %d\n", \		   num_locales, lc_##CATEGORY##_uniq, NUM_NL_##CATEGORY, (int)(last - buf), \		   i = num_locales + lc_##CATEGORY##_uniq*NUM_NL_##CATEGORY + (int)(last - buf)); \	total_size += i; \	dump_table8c("__lc_" #CATEGORY "_data", buf, (int)(last - buf)); \	for (i=0 ; i < lc_##CATEGORY##_uniq ; i++) { \		m = locales[i].lc_##CATEGORY##_row; \		for (k=0 ; k < NUM_NL_##CATEGORY ; k++) { \			buf[NUM_NL_##CATEGORY*i + k] = (char)((unsigned char) lc_##CATEGORY##_uniq_X[i][k]); \		} \	} \	dump_table8("__lc_" #CATEGORY "_rows", buf, lc_##CATEGORY##_uniq * NUM_NL_##CATEGORY); \	buf16[0] =0; \	for (i=0 ; i < NUM_NL_##CATEGORY - 1 ; i++) { \		buf16[i+1] = buf16[i] + lc_##CATEGORY##_count[i]; \	} \	dump_table16("__lc_" #CATEGORY "_item_offsets", buf16, NUM_NL_##CATEGORY); \	m = 0; \	for (k=0 ; k < NUM_NL_##CATEGORY ; k++) { \		for (i=0 ; i < lc_##CATEGORY##_count[k] ; i++) { \			buf16[m] = lc_##CATEGORY##_item[k][i]; \			++m; \		} \	} \	dump_table16("__lc_" #CATEGORY "_item_idx", buf16, m);#define DL_LC_LOOPTAIL(CATEGORY) \		if (k > NUM_NL_##CATEGORY) { \			printf("error -- lc_" #CATEGORY " nl_item count > %d!\n", NUM_NL_##CATEGORY); \			exit(EXIT_FAILURE); \		} \		{ \			int r; \			for (r=0 ; r < lc_##CATEGORY##_uniq ; r++) { \				if (!memcmp(lc_##CATEGORY##_uniq_X[lc_##CATEGORY##_uniq], \							lc_##CATEGORY##_uniq_X[r], NUM_NL_##CATEGORY)) { \					break; \				} \			} \			if (r == lc_##CATEGORY##_uniq) { /* new locale row */ \				++lc_##CATEGORY##_uniq; \				if (lc_##CATEGORY##_uniq > 255) { \					printf("too many unique lc_" #CATEGORY " rows!\n"); \					exit(EXIT_FAILURE); \				} \			} \			locales[i].lc_##CATEGORY##_row = r; \		}static int buf16[100*256];static void dump_table8(const char *name, const char *tbl, int len){	int i;	fprintf(ofp, "#define %s_LEN\t\t%d\n", name, len);	fprintf(ofp, "static const unsigned char %s[%d] = {", name, len);	for (i=0 ; i < len ; i++) {		if ((i % 12) == 0) {			fprintf(ofp, "\n\t");		}		fprintf(ofp, "%#4x, ", (int)((unsigned char) tbl[i]));	}	fprintf(ofp, "\n};\n\n");}#define __C_isdigit(c) \	((sizeof(c) == sizeof(char)) \	 ? (((unsigned char)((c) - '0')) < 10) \	 : (((unsigned int)((c) - '0')) < 10))#define __C_isalpha(c) \	((sizeof(c) == sizeof(char)) \	 ? (((unsigned char)(((c) | 0x20) - 'a')) < 26) \	 : (((unsigned int)(((c) | 0x20) - 'a')) < 26))#define __C_isalnum(c) (__C_isalpha(c) || __C_isdigit(c))static void dump_table8c(const char *name, const char *tbl, int len){	int i;	fprintf(ofp, "#define %s_LEN\t\t%d\n", name, len);	fprintf(ofp, "static const unsigned char %s[%d] = {", name, len);	for (i=0 ; i < len ; i++) {		if ((i % 12) == 0) {			fprintf(ofp, "\n\t");		}		if (__C_isalnum(tbl[i]) || (tbl[i] == ' ')) {			fprintf(ofp, " '%c', ", (int)((unsigned char) tbl[i]));		} else {			fprintf(ofp, "%#4x, ", (int)((unsigned char) tbl[i]));		}	}	fprintf(ofp, "\n};\n\n");}static void dump_table16(const char *name, const int *tbl, int len){	int i;	fprintf(ofp, "#define %s_LEN\t\t%d\n", name, len);	fprintf(ofp, "static const uint16_t %s[%d] = {", name, len);	for (i=0 ; i < len ; i++) {		if ((i % 8) == 0) {			fprintf(ofp, "\n\t");		}		if (tbl[i] != (uint16_t) tbl[i]) {			printf("error - falls outside uint16 range!\n");			exit(EXIT_FAILURE);		}		fprintf(ofp, "%#6x, ", tbl[i]);	}	fprintf(ofp, "\n};\n\n");}#define NUM_NL_time 50static int lc_time_item[NUM_NL_time][256];static int lc_time_count[NUM_NL_time];static unsigned char lc_time_uniq_X[700][NUM_NL_time];static int lc_time_uniq;#define DO_NL_S(X)	lc_time_S(X, k++)static void lc_time_S(int X, int k){	size_t len;	int j, m;	const char *s = nl_langinfo(X);	const char *p;	static const char nulbuf[] = "";	if (X == ALT_DIGITS) {		len = 1;		if (!s) {			s = nulbuf;		}		if (*s) {			p = s;			for (j = 0 ; j < 100 ; j++) {				while (*p) {					++p;				}				++p;			}			len = p - s;		}		j = addblock(s, len);/* 		if (len > 1) fprintf(stderr, "alt_digit: called addblock with len %zd\n", len); */	} else if (X == ERA) {		if (!s) {			s = nulbuf;		}		p = s;		while (*p) {			while (*p) {				++p;			}			++p;		}		++p;		j = addblock(s, p - s);/* 		if (p-s > 1) fprintf(stderr, "era: called addblock with len %d\n", p-s); */	} else {		j = addstring(s);	}	for (m=0 ; m < lc_time_count[k] ; m++) {		if (lc_time_item[k][m] == j) {			break;		}	}	if (m == lc_time_count[k]) { /* new for this nl_item */		if (m > 255) {			printf("too many nl_item %d entries in lc_time\n", k);			exit(EXIT_FAILURE);		}		lc_time_item[k][m] = j;		++lc_time_count[k];	}	lc_time_uniq_X[lc_time_uniq][k] = m;}static void do_lc_time(void){	int i, k, m;	last = buf+1;	uniq = 1;	*buf = 0;	*idx = buf;	for (i=0 ; i < num_locales ; i++) {		k = 0;		if (!setlocale(LC_ALL, locales[i].glibc_name)) {			printf("setlocale(LC_ALL,%s) failed!\n",				   locales[i].glibc_name);		}		DO_NL_S(ABDAY_1);		DO_NL_S(ABDAY_2);		DO_NL_S(ABDAY_3);		DO_NL_S(ABDAY_4);		DO_NL_S(ABDAY_5);		DO_NL_S(ABDAY_6);		DO_NL_S(ABDAY_7);		DO_NL_S(DAY_1);		DO_NL_S(DAY_2);		DO_NL_S(DAY_3);		DO_NL_S(DAY_4);		DO_NL_S(DAY_5);		DO_NL_S(DAY_6);		DO_NL_S(DAY_7);		DO_NL_S(ABMON_1);		DO_NL_S(ABMON_2);		DO_NL_S(ABMON_3);		DO_NL_S(ABMON_4);		DO_NL_S(ABMON_5);		DO_NL_S(ABMON_6);		DO_NL_S(ABMON_7);		DO_NL_S(ABMON_8);		DO_NL_S(ABMON_9);		DO_NL_S(ABMON_10);		DO_NL_S(ABMON_11);		DO_NL_S(ABMON_12);		DO_NL_S(MON_1);		DO_NL_S(MON_2);		DO_NL_S(MON_3);		DO_NL_S(MON_4);		DO_NL_S(MON_5);		DO_NL_S(MON_6);		DO_NL_S(MON_7);		DO_NL_S(MON_8);		DO_NL_S(MON_9);		DO_NL_S(MON_10);		DO_NL_S(MON_11);		DO_NL_S(MON_12);		DO_NL_S(AM_STR);		DO_NL_S(PM_STR);		DO_NL_S(D_T_FMT);		DO_NL_S(D_FMT);		DO_NL_S(T_FMT);		DO_NL_S(T_FMT_AMPM);		DO_NL_S(ERA);		DO_NL_S(ERA_YEAR);		/* non SuSv3 */		DO_NL_S(ERA_D_FMT);		DO_NL_S(ALT_DIGITS);		DO_NL_S(ERA_D_T_FMT);		DO_NL_S(ERA_T_FMT);		DL_LC_LOOPTAIL(time)	}	DO_LC_COMMON(time)}#undef DO_NL_S#define NUM_NL_numeric 3static int lc_numeric_item[NUM_NL_numeric][256];static int lc_numeric_count[NUM_NL_numeric];static unsigned char lc_numeric_uniq_X[700][NUM_NL_numeric];static int lc_numeric_uniq;#define DO_NL_S(X)	lc_numeric_S(X, k++)static void lc_numeric_S(int X, int k){	int j, m;	char buf[256];	char *e;	char *s;	char c;	s = nl_langinfo(X);	if (X == GROUPING) {		if (s) {			if ((*s == CHAR_MAX) || (*s == -1)) { /* stupid glibc... :-( */				s = "";			}			e = s;			c = 0;			while (*e) { /* find end of string */				if (*e == CHAR_MAX) {					c = CHAR_MAX;					++e;					break;				}				++e;			}			if ((e - s) > sizeof(buf)) {				printf("grouping specifier too long\n");				exit(EXIT_FAILURE);			}			strncpy(buf, s, (e-s));			e = buf + (e-s);			*e = 0;				/* Make sure we're null-terminated. */			if (c != CHAR_MAX) { /* remove duplicate repeats */				while (e > buf) {					--e;					if (*e != e[-1]) {						break;					}				}				*++e = 0;			}			s = buf;		}	}	j = addstring(s);	for (m=0 ; m < lc_numeric_count[k] ; m++) {		if (lc_numeric_item[k][m] == j) {			break;		}	}	if (m == lc_numeric_count[k]) { /* new for this nl_item */		if (m > 255) {			printf("too many nl_item %d entries in lc_numeric\n", k);			exit(EXIT_FAILURE);		}		lc_numeric_item[k][m] = j;		++lc_numeric_count[k];	}/*  	printf("\\x%02x", m); */	lc_numeric_uniq_X[lc_numeric_uniq][k] = m;}static void do_lc_numeric(void){	int i, k, m;	last = buf+1;	uniq = 1;	*buf = 0;	*idx = buf;	for (i=0 ; i < num_locales ; i++) {		k = 0;		if (!setlocale(LC_ALL, locales[i].glibc_name)) {			printf("setlocale(LC_ALL,%s) failed!\n",				   locales[i].glibc_name);		}		DO_NL_S(RADIXCHAR);		/* DECIMAL_POINT */		DO_NL_S(THOUSEP);		/* THOUSANDS_SEP */		DO_NL_S(GROUPING);		DL_LC_LOOPTAIL(numeric)	}	DO_LC_COMMON(numeric)}#undef DO_NL_S#define NUM_NL_monetary (7+14+1)static int lc_monetary_item[NUM_NL_monetary][256];static int lc_monetary_count[NUM_NL_monetary];static unsigned char lc_monetary_uniq_X[700][NUM_NL_monetary];static int lc_monetary_uniq;#define DO_NL_S(X)	lc_monetary_S(X, k++)/*  #define DO_NL_C(X)		printf("%#02x", (int)(unsigned char)(*nl_langinfo(X))); */#define DO_NL_C(X) lc_monetary_C(X, k++)static void lc_monetary_C(int X, int k){	int j, m;	char c_buf[2];#warning fix the char entries for monetary... target signedness of char may be different!	c_buf[1] = 0;	c_buf[0] = *nl_langinfo(X);	j = addstring(c_buf);	for (m=0 ; m < lc_monetary_count[k] ; m++) {		if (lc_monetary_item[k][m] == j) {			break;		}	}	if (m == lc_monetary_count[k]) { /* new for this nl_item */		if (m > 255) {			printf("too many nl_item %d entries in lc_monetary\n", k);			exit(EXIT_FAILURE);		}		lc_monetary_item[k][m] = j;		++lc_monetary_count[k];	}/*  	printf("\\x%02x", m); */	lc_monetary_uniq_X[lc_monetary_uniq][k] = m;}static void lc_monetary_S(int X, int k){	int j, m;	char buf[256];	char *e;	char *s;	char c;	s = nl_langinfo(X);	if (X == MON_GROUPING) {		if (s) {			if ((*s == CHAR_MAX) || (*s == -1)) { /* stupid glibc... :-( */				s = "";			}			e = s;			c = 0;			while (*e) { /* find end of string */				if (*e == CHAR_MAX) {					c = CHAR_MAX;					++e;					break;				}				++e;			}			if ((e - s) > sizeof(buf)) {				printf("mon_grouping specifier too long\n");				exit(EXIT_FAILURE);			}			strncpy(buf, s, (e-s));			e = buf + (e-s);			*e = 0;				/* Make sure we're null-terminated. */			if (c != CHAR_MAX) { /* remove duplicate repeats */				while (e > buf) {					--e;					if (*e != e[-1]) {						break;					}				}				*++e = 0;			}			s = buf;		}	}	j = addstring(s);	for (m=0 ; m < lc_monetary_count[k] ; m++) {		if (lc_monetary_item[k][m] == j) {			break;		}	}	if (m == lc_monetary_count[k]) { /* new for this nl_item */		if (m > 255) {			printf("too many nl_item %d entries in lc_monetary\n", k);			exit(EXIT_FAILURE);		}		lc_monetary_item[k][m] = j;		++lc_monetary_count[k];	}/*  	printf("\\x%02x", m); */	lc_monetary_uniq_X[lc_monetary_uniq][k] = m;}static void do_lc_monetary(void){	int i, k, m;	last = buf+1;	uniq = 1;	*buf = 0;	*idx = buf;	for (i=0 ; i < num_locales ; i++) {		k = 0;		if (!setlocale(LC_ALL, locales[i].glibc_name)) {			printf("setlocale(LC_ALL,%s) failed!\n",				   locales[i].glibc_name);		}		/* non SUSv3 */		DO_NL_S(INT_CURR_SYMBOL);		DO_NL_S(CURRENCY_SYMBOL);		DO_NL_S(MON_DECIMAL_POINT);		DO_NL_S(MON_THOUSANDS_SEP);		DO_NL_S(MON_GROUPING);		DO_NL_S(POSITIVE_SIGN);		DO_NL_S(NEGATIVE_SIGN);		DO_NL_C(INT_FRAC_DIGITS);		DO_NL_C(FRAC_DIGITS);		DO_NL_C(P_CS_PRECEDES);		DO_NL_C(P_SEP_BY_SPACE);		DO_NL_C(N_CS_PRECEDES);		DO_NL_C(N_SEP_BY_SPACE);		DO_NL_C(P_SIGN_POSN);		DO_NL_C(N_SIGN_POSN);		DO_NL_C(INT_P_CS_PRECEDES);		DO_NL_C(INT_P_SEP_BY_SPACE);		DO_NL_C(INT_N_CS_PRECEDES);		DO_NL_C(INT_N_SEP_BY_SPACE);		DO_NL_C(INT_P_SIGN_POSN);		DO_NL_C(INT_N_SIGN_POSN);		DO_NL_S(CRNCYSTR);		/* CURRENCY_SYMBOL */		DL_LC_LOOPTAIL(monetary)	}	DO_LC_COMMON(monetary)}#undef DO_NL_S#define NUM_NL_messages 4static int lc_messages_item[NUM_NL_messages][256];static int lc_messages_count[NUM_NL_messages];static unsigned char lc_messages_uniq_X[700][NUM_NL_messages];static int lc_messages_uniq;#define DO_NL_S(X)	lc_messages_S(X, k++)static void lc_messages_S(int X, int k){	int j, m;	j = addstring(nl_langinfo(X));	for (m=0 ; m < lc_messages_count[k] ; m++) {		if (lc_messages_item[k][m] == j) {			break;		}	}	if (m == lc_messages_count[k]) { /* new for this nl_item */		if (m > 255) {			printf("too many nl_item %d entries in lc_messages\n", k);			exit(EXIT_FAILURE);		}		lc_messages_item[k][m] = j;		++lc_messages_count[k];	}/*  	printf("\\x%02x", m); */	lc_messages_uniq_X[lc_messages_uniq][k] = m;}static void do_lc_messages(void){	int i, k, m;	last = buf+1;	uniq = 1;	*buf = 0;	*idx = buf;	for (i=0 ; i < num_locales ; i++) {		k = 0;		if (!setlocale(LC_ALL, locales[i].glibc_name)) {			printf("setlocale(LC_ALL,%s) failed!\n",				   locales[i].glibc_name);		}		DO_NL_S(YESEXPR);		DO_NL_S(NOEXPR);		DO_NL_S(YESSTR);		DO_NL_S(NOSTR);		DL_LC_LOOPTAIL(messages)	}	DO_LC_COMMON(messages)}#undef DO_NL_S#define NUM_NL_ctype 10static int lc_ctype_item[NUM_NL_ctype][256];static int lc_ctype_count[NUM_NL_ctype];static unsigned char lc_ctype_uniq_X[700][NUM_NL_ctype];static int lc_ctype_uniq;#define DO_NL_S(X)	lc_ctype_S(X, k++)static void lc_ctype_S(int X, int k){	int j, m;	j = addstring(nl_langinfo(X));	for (m=0 ; m < lc_ctype_count[k] ; m++) {		if (lc_ctype_item[k][m] == j) {			break;		}	}	if (m == lc_ctype_count[k]) { /* new for this nl_item */		if (m > 255) {			printf("too many nl_item %d entries in lc_ctype\n", k);			exit(EXIT_FAILURE);		}		lc_ctype_item[k][m] = j;		++lc_ctype_count[k];	}/*  	printf("\\x%02x", m); */	lc_ctype_uniq_X[lc_ctype_uniq][k] = m;}static void do_lc_ctype(void){	int i, k, m;	last = buf+1;	uniq = 1;	*buf = 0;	*idx = buf;	for (i=0 ; i < num_locales ; i++) {		k = 0;		if (!setlocale(LC_ALL, locales[i].glibc_name)) {			printf("setlocale(LC_ALL,%s) failed!\n",				   locales[i].glibc_name);		}		DO_NL_S(_NL_CTYPE_OUTDIGIT0_MB);		DO_NL_S(_NL_CTYPE_OUTDIGIT1_MB);		DO_NL_S(_NL_CTYPE_OUTDIGIT2_MB);		DO_NL_S(_NL_CTYPE_OUTDIGIT3_MB);		DO_NL_S(_NL_CTYPE_OUTDIGIT4_MB);		DO_NL_S(_NL_CTYPE_OUTDIGIT5_MB);		DO_NL_S(_NL_CTYPE_OUTDIGIT6_MB);		DO_NL_S(_NL_CTYPE_OUTDIGIT7_MB);		DO_NL_S(_NL_CTYPE_OUTDIGIT8_MB);		DO_NL_S(_NL_CTYPE_OUTDIGIT9_MB);		DL_LC_LOOPTAIL(ctype)	}	DO_LC_COMMON(ctype)}

⌨️ 快捷键说明

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