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

📄 syntax.c

📁 举世闻名的joe记事本源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
		p = buf;		c = parse_ws(&p,'#');		if (!parse_char(&p, '.')) {			if (!parse_ident(&p, bf, sizeof(bf))) {				if (!zcmp(bf, USTR "ifdef")) {					struct ifstack *st = (struct ifstack *)joe_malloc(sizeof(struct ifstack));					st->next = stack;					st->else_part = 0;					st->ignore = 1;					st->skip = 1;					st->line = line;					if (!stack || !stack->ignore) {						parse_ws(&p,'#');						if (!parse_ident(&p, bf, sizeof(bf))) {							struct syparm *sy;							for (sy = parms; sy; sy = sy->next)								if (!zcmp(sy->name, bf))									break;							if (sy)								st->ignore = 0;							st->skip = 0;						} else {							i_printf_2((char *)joe_gettext(_("%s %d: missing parameter for ifdef\n")),name,line);						}					}					stack = st;				} else if (!zcmp(bf, USTR "else")) {					if (stack && !stack->else_part) {						stack->else_part = 1;						if (!stack->skip)							stack->ignore = !stack->ignore;					} else						i_printf_2((char *)joe_gettext(_("%s %d: else with no matching if\n")),name,line);				} else if (!zcmp(bf, USTR "endif")) {					if (stack) {						struct ifstack *st = stack;						stack = st->next;						joe_free(st);					} else						i_printf_2((char *)joe_gettext(_("%s %d: endif with no matching if\n")),name,line);				} else if (!zcmp(bf, USTR "subr")) {					parse_ws(&p, '#');					if (parse_ident(&p, bf, sizeof(bf))) {						i_printf_2((char *)joe_gettext(_("%s %d: Missing subroutine name\n")),name,line);					} else {						if (!stack || !stack->ignore) {							inside_subr = 1;							this_one = 0;							if (subr && !zcmp(bf, subr))								this_one = 1;						}					}				} else if (!zcmp(bf, USTR "end")) {					if (!stack || !stack->ignore) {						this_one = 0;						inside_subr = 0;					}				} else {					i_printf_2((char *)joe_gettext(_("%s %d: Unknown control statement\n")),name,line);				}			} else {				i_printf_2((char *)joe_gettext(_("%s %d: Missing control statement name\n")),name,line);			}		} else if (stack && stack->ignore) {			/* Ignore this line because of ifdef */		} else if(!parse_char(&p, '=')) {			/* Parse color */			parse_color_def(&syntax->color,p,name,line);		} else if ((subr && !this_one) || (!subr && inside_subr)) {			/* Ignore this line because it's not the code we want */		} else if(!parse_char(&p, ':')) {			if(!parse_ident(&p, bf, sizeof(bf))) {				state = find_state(syntax,prefix,bf);				if (!first)					first = state;				parse_ws(&p,'#');				if(!parse_ident(&p,bf,sizeof(bf))) {					struct high_color *color;					for(color=syntax->color;color;color=color->next)						if(!zcmp(color->name,bf))							break;					if(color)						state->color=color->color;					else {						state->color=0;						i_printf_2((char *)joe_gettext(_("%s %d: Unknown class\n")),name,line);					}				} else					i_printf_2((char *)joe_gettext(_("%s %d: Missing color for state definition\n")),name,line);			} else				i_printf_2((char *)joe_gettext(_("%s %d: Missing state name\n")),name,line);		} else if(!parse_char(&p, '-')) { /* No. sync lines */			if(parse_int(&p, &syntax->sync_lines))				syntax->sync_lines = -1;		} else {			c = parse_ws(&p,'#');			if (!c) {			} else if (c=='"' || c=='*' || c=='&') {				if (state) {					struct high_cmd *cmd;					int delim = 0;					if(!parse_field(&p, USTR "*")) {						int z;						for(z=0;z!=256;++z)							clist[z] = 1;					} else if(!parse_field(&p, USTR "&")) {						delim = 1;					} else {						c = parse_string(&p, bf, sizeof(bf));						if(c < 0)							i_printf_2((char *)joe_gettext(_("%s %d: Bad string\n")),name,line);						else {							int z;							int first, second;							unsigned char *t = bf;							for(z=0;z!=256;++z)								clist[z] = 0;							while(!parse_range(&t, &first, &second)) {								if(first>second)									second = first;								while(first<=second)									clist[first++] = 1;							}						}					}					/* Create command */					cmd = mkcmd();					parse_ws(&p,'#');					if(!parse_ident(&p,bf,sizeof(bf))) {						int z;						cmd->new_state = find_state(syntax,prefix,bf);						/* Parse options */						while (parse_ws(&p,'#'), !parse_ident(&p,bf,sizeof(bf)))							if(!zcmp(bf,USTR "buffer")) {								cmd->start_buffering = 1;							} else if(!zcmp(bf,USTR "hold")) {								cmd->stop_buffering = 1;							} else if(!zcmp(bf,USTR "return")) {								if (rtn)									cmd->new_state = rtn;							} else if(!zcmp(bf,USTR "save_c")) {								cmd->save_c = 1;							} else if(!zcmp(bf,USTR "save_s")) {								cmd->save_s = 1;							} else if(!zcmp(bf,USTR "recolor")) {								parse_ws(&p,'#');								if(!parse_char(&p,'=')) {									parse_ws(&p,'#');									if(parse_int(&p,&cmd->recolor))										i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")),name,line);								} else									i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")),name,line);							} else if(!zcmp(bf,USTR "call")) {								parse_ws(&p,'#');								if(!parse_char(&p,'=')) {									parse_ws(&p,'#');									if (!parse_char(&p,'.')) {										cmd->call = zdup(short_name);										goto subr;									} else if (parse_ident(&p,bf1,sizeof(bf1)))										i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")),name,line);									else {										cmd->call = zdup(bf1);										if (!parse_char(&p,'.')) {											subr:											if (parse_ident(&p,bf1,sizeof(bf1)))												i_printf_2((char *)joe_gettext(_("%s %d: Missing subroutine name\n")),name,line);											else												cmd->call_subr = zdup(bf1);										}										*needs_link = 1;										cmd->parms = parse_parms(&p,name,line);									}								} else									i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")),name,line);							} else if(!zcmp(bf,USTR "strings") || !zcmp(bf,USTR "istrings")) {								if (bf[0]=='i')									cmd->ignore = 1;								while(fgets((char *)buf,1023,f)) {									++line;									p = buf;									c = parse_ws(&p,'#');									if (*p) {										if(!parse_field(&p,USTR "done"))											break;										if(parse_string(&p,bf,sizeof(bf)) >= 0) {											parse_ws(&p,'#');											if (cmd->ignore)												lowerize(bf);											if(!parse_ident(&p,bf1,sizeof(bf1))) {												struct high_cmd *kw_cmd=mkcmd();												kw_cmd->noeat=1;												kw_cmd->new_state = find_state(syntax,prefix,bf1);												if (!zcmp(bf, USTR "&")) {													cmd->delim = kw_cmd;												} else {													if(!cmd->keywords)														cmd->keywords = htmk(64);														htadd(cmd->keywords,zdup(bf),kw_cmd);												}												while (parse_ws(&p,'#'), !parse_ident(&p,bf,sizeof(bf)))													if(!zcmp(bf,USTR "buffer")) {														kw_cmd->start_buffering = 1;													} else if(!zcmp(bf,USTR "hold")) {														kw_cmd->stop_buffering = 1;													} else if(!zcmp(bf,USTR "recolor")) {														parse_ws(&p,'#');														if(!parse_char(&p,'=')) {															parse_ws(&p,'#');															if(parse_int(&p,&kw_cmd->recolor))																i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")),name,line);														} else															i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")),name,line);													} else														i_printf_2((char *)joe_gettext(_("%s %d: Unknown option\n")),name,line);											} else												i_printf_2((char *)joe_gettext(_("%s %d: Missing state name\n")),name,line);										} else											i_printf_2((char *)joe_gettext(_("%s %d: Missing string\n")),name,line);									}								}							} else if(!zcmp(bf,USTR "noeat")) {								cmd->noeat = 1;							} else if(!zcmp(bf,USTR "mark")) {								cmd->start_mark = 1;							} else if(!zcmp(bf,USTR "markend")) {								cmd->stop_mark = 1;							} else if(!zcmp(bf,USTR "recolormark")) {								cmd->recolor_mark = 1;							} else								i_printf_2((char *)joe_gettext(_("%s %d: Unknown option\n")),name,line);						/* Install command */						if (delim)							state->delim = cmd;						else for(z=0;z!=256;++z)							if(clist[z])								state->cmd[z]=cmd;					} else						i_printf_2((char *)joe_gettext(_("%s %d: Missing jump\n")),name,line);				} else					i_printf_2((char *)joe_gettext(_("%s %d: No state\n")),name,line);			} else				i_printf_2((char *)joe_gettext(_("%s %d: Unknown character\n")),name,line);		}	}	while (stack) {		struct ifstack *st = stack;		stack = st->next;		i_printf_2((char *)joe_gettext(_("%s %d: ifdef with no matching endif\n")),name,st->line);		joe_free(st);	}	fclose(f);	return first;}/* Load dfa */void link_syntax(struct high_syntax *syntax);struct high_syntax *load_dfa(unsigned char *name){	struct high_syntax *syntax;	/* New syntax table */	int needs_link = 0;	if (!name)		return NULL;	if(!attr_buf) {		attr_size = 1024;		attr_buf = joe_malloc(sizeof(int)*attr_size);	}	/* Find syntax table */	/* Already loaded? */	for(syntax=syntax_list;syntax;syntax=syntax->next)		if(!zcmp(syntax->name,name))			return syntax;	/* Create new one */	syntax = joe_malloc(sizeof(struct high_syntax));	syntax->name = zdup(name);	syntax->next = syntax_list;	syntax->nstates = 0;	syntax->color = 0;	syntax->states = joe_malloc(sizeof(struct high_state *)*(syntax->szstates = 64));	syntax->ht_states = htmk(syntax->szstates);	syntax->sync_lines = 50;	syntax->recur = 0;	iz_cmd(&syntax->default_cmd);	if (append_dfa(syntax,USTR "",name,NULL,&needs_link,NULL,NULL)) {		if (needs_link)			link_syntax(syntax);		/* dump_syntax(syntax); */		syntax_list = syntax;		return syntax;	} else {		htrm(syntax->ht_states);		joe_free(syntax->name);		joe_free(syntax->states);		joe_free(syntax);		return 0;	}}/* Link in subroutine calls made to other tables *//* List of existing subroutines */struct sub_list {	struct sub_list *next;	unsigned char *name;	struct high_state *rtn;	/* Return address */	struct high_state *sub;	/* Pointer to subroutine */};struct high_state *find_sub(struct sub_list *list,unsigned char *name,struct high_state *rtn){	/* printf("Find %s %p\n",name,(void *)rtn); */	while (list) {		if (!zcmp(list->name, name) && list->rtn==rtn)			return list->rtn;		list = list->next;	}	return 0;}struct sub_list *add_sub(struct sub_list *list,unsigned char *name,struct high_state *rtn,struct high_state *sub){	struct sub_list *l=(struct sub_list *)malloc(sizeof(struct sub_list));	l->next = list;	l->name = zdup(name);	l->rtn = rtn;	l->sub = sub;	/* printf("Add %p %s\n",(void *)rtn,name); */	return l;}void link_syntax(struct high_syntax *syntax){	int depth;	int start = 0;	struct sub_list *sub_list = 0;	for (depth = 0; depth != 5; ++depth) {		int inst = 0;		int x = start;		int nstates = syntax->nstates;		start = nstates;		for (; x != nstates; ++x) {			struct high_state *state = syntax->states[x];			int y;			for(y = 0; y != 256; ++y) {				struct high_cmd *cmd = state->cmd[y];				if (cmd->call) {					unsigned char buf1[256];					unsigned char buf[256];					struct high_state *sub;					int needs_link = 0;					joe_snprintf_3(buf1,sizeof(buf1),"%d.%s.%s",depth,cmd->call,cmd->call_subr);					/* printf("%s is looking for %s.%s\n",state->name,cmd->call,(cmd->call_subr?cmd->call_subr:USTR "")); */					if ( 1 ) { /* !(sub = find_sub(sub_list, buf1, cmd->new_state))) { */						/* printf("loading...\n"); */						joe_snprintf_2(buf,sizeof(buf),"%d.%d.",depth,inst++);						sub = append_dfa(syntax,buf,cmd->call,cmd->new_state,&needs_link,cmd->parms,cmd->call_subr);						if (sub)							sub_list = add_sub(sub_list, buf1, cmd->new_state, sub);					}					if (sub)						cmd->new_state = sub;					cmd->call = 0;				}			}		}	}}

⌨️ 快捷键说明

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