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

📄 tw.c

📁 举世闻名的joe记事本源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  *	Text editing windows *	Copyright *		(C) 1992 Joseph H. Allen * *	This file is part of JOE (Joe's Own Editor) */#include "types.h"int staen = 0;int staupd = 0;int keepup = 0;int bg_stalin;/* Move text window */static void movetw(BW *bw, int x, int y){	TW *tw = (TW *) bw->object;	if (y || !staen) {		if (!tw->staon) {	/* Scroll down and shrink */			nscrldn(bw->parent->t->t, y, bw->parent->nh + y, 1);		}		bwmove(bw, x + (bw->o.linums ? LINCOLS : 0), y + 1);		tw->staon = 1;	} else {		if (tw->staon) {	/* Scroll up and grow */			nscrlup(bw->parent->t->t, y, bw->parent->nh + y, 1);		}		bwmove(bw, x + (bw->o.linums ? LINCOLS : 0), y);		tw->staon = 0;	}}/* Resize text window */static void resizetw(BW *bw, int wi, int he){	if (bw->parent->ny || !staen)		bwresz(bw, wi - (bw->o.linums ? LINCOLS : 0), he - 1);	else		bwresz(bw, wi - (bw->o.linums ? LINCOLS : 0), he);}/* Get current context *//* Find first line (going backwards) which has 0 indentation level * and is not a comment, blank, or block structuring line.  This is * likely to be the line with the function name. * * There are actually two possibilities: * * We want the first line-  * * int * foo(int x,int y) { * *   } * * We want the last line- * * program foo(input,output); * var a, b, c : real; * begin * */unsigned char *get_context(BW *bw){	P *p = pdup(bw->cursor, USTR "get_context");	static unsigned char buf1[stdsiz];	int i, j, spc;	buf1[0] = 0;	/* Find first line with 0 indentation which is not a comment line */	do {		p_goto_bol(p);		if (!pisindent(p) && !pisblank(p)) {			/* next: */			brzs(p,stdbuf,stdsiz/8); /* To avoid buffer overruns with my_iconv */			/* Ignore comment and block structuring lines */			if (!(stdbuf[0]=='{' ||			    (stdbuf[0]=='/' && stdbuf[1]=='*') ||			    stdbuf[0]=='\f' ||			    (stdbuf[0]=='/' && stdbuf[1]=='/') ||			    stdbuf[0]=='#' ||			    (stdbuf[0]=='b' && stdbuf[1]=='e' && stdbuf[2]=='g' && stdbuf[3]=='i' && stdbuf[4]=='n') ||			    (stdbuf[0]=='B' && stdbuf[1]=='E' && stdbuf[2]=='G' && stdbuf[3]=='I' && stdbuf[4]=='N') ||			    (stdbuf[0]=='-' && stdbuf[1]=='-') ||			    stdbuf[0]==';')) {			    	/* zcpy(buf1,stdbuf); */ 				/* replace tabs to spaces and remove adjoining spaces */ 				for (i=0,j=0,spc=0; stdbuf[i]; i++) { 					if (stdbuf[i]=='\t' || stdbuf[i]==' ') { 						if (spc) continue; 						spc = 1; 					} 					else spc = 0; 					if (stdbuf[i]=='\t') 						buf1[j++] = ' ';					else if (stdbuf[i]=='\\') {						buf1[j++] = '\\';						buf1[j++] = '\\';					} else						buf1[j++] = stdbuf[i]; 				} 				buf1[j]= '\0';				/* Uncomment to get the last line instead of the first line (see above)			    	if (pprevl(p)) {			    		p_goto_bol(p);			    		if (!pisindent(p) && !pisblank(p))			    			goto next;			    	}			    	*/			    	break;			}					}	} while (!buf1[0] && pprevl(p));	prm(p);	return buf1;}static unsigned char *stagen(unsigned char *stalin, BW *bw, unsigned char *s, int fill){	unsigned char buf[80];	int x;	W *w = bw->parent;	stalin = vstrunc(stalin, 0);	while (*s) {		if (*s == '%' && s[1]) {			switch (*++s) {			case 'x': /* Context (but only if autoindent is enabled) */				{					if ( bw->o.autoindent) {						unsigned char *s = get_context(bw);						/* We need to translate between file's character set to						   locale */						my_iconv(stdbuf,locale_map,s,bw->o.charmap);						stalin = vsncpy(sv(stalin), sz(stdbuf));					}				}				break;			case 'y':				{					if (bw->o.syntax) {						joe_snprintf_1(buf, sizeof(buf), "(%s)", bw->o.syntax->name);						stalin = vsncpy(sv(stalin), sz(buf));					}				}				break;			case 't':				{					time_t n = time(NULL);					int l;					unsigned char *d = (unsigned char *)ctime(&n);					l = (d[11] - '0') * 10 + d[12] - '0';					if (l > 12)						l -= 12;					joe_snprintf_1(buf, sizeof(buf), "%2.2d", l);					if (buf[0] == '0')						buf[0] = fill;					stalin = vsncpy(sv(stalin), buf, 2);					stalin = vsncpy(sv(stalin), d + 13, 3);				}				break;			case 'u':				{					time_t n = time(NULL);					unsigned char *d = (unsigned char *)ctime(&n);					stalin = vsncpy(sv(stalin), d + 11, 5);				}				break;			case 'T':				if (bw->o.overtype)					stalin = vsadd(stalin, 'O');				else					stalin = vsadd(stalin, 'I');				break;			case 'W':				if (bw->o.wordwrap)					stalin = vsadd(stalin, 'W');				else					stalin = vsadd(stalin, fill);				break;			case 'I':				if (bw->o.autoindent)					stalin = vsadd(stalin, 'A');				else					stalin = vsadd(stalin, fill);				break;			case 'X':				if (square)					stalin = vsadd(stalin, 'X');				else					stalin = vsadd(stalin, fill);				break;			case 'n':				{				if (bw->b->name) {					unsigned char *tmp = simplify_prefix(bw->b->name);					stalin = vsncpy(sv(stalin), sv(tmp));					vsrm(tmp);				} else {					stalin = vsncpy(sv(stalin), sz(joe_gettext(_("Unnamed"))));				}				}				break;			case 'm':				if (bw->b->changed)					stalin = vsncpy(sv(stalin), sz(joe_gettext(_("(Modified)"))));				break;			case 'R':				if (bw->b->rdonly)					stalin = vsncpy(sv(stalin), sz(joe_gettext(_("(Read only)"))));				break;			case '*':				if (bw->b->changed)					stalin = vsadd(stalin, '*');				else					stalin = vsadd(stalin, fill);				break;			case 'r':				joe_snprintf_1(buf, sizeof(buf), "%-4ld", bw->cursor->line + 1);				for (x = 0; buf[x]; ++x)					if (buf[x] == ' ')						buf[x] = fill;				stalin = vsncpy(sv(stalin), sz(buf));				break;			case 'o':				joe_snprintf_1(buf, sizeof(buf), "%-4lld", bw->cursor->byte);				for (x = 0; buf[x]; ++x)					if (buf[x] == ' ')						buf[x] = fill;				stalin = vsncpy(sv(stalin), sz(buf));				break;			case 'O':				joe_snprintf_1(buf, sizeof(buf), "%-4llX", bw->cursor->byte);				for (x = 0; buf[x]; ++x)					if (buf[x] == ' ')						buf[x] = fill;				stalin = vsncpy(sv(stalin), sz(buf));				break;			case 'a':				if (!piseof(bw->cursor))					joe_snprintf_1(buf, sizeof(buf), "%3d", 255 & brc(bw->cursor));				else					joe_snprintf_0(buf, sizeof(buf), "   ");				for (x = 0; buf[x]; ++x)					if (buf[x] == ' ')						buf[x] = fill;				stalin = vsncpy(sv(stalin), sz(buf));				break;			case 'A':				if (!piseof(bw->cursor))					joe_snprintf_1(buf, sizeof(buf), "%2.2X", 255 & brc(bw->cursor));				else					joe_snprintf_0(buf, sizeof(buf), "  ");				for (x = 0; buf[x]; ++x)					if (buf[x] == ' ')						buf[x] = fill;				stalin = vsncpy(sv(stalin), sz(buf));				break;			case 'c':				joe_snprintf_1(buf, sizeof(buf), "%-3ld", piscol(bw->cursor) + 1);				for (x = 0; buf[x]; ++x)					if (buf[x] == ' ')						buf[x] = fill;				stalin = vsncpy(sv(stalin), sz(buf));				break;			case 'p':				if (bw->b->eof->byte >= 1024*1024)					joe_snprintf_1(buf, sizeof(buf), "%3lld", (bw->cursor->byte >> 10) * 100 / (bw->b->eof->byte >> 10));				else if (bw->b->eof->byte)					joe_snprintf_1(buf, sizeof(buf), "%3lld", bw->cursor->byte * 100 / bw->b->eof->byte);				else					joe_snprintf_0(buf, sizeof(buf), "100");				for (x = 0; buf[x]; ++x)					if (buf[x] == ' ')						buf[x] = fill;				stalin = vsncpy(sv(stalin), sz(buf));				break;			case 'l':				joe_snprintf_1(buf, sizeof(buf), "%-4ld", bw->b->eof->line + 1);				for (x = 0; buf[x]; ++x)					if (buf[x] == ' ')						buf[x] = fill;				stalin = vsncpy(sv(stalin), sz(buf));				break;			case 'k':				{					int i;					unsigned char *cpos = buf;					buf[0] = 0;					if (w->kbd->x && w->kbd->seq[0])						for (i = 0; i != w->kbd->x; ++i) {							int c = w->kbd->seq[i] & 127;							if (c < 32) {								cpos[0] = '^';								cpos[1] = c + '@';								cpos += 2;							} else if (c == 127) {								cpos[0] = '^';								cpos[1] = '?';								cpos += 2;							} else {								cpos[0] = c;								cpos += 1;							}						}					*cpos++ = fill;					while (cpos - buf < 4)						*cpos++ = fill;					stalin = vsncpy(sv(stalin), buf, cpos - buf);				}				break;			case 'S':				if (bw->b->pid)					stalin = vsncpy(sv(stalin), sz(joe_gettext(_("*SHELL*"))));				break;			case 'M':				if (recmac) {					joe_snprintf_1(buf, sizeof(buf), joe_gettext(_("(Macro %d recording...)")), recmac->n);					stalin = vsncpy(sv(stalin), sz(buf));				}				break;			default:				stalin = vsadd(stalin, *s);			}		} else			stalin = vsadd(stalin, *s);		++s;	}	return stalin;}static void disptw(BW *bw, int flg){	W *w = bw->parent;

⌨️ 快捷键说明

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