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

📄 charmap.c

📁 举世闻名的joe记事本源程序
💻 C
📖 第 1 页 / 共 5 页
字号:
	map->from_uni = from_uni;	map->from_size = 0;	map->to_map = builtin->to_uni;	for (x=0; x!=256; ++x) {		if (map->to_map[x]!=-1) {			map->from_map[map->from_size].first = map->to_map[x];			map->from_map[map->from_size].last = x;			++map->from_size;		}	}			qsort(map->from_map,map->from_size,sizeof(struct pair), (int (*)(const void *, const void *))pair_cmp);	/* Fill in print, alpha and alnum bit maps */	for (x=0;x!=32;++x) {		map->print_map[x] = 0;		map->alpha__map[x] = 0;		map->alnum__map[x] = 0;	}	for (x=0; x!=256; ++x)		if (map->to_map[x] != -1) {			if (joe_iswprint(NULL,map->to_map[x]))				set_bit(map->print_map,x);			if (joe_iswalpha(NULL,map->to_map[x])) {				set_bit(map->alpha__map,x);				set_bit(map->alnum__map,x);			}		}	/* Set underbar <U+005F> */	x = from_uni(map,0x5F);	if (x != -1) {		set_bit(map->alpha__map,x);		set_bit(map->alnum__map,x);	}	/* Put digits in alnum map */	for (x=0x30; x!=0x3A; ++x) {		int y = from_uni(map,x);		if (y != -1)			set_bit(map->alnum__map,y);	}	/* Build case conversion tables */	for (x=0; x!=256; ++x) {		map->lower_map[x] = x;		if (map->to_map[x] != -1) {			int y = joe_towlower(NULL,map->to_map[x]);			int z = from_uni(map,y);			if (z != -1)				map->lower_map[x] = z;		}	}	for (x=0; x!=256; ++x) {		map->upper_map[x] = x;		if (map->to_map[x] != -1) {			int y = joe_towupper(NULL,map->to_map[x]);			int z = from_uni(map,y);			if (z != -1)				map->upper_map[x] = z;		}	}	map->next = charmaps;	charmaps = map;	return map;}static void load_builtins(void){	struct charmap *map;	/* install UTF-8 map (ties into i18n module) */	map = joe_malloc(sizeof(struct charmap));	map->name = USTR "utf-8";	map->type = 1;	map->to_uni = rtn_arg;	map->from_uni = rtn_arg;	map->is_punct = joe_iswpunct;	map->is_print = joe_iswprint;	map->is_space = joe_iswspace;	map->is_alpha_ = joe_iswalpha_;	map->is_alnum_ = joe_iswalnum_;	map->to_lower = joe_towlower;	map->to_upper = joe_towupper;	map->next = charmaps;	charmaps = map;	/* Load all built-in byte maps */	/*	for (y=0; y!=sizeof(builtin_charmaps)/sizeof(struct builtin_charmap); ++y)		process_builtin(builtin_charmaps + y);	*/}/* Parse character map file */struct builtin_charmap *parse_charmap(unsigned char *name,FILE *f){	unsigned char buf[1024];	unsigned char bf1[1024];	unsigned comment_char = '#';	int in_map = 0;	int x;	struct builtin_charmap *b;	if (!f)		return 0;	b = joe_malloc(sizeof(struct builtin_charmap));	b->name = zdup(name);	for (x=0; x!=256; ++x)		b->to_uni[x]= -1;	/* This is a _really_bad_ parser.  The file has to be perfect. */	while (fgets((char *)buf,1023,f)) {		unsigned char *p = buf;		parse_ws(&p, comment_char);		parse_tows(&p, bf1);		if (!zcmp(bf1,USTR "<comment_char>")) {			parse_ws(&p, comment_char);			parse_tows(&p, bf1);			comment_char = bf1[0];		} else if (!zcmp(bf1,USTR "<escape_char>")) {			parse_ws(&p, comment_char);			parse_tows(&p, bf1);		} else if (!zcmp(bf1,USTR "CHARMAP")) {			in_map = 1;		} else if (!zcmp(bf1,USTR "END")) {			in_map = 0;		} else if (in_map && bf1[0]=='<' && bf1[1]=='U') {			int uni;			int byt;			sscanf((char *)bf1+2,"%x",(unsigned *)&uni);			parse_ws(&p, comment_char);			parse_tows(&p, bf1);			sscanf((char *)bf1+2,"%x",(unsigned *)&byt);			b->to_uni[byt]=uni;		}	}	/* For generating builtin maps from /usr/share/i18n/charmaps/ * *//*	printf("	{ \"%s\"\n",name);	for (y=0;y!=256;y+=8) {		printf("\t");		for(x=0;x!=8;++x) {			if (b->to_uni[y+x]==-1)				printf("    -1, ");			else				printf("0x%4.4x, ",b->to_uni[y+x]);		}		printf("\n");	}*/	fclose(f);	return b;}/* Byte wide character map to unicode conversion *//* Compare character map names.  Ignores '-'s and terminates string on '.' *//* Chicken and egg problem here.. */static int map_up(int c){	if (c>='a' && c<='z')		return c+'A'-'a';	else		return c;}int map_name_cmp(unsigned char *a,unsigned char *b){	while (*a=='-') ++a;	while (*b=='-') ++b;	while (*a && *b && map_up(*a)==map_up(*b)) {		++a;		++b;		while (*a=='-') ++a;		while (*b=='-') ++b;	}	if (!*a && (*b=='.' || !*b))		return 0;	else		return 1;}/* Find a character map */struct charmap *find_charmap(unsigned char *name){	unsigned char buf[1024];	unsigned char *p;	struct charmap *m;	struct builtin_charmap *b;	FILE *f;	int y;	if (!name)		return 0;	/* Install some initial character maps */	if (!charmaps)		load_builtins();	/* Alias? */	for (y=0; alias_table[y].alias; ++y)		if (!map_name_cmp(alias_table[y].alias,name)) {			name = alias_table[y].builtin;			break;		}	/* Already loaded? */	for (m=charmaps; m; m=m->next)		if (!map_name_cmp(m->name,name))			return m;	/* Check ~/.joe/charmaps */	p = (unsigned char *)getenv("HOME");	f = 0;	if (p) {		joe_snprintf_2(buf,sizeof(buf),"%s/.joe/charmaps/%s",p,name);		f = fopen((char *)buf,"r");	}	/* Check JOERCcharmaps */	if (!f) {		joe_snprintf_2(buf,sizeof(buf),"%scharmaps/%s",JOERC,name);		f = fopen((char *)buf,"r");	}	/* Parse and install character map from file */	if (f && (b = parse_charmap(name,f)))		return process_builtin(b);	/* Check builtin sets */	for (y=0; y!=sizeof(builtin_charmaps)/sizeof(struct builtin_charmap); ++y)		if (!map_name_cmp(builtin_charmaps[y].name,name))			return process_builtin(builtin_charmaps + y);	return NULL;}/* Test */#if 0main(int argc,char *argv[]){	struct charmap *map=find_charma

⌨️ 快捷键说明

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