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

📄 rc.c

📁 举世闻名的joe记事本源程序
💻 C
📖 第 1 页 / 共 3 页
字号:
			return -1;	}	if (notify)		*notify = 1;	bw->b->o = bw->o;	wfit(bw->parent->t);	updall();	return 0;}static int doabrt(MENU *m, int x, unsigned char **s){	optx = x;	for (x = 0; s[x]; ++x)		joe_free(s[x]);	joe_free(s);	return -1;}int umode(BW *bw){	int size;	unsigned char **s;	int x;	bw->b->o.readonly = bw->o.readonly = bw->b->rdonly;	for (size = 0; glopts[size].menu; ++size) ;	s = (unsigned char **) joe_malloc(sizeof(unsigned char *) * (size + 1));	for (x = 0; x != size; ++x) {		s[x] = (unsigned char *) joe_malloc(80);		/* FIXME: why 40 ??? */		switch (glopts[x].type) {		case 0:			joe_snprintf_2((s[x]), OPT_BUF_SIZE, "%s%s", joe_gettext(glopts[x].menu), *(int *)glopts[x].set ? "ON" : "OFF");			break;		case 1:			joe_snprintf_2((s[x]), OPT_BUF_SIZE, "%s%d", joe_gettext(glopts[x].menu), *(int *)glopts[x].set);			break;		case 2:		case 9:		case 13:		case 6:			zcpy(s[x], joe_gettext(glopts[x].menu));			break;		case 4:			joe_snprintf_2((s[x]), OPT_BUF_SIZE, "%s%s", joe_gettext(glopts[x].menu), *(int *) ((unsigned char *) &bw->o + glopts[x].ofst) ? "ON" : "OFF");			break;		case 5:			joe_snprintf_2((s[x]), OPT_BUF_SIZE, "%s%d", joe_gettext(glopts[x].menu), *(int *) ((unsigned char *) &bw->o + glopts[x].ofst));			break;		case 7:			joe_snprintf_2((s[x]), OPT_BUF_SIZE, "%s%d", joe_gettext(glopts[x].menu), *(int *) ((unsigned char *) &bw->o + glopts[x].ofst) + 1);			break;		}	}	s[x] = 0;	if (mkmenu(bw->parent, bw->parent, s, doopt, doabrt, NULL, optx, s, NULL))		return 0;	else		return -1;}/* Process rc file * Returns 0 if the rc file was succefully processed *        -1 if the rc file couldn't be opened *         1 if there was a syntax error in the file */int procrc(CAP *cap, unsigned char *name){	OPTIONS *o = &fdefault;	/* Current options */	KMAP *context = NULL;	/* Current context */	unsigned char buf[1024];	/* Input buffer */	JFILE *fd;		/* rc file */	int line = 0;		/* Line number */	int err = 0;		/* Set to 1 if there was a syntax error */	strncpy((char *)buf, (char *)name, sizeof(buf) - 1);	buf[sizeof(buf)-1] = '\0';#ifdef __MSDOS__	fd = jfopen(buf, "rt");#else	fd = jfopen(buf, "r");#endif	if (!fd)		return -1;	/* Return if we couldn't open the rc file */	fprintf(stderr,(char *)joe_gettext(_("Processing '%s'...")), name);	fflush(stderr);	while (jfgets(buf, sizeof(buf), fd)) {		line++;		switch (buf[0]) {		case ' ':		case '\t':		case '\n':		case '\f':		case 0:			break;	/* Skip comment lines */		case '=':	/* Define a global color */			{ /* # introduces comment */			parse_color_def(&global_colors,buf+1,name,line);			}			break;		case '*':	/* Select file types for file-type dependant options */			{ /* Space and tab introduce comments- which means we can't have them in the regex */				int x;				o = (OPTIONS *) joe_malloc(sizeof(OPTIONS));				*o = fdefault;				for (x = 0; buf[x] && buf[x] != '\n' && buf[x] != ' ' && buf[x] != '\t'; ++x) ;				buf[x] = 0;				o->next = options;				options = o;				o->name_regex = zdup(buf);			}			break;		case '+':	/* Set file contents match regex */			{ /* No comments allowed- entire line used. */				int x;				for (x = 0; buf[x] && buf[x] != '\n' && buf[x] != '\r'; ++x) ;				buf[x] = 0;				if (o)					o->contents_regex = zdup(buf+1);			}			break;		case '-':	/* Set an option */			{ /* parse option and arg.  arg goes to end of line.  This is bad. */				unsigned char *opt = buf + 1;				int x;				unsigned char *arg = NULL;				for (x = 0; buf[x] && buf[x] != '\n' && buf[x] != ' ' && buf[x] != '\t'; ++x) ;				if (buf[x] && buf[x] != '\n') {					buf[x] = 0;					for (arg = buf + ++x; buf[x] && buf[x] != '\n'; ++x) ;				}				buf[x] = 0;				if (!glopt(opt, arg, o, 2)) {					err = 1;					fprintf(stderr,(char *)joe_gettext(_("\n%s %d: Unknown option %s")), name, line, opt);				}			}			break;		case '{':	/* Process help text.  No comment allowed after {name */			{	/* everything after } is ignored. */				line = help_init(fd,buf,line);			}			break;		case ':':	/* Select context */			{				int x, c;				for (x = 1; !joe_isspace_eof(locale_map,buf[x]); ++x) ;				c = buf[x];				buf[x] = 0;				if (x != 1)					if (!zcmp(buf + 1, USTR "def")) {						int y;						for (buf[x] = c; joe_isblank(locale_map,buf[x]); ++x) ;						for (y = x; !joe_isspace_eof(locale_map,buf[y]); ++y) ;						c = buf[y];						buf[y] = 0;						if (y != x) {							int sta;							MACRO *m;							if (joe_isblank(locale_map,c)							    && (m = mparse(NULL, buf + y + 1, &sta)))								addcmd(buf + x, m);							else {								err = 1;								fprintf(stderr, (char *)joe_gettext(_("\n%s %d: macro missing from :def")), name, line);							}						} else {							err = 1;							fprintf(stderr, (char *)joe_gettext(_("\n%s %d: command name missing from :def")), name, line);						}					} else if (!zcmp(buf + 1, USTR "inherit")) {						if (context) {							for (buf[x] = c; joe_isblank(locale_map,buf[x]); ++x) ;							for (c = x; !joe_isspace_eof(locale_map,buf[c]); ++c) ;							buf[c] = 0;							if (c != x)								kcpy(context, kmap_getcontext(buf + x));							else {								err = 1;								fprintf(stderr, (char *)joe_gettext(_("\n%s %d: context name missing from :inherit")), name, line);							}						} else {							err = 1;							fprintf(stderr, (char *)joe_gettext(_("\n%s %d: No context selected for :inherit")), name, line);						}					} else if (!zcmp(buf + 1, USTR "include")) {						for (buf[x] = c; joe_isblank(locale_map,buf[x]); ++x) ;						for (c = x; !joe_isspace_eof(locale_map,buf[c]); ++c) ;						buf[c] = 0;						if (c != x) {							unsigned char bf[1024];							unsigned char *p = (unsigned char *)getenv("HOME");							int rtn = -1;							bf[0] = 0;							if (p && buf[x] != '/') {								joe_snprintf_2(bf,sizeof(bf),"%s/.joe/%s",p,buf + x);								rtn = procrc(cap, bf);							}							if (rtn == -1 && buf[x] != '/') {								joe_snprintf_2(bf,sizeof(bf),"%s%s",JOERC,buf + x);								rtn = procrc(cap, bf);							}							if (rtn == -1 && buf[x] == '/') {								joe_snprintf_1(bf,sizeof(bf),"%s",buf + x);								rtn = procrc(cap, bf);							}							switch (rtn) {							case 1:								err = 1;								break;							case -1:								fprintf(stderr, (char *)joe_gettext(_("\n%s %d: Couldn't open %s")), name, line, bf);								err = 1;								break;							}							context = 0;							o = &fdefault;						} else {							err = 1;							fprintf(stderr, (char *)joe_gettext(_("\n%s %d: :include missing file name")), name, line);						}					} else if (!zcmp(buf + 1, USTR "delete")) {						if (context) {							int y;							for (buf[x] = c; joe_isblank(locale_map,buf[x]); ++x) ;							for (y = x; buf[y] != 0 && buf[y] != '\t' && buf[y] != '\n' && (buf[y] != ' ' || buf[y + 1]															!= ' '); ++y) ;							buf[y] = 0;							kdel(context, buf + x);						} else {							err = 1;							fprintf(stderr, (char *)joe_gettext(_("\n%s %d: No context selected for :delete")), name, line);						}					} else {						context = kmap_getcontext(buf + 1);					}				else {					err = 1;					fprintf(stderr,(char *)joe_gettext(_("\n%s %d: Invalid context name")), name, line);				}			}			break;		default:	/* Get key-sequence to macro binding */			{				int x, y;				MACRO *m;				if (!context) {					err = 1;					fprintf(stderr,(char *)joe_gettext(_("\n%s %d: No context selected for macro to key-sequence binding")), name, line);					break;				}				m = 0;			      macroloop:				m = mparse(m, buf, &x);				if (x == -1) {					err = 1;					fprintf(stderr,(char *)joe_gettext(_("\n%s %d: Unknown command in macro")), name, line);					break;				} else if (x == -2) {					jfgets(buf, 1024, fd);					++line;					goto macroloop;				}				if (!m)					break;				/* Skip to end of key sequence */				for (y = x; buf[y] != 0 && buf[y] != '\t' && buf[y] != '\n' && (buf[y] != ' ' || buf[y + 1] != ' '); ++y) ;				buf[y] = 0;				/* Add binding to context */				if (kadd(cap, context, buf + x, m) == -1) {					fprintf(stderr,(char *)joe_gettext(_("\n%s %d: Bad key sequence '%s'")), name, line, buf + x);					err = 1;				}			}			break;		}	}	jfclose(fd);		/* Close rc file */	/* Print proper ending string */	if (err)		fprintf(stderr, (char *)joe_gettext(_("\ndone\n")));	else		fprintf(stderr, (char *)joe_gettext(_("done\n")));	return err;		/* 0 for success, 1 for syntax error */}/* Save a history buffer */void save_hist(FILE *f,B *b){	unsigned char buf[512];	int len;	if (b) {		P *p = pdup(b->bof, USTR "save_hist");		P *q = pdup(b->bof, USTR "save_hist");		if (b->eof->line>10)			pline(p,b->eof->line-10);		pset(q,p);		while (!piseof(p)) {			pnextl(q);			if (q->byte-p->byte<512) {				len = q->byte - p->byte;				brmem(p,buf,len);			} else {				brmem(p,buf,512);				len = 512;			}			fprintf(f,"\t");			emit_string(f,buf,len);			fprintf(f,"\n");			pset(p,q);		}		prm(p);		prm(q);	}	fprintf(f,"done\n");}/* Load a history buffer */void load_hist(FILE *f,B **bp){	B *b;	unsigned char buf[1024];	unsigned char bf[1024];	P *q;	b = *bp;	if (!b)		*bp = b = bmk(NULL);	q = pdup(b->eof, USTR "load_hist");	while(fgets((char *)buf,1023,f) && zcmp(buf,USTR "done\n")) {		unsigned char *p = buf;		int len;		parse_ws(&p,'#');		len = parse_string(&p,bf,sizeof(bf));		if (len>0) {			binsm(q,bf,len);			pset(q,b->eof);		}	}	prm(q);}/* Save state */#define STATE_ID (unsigned char *)"# JOE state file v1.0\n"void save_state(){	unsigned char *home = (unsigned char *)getenv("HOME");	int old_mask;	FILE *f;	if (!joe_state)		return;	if (!home)		return;	joe_snprintf_1(stdbuf,stdsiz,"%s/.joe_state",home);	old_mask = umask(0066);	f = fopen((char *)stdbuf,"w");	umask(old_mask);	if(!f)		return;	/* Write ID */	fprintf(f,"%s",(char *)STATE_ID);	/* Write state information */	fprintf(f,"search\n"); save_srch(f);	fprintf(f,"macros\n"); save_macros(f);	fprintf(f,"files\n"); save_hist(f,filehist);	fprintf(f,"find\n"); save_hist(f,findhist);	fprintf(f,"replace\n"); save_hist(f,replhist);	fprintf(f,"run\n"); save_hist(f,runhist);	fprintf(f,"build\n"); save_hist(f,buildhist);	fprintf(f,"grep\n"); save_hist(f,grephist);	fprintf(f,"cmd\n"); save_hist(f,cmdhist);	fprintf(f,"math\n"); save_hist(f,mathhist);	fprintf(f,"yank\n"); save_yank(f);	fprintf(f,"file_pos\n"); save_file_pos(f);	fclose(f);}/* Load state */void load_state(){	unsigned char *home = (unsigned char *)getenv("HOME");	unsigned char buf[1024];	FILE *f;	if (!joe_state)		return;	if (!home)		return;	joe_snprintf_1(stdbuf,stdsiz,"%s/.joe_state",home);	f = fopen((char *)stdbuf,"r");	if(!f)		return;	/* Only read state information if the version is correct */	if (fgets((char *)buf,1024,f) && !zcmp(buf,STATE_ID)) {		/* Read state information */		while(fgets((char *)buf,1023,f)) {			if(!zcmp(buf,USTR "search\n"))				load_srch(f);			else if(!zcmp(buf,USTR "macros\n"))				load_macros(f);			else if(!zcmp(buf,USTR "files\n"))				load_hist(f,&filehist);			else if(!zcmp(buf,USTR "find\n"))				load_hist(f,&findhist);			else if(!zcmp(buf,USTR "replace\n"))				load_hist(f,&replhist);			else if(!zcmp(buf,USTR "run\n"))				load_hist(f,&runhist);			else if(!zcmp(buf,USTR "build\n"))				load_hist(f,&buildhist);			else if(!zcmp(buf,USTR "grep\n"))				load_hist(f,&grephist);			else if(!zcmp(buf,USTR "cmd\n"))				load_hist(f,&cmdhist);			else if(!zcmp(buf,USTR "math\n"))				load_hist(f,&mathhist);			else if(!zcmp(buf,USTR "yank\n"))				load_yank(f);			else if (!zcmp(buf,USTR "file_pos\n"))				load_file_pos(f);			else { /* Unknown... skip until next done */				while(fgets((char *)buf,1023,f) && zcmp(buf,USTR "done\n"));			}		}	}	fclose(f);}

⌨️ 快捷键说明

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