Exemplo n.º 1
0
char load_lang_file(char *pth)
{
	char *buf;
	DWORD sz=0;
	DWORD afc=0;
	AF *af;
	if(!(buf = read_whole_file(pth,&sz)))
		return 0;

	
	free_lang();//free_crs(lang_file,&lf_afc);
	af= make_af("%*[#(#)#]%*[#(#)#]%*",0,&lf_afc);
	lang_file=parse_string(buf,sz,af,lf_afc,1);
	

	load_menu_lang(lang_file[0].str,lang_file[0].dx);
	parse_msgs(lang_file[4].str,lang_file[4].dx);

	return 1;
}
Exemplo n.º 2
0
Arquivo: xkey.c Projeto: 8l/ted
LoadTedrc(char *tedname, int depth, int kdefmapno)
{
FILE *fp;
char ss[8192],ibuf[2048],*tt,*uu,*vv,*ww,*xx;
int len,i,j,lno;
int hdef[128];
extern int X_inited;
KEYDEF *kdef=kdefmap[kdefmapno];
int kdefno=kdefno_m[kdefmapno];

if ((fp=init_tedrc_fname(tedname, depth))==NULL)
	return 1;

if (kdefno && !depth) {
	for(j=0;j<kdefno;j++) free(kdef[j].cmd);
	if (!kdefmapno) free_lang();
	free(kdef);
	kdefmap[kdefmapno]=NULL;
	if (kdefmapno) {
		free(mode_str_m[kdefmapno]);
		mode_str_m[kdefmapno]=NULL;
	}
	kdef=NULL;
}
#if	0
printf("-- %d %d %s\n",depth, kdefmapno, ftedrc);
#endif
if (kdef==NULL) {
	MAX_KEY_DEF=280;
	if ((kdef=mmalloc(sizeof(KEYDEF)*MAX_KEY_DEF,"LoadTedrc"))==NULL)
		exit(1);
	kdefmap[kdefmapno]=kdef;
	kdefno_m[kdefmapno]=kdefno=0;
}


if (!depth) qsort(kmap,kname_no,sizeof(KEYMAP),qcmpxk);
tedrcfname=tedname;
lno=0;
while (!feof(fp)) {
	int next_l;

	ss[0]=0;
	next_l=0;
	for(;;) {
		lno++;
		len=mfgets(ibuf,sizeof(ibuf),fp);
		if (!len) {
			next_l=1;
			break;
		}
		if (ibuf[len-1]=='\n') ibuf[--len]=0;
		if (!len) {
			next_l=1;
			break;
		}
		while (len && (ibuf[len-1]==' '||ibuf[len-1]==9)) len--;
		if (!len) {
			next_l=1;
			break;
		}
		if (ibuf[len-1]=='\\') {
			ibuf[len-1]=0;
			strcat(ss,ibuf);
		} else {
			strcat(ss,ibuf);
			break;
		}
	}
	if (next_l) continue;

	tt=skip_spc(ss);
	uu=to_spc(tt);
	vv=skip_spc(uu);
	*uu=0;
	if (tt[0]=='#')	continue;
	if (!strcmp(tt,"d")) {
		ww=to_spc(vv);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode);
		if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno)
			free(kdef[i].cmd);
		xx=skip_spc(ww);
		kdef[i].cmd=strdup(parse_Cstr(tedname, lno,xx,&uu));
		kdef[i].type=0;
		if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno);
		continue;
	} else
	if (!strcmp(tt,"f")) {
		ww=to_spc(vv);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode);
		if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno)
			free(kdef[i].cmd);
		xx=skip_spc(ww);
		if (parse_stmt(tedname, lno,xx,&kdef[i].cmd,&kdef[i].type)) {
			if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno);
		}
		continue;
	}
	if (kdefmapno)
		lper(tedname,lno,"%s for LoadKeyDefInto can accept 'f' and 'd' command only", tedname);
	if (!strcmp(tt,"s")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		*ww=0;
		for(i=0;i<sizeof(locolor)/sizeof(locolor[0]);i++)
			if (!strcmp(vv,locolor[i].cname)) break;
		if (i==sizeof(locolor)/sizeof(locolor[0]))
			lper(tedname,lno,"Unknown Def color %s",vv);
		ww=to_spc(xx);
		*ww=0;
		strcpy(locolor[i].caddr,xx);
	} else
	if (!strcmp(tt,"set")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		tt=to_spc(xx);
		if (!(*ww)) lper(tedname,lno,"argument expected");
		*ww=0;
		for(i=0;i<sizeof(sets)/sizeof(sets[0]);i++)
		if (!strcmp(sets[i].sname,vv)) break;
		if (i==sizeof(sets)/sizeof(sets[0]))
			lper2(tedname,lno,"Unknown set %s",vv);
		else {
		  *tt=0;
		  *(sets[i].saddr)=atoi(xx);
		}
	} else
	if (!strcmp(tt,"lang") && !depth) {
		extern char DirectCommentChars[];
		int keywcnt=3,LangIdx,ColIdx,AllocN=32,kwidx, MaxKeywordLen=0;
		char *ff;
		KW *kw;

		if (depth)
			p_err("cannot define 'lang' in include %s", tedname);


		tt=parse_Cstr(tedname, lno,vv,&uu);
		i=strlen(tt)+2;
		if ((vv=mmalloc(i,"LoadTedrc"))==NULL) exit(1);
		if ((kw=mmalloc(AllocN*sizeof(KW),"LoadTedrc 2"))==NULL) exit(1);

		LangExt[LangN]=strcat(strcpy(vv,tt)," ");
		kw[0].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		uu=skip_spc(uu);
		DirectCommentChars[LangN]=*uu;
		kw[1].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		kw[2].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		for(;;) {
			if (!*uu) break;
			strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
			strcpy(pc_color[ColorCnt].bg_str,getstr(vv,&uu));
			uu=skip_spc(uu);
			ww=tt=parse_Cstr(tedname, lno,uu,&vv);
			uu=vv;
			xx=tt+strlen(tt);
			for(;;) {
				char *pstr;

				tt=to_spc(ww);
				vv=skip_spc(tt);
				*(tt)=0;
				if (pstr=strchr(ww,'(')) {
					kw[keywcnt].arg=strdup(pstr);
					*pstr=0;
				} else kw[keywcnt].arg=0;
				kw[keywcnt].keyword=strdup(ww);
				if (strlen(ww) > MaxKeywordLen) MaxKeywordLen=strlen(ww);
				kw[keywcnt].coloridx=ColorCnt;
#if	0
				printf("%d %d   %d %s\n",LangN,keywcnt, ColorCnt,
				kw[keywcnt].keyword);
#endif
				keywcnt++;
				if (keywcnt+3>=AllocN) {
					AllocN+=32;
					if ((kw=mrealloc(kw,AllocN*sizeof(KW),"LoadTedrc 3"))==NULL) exit(1);
				}
				ww=vv;
				if (ww==xx) break;
			}
			ColorCnt++;
		}
		qsort(kw+3,keywcnt-3,sizeof(KW), kwcmp);
		LangKw[LangN]=kw;
		LangMaxKeywordLen[LangN]=MaxKeywordLen;
		LangKwN[LangN++]=keywcnt;
		if (LangN>=MaxLang) {
			error("Too many languages defined");
			error("Remove unused language in tedrc or modify ted.h and recompile");
			exit(1);
		}
	} else
	if (!strcmp(tt,"include")) {
		if (depth > 10) {
			error("include too many level ??");
			continue;
		}
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		*ww=0;
		LoadTedrc(vv,depth+1,kdefmapno);
		tedrcfname=tedname;
	} else
	if (!strcmp(tt,"filebrowser")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		init_reg_exp(vv);
	} else
	if (!strcmp(tt,"fontlist")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		setFontList(vv);
	} else
	if (!strcmp(tt,"LoadKeyDefInto")) {
		int no;
		char mstr[16], *p;
		tt=parse_Cstr(tedname, lno,vv,&uu);
		if (!(*tt)) lper(tedname,lno,"file name expected");
		ww=skip_spc(uu);
		if (!*ww) lper(tedname,lno,"Bind number expected");
		no=*ww-'0';
		if (no<=0 || no>=4)
			lper(tedname,lno,"Bind number must be less than 4 and greater than 0");
		if ((p=strchr(tt,'.'))==NULL) {
			mode_str_m[no]="      ";
		} else {
			p++;
			if (! *p)
				mode_str_m[no]=strdup("      ");
			else
				mode_str_m[no]=strdup(p);
		}
		LoadTedrc(tt,0,no);
	}
}
fclose(fp);

if (!depth) {
kdefno=kdefno_m[kdefmapno];
qsort(kdef,kdefno,sizeof(kdef[0]),qcmp);
bzero(hdef,sizeof(hdef));
bzero(kdefhash[kdefmapno],128*sizeof(int));
for(i=0;i<kdefno;i++) {
	j=KEYHASH(kdef[i].kcode[0]);
	if (hdef[j]) continue;
	hdef[j]=1;
	kdefhash[kdefmapno][j]=i;
}
kdefhash[kdefmapno][127]=kdefno;
for(i=126;i>=0;i--)
if (!hdef[i]) kdefhash[kdefmapno][i]=kdefhash[kdefmapno][i+1];
ReLoadTed=1;
if (X_inited) alloc_pc_colors();
}
return 0;
}