📄 screen.c
字号:
clrline(Screen[bot].s_line, Screen[bot].s_length); Screen[bot].s_length = Screen[bot].s_line; bot -= 1; }#ifdef IBMPC scr_win(num, (unsigned char) top, 0, (unsigned char) bottom, CHPL-1);#else /* !IBMPC */# ifdef MAC d_lines(top, bottom, num);# else /* !MAC */ (*TTdel_line)(top, bottom, num);# endif /* !MAC */#endif /* !IBMPC */}#ifdef TERMCAP /* remainder of this file *//* The cursor optimization happens here. You may decide that this is going too far with cursor optimization, or perhaps it should limit the amount of checking to when the output speed is slow. What ever turns you on ... */struct cursaddr { int cm_numchars; void (*cm_proc) ();};private char *Cmstr;private struct cursaddr *HorMin, *VertMin, *DirectMin;private void GENi_lines proto((int, int, int)), GENd_lines proto((int, int, int)), ForMotion proto((int)), ForTab proto((int)), BackMotion proto((int)), RetTab proto((int)), DownMotion proto((int)), UpMotion proto((int)), GoDirect proto((int, int)), HomeGo proto((int, int)), BottomUp proto((int, int));private struct cursaddr WarpHor[] = { 0, ForMotion, 0, ForTab, 0, BackMotion, 0, RetTab};private struct cursaddr WarpVert[] = { 0, DownMotion, 0, UpMotion};private struct cursaddr WarpDirect[] = { 0, GoDirect, 0, HomeGo, 0, BottomUp};#undef FORWARD#define FORWARD 0 /* Move forward */#define FORTAB 1 /* Forward using tabs */#undef BACKWARD#define BACKWARD 2 /* Move backward */#define RETFORWARD 3 /* Beginning of line and then tabs */#define NUMHOR 4#define DOWN 0 /* Move down */#define UPMOVE 1 /* Move up */#define NUMVERT 2#define DIRECT 0 /* Using CM */#define HOME 1 /* HOME */#define LOWER 2 /* Lower Line */#define NUMDIRECT 3#define home() Placur(0, 0)#define LowLine() { putpad(LL, 1); CapLine = ILI; CapCol = 0; }#define PrintHo() { putpad(HO, 1); CapLine = CapCol = 0; }int phystab = 8;private voidGoDirect(line, col)register int line, col;{ putpad(Cmstr, 1); CapLine = line; CapCol = col;}private voidRetTab(col)register int col;{ jputchar('\r'); CapCol = 0; ForTab(col);}private voidHomeGo(line, col)int line, col;{ PrintHo(); DownMotion(line); ForTab(col);}private voidBottomUp(line, col)register int line, col;{ LowLine(); UpMotion(line); ForTab(col);}/* Tries to move forward using tabs (if possible). It tabs to the closest tabstop which means it may go past 'destcol' and backspace to it. */private voidForTab(destcol)int destcol;{ register int tabgoal, ntabs, tabstp = phystab; if (TABS && (tabstp > 0)) { tabgoal = destcol + (tabstp / 2); tabgoal -= (tabgoal % tabstp); /* Don't tab to last place or else it is likely to screw up. */ if (tabgoal >= CO) tabgoal -= tabstp; ntabs = (tabgoal / tabstp) - (CapCol / tabstp); while (--ntabs >= 0) jputchar('\t'); CapCol = tabgoal; } if (CapCol > destcol) BackMotion(destcol); else if (CapCol < destcol) ForMotion(destcol);}private voidForMotion(destcol)register int destcol;{ register int nchars = destcol - CapCol; register char *cp = &Screen[CapLine].s_line[CapCol]; while (--nchars >= 0) jputchar(*cp++ & CHARMASK); CapCol = destcol;}private voidBackMotion(destcol)register int destcol;{ register int nchars = CapCol - destcol; if (BC) while (--nchars >= 0) putpad(BC, 1); else while (--nchars >= 0) jputchar('\b'); CapCol = destcol;}private voidDownMotion(destline)register int destline;{ register int nlines = destline - CapLine; while (--nlines >= 0) putpad(DO, 1); CapLine = destline;}private voidUpMotion(destline)register int destline;{ register int nchars = CapLine - destline; while (--nchars >= 0) putpad(UP, 1); CapLine = destline;}#ifdef ID_CHARstatic int EIlen;#endifvoidInitCM(){ HOlen = HO ? strlen(HO) : 1000; LLlen = LL ? strlen(LL) : 1000; UPlen = UP ? strlen(UP) : 1000;#ifdef ID_CHAR if (EI) EIlen = strlen(EI);#endif}private int ForNum proto((int from, int to));voidPlacur(line, col)int line, col;{ int dline, /* Number of lines to move */ dcol; /* Number of columns to move */ register int best, i; register struct cursaddr *cp; int xtracost = 0; /* Misc addition to cost. */#define CursMin(which,addrs,max) { \ for (best = 0, cp = &(addrs)[1], i = 1; i < (max); i++, cp++) \ if (cp->cm_numchars < (addrs)[best].cm_numchars) \ best = i; \ (which) = &(addrs)[best]; \} if (line == CapLine && col == CapCol) return; /* We are already there. */ dline = line - CapLine; dcol = col - CapCol;#ifdef ID_CHAR if (IN_INSmode && MI) xtracost = EIlen + IMlen; /* If we're already in insert mode, it is likely that we will want to be in insert mode again, after the insert. */#endif /* Number of characters to move horizontally for each case. 1: Just move forward by typing the right character on the screen. 2: Print the correct number of back spaces. 3: Try tabbing to the correct place. 4: Try going to the beginning of the line, and then tab. */ if (dcol == 1 || dcol == 0) { /* Most common case. */ HorMin = &WarpHor[FORWARD]; HorMin->cm_numchars = dcol + xtracost; } else { WarpHor[FORWARD].cm_numchars = dcol >= 0 ? dcol + xtracost : 1000; WarpHor[BACKWARD].cm_numchars = dcol < 0 ? -(dcol + xtracost) : 1000; WarpHor[FORTAB].cm_numchars = dcol >= 0 && TABS ? ForNum(CapCol, col) + xtracost : 1000; WarpHor[RETFORWARD].cm_numchars = (xtracost + 1 + (TABS ? ForNum(0, col) : col)); /* Which is the shortest of the bunch */ CursMin(HorMin, WarpHor, NUMHOR); } /* Moving vertically is more simple. */ WarpVert[DOWN].cm_numchars = dline >= 0 ? dline : 1000; WarpVert[UPMOVE].cm_numchars = dline < 0 ? ((-dline) * UPlen) : 1000; /* Which of these is simpler */ CursMin(VertMin, WarpVert, NUMVERT); /* Homing first and lowering first are considered direct motions. Homing first's total is the sum of the cost of homing and the sum of tabbing (if possible) to the right. */ if (VertMin->cm_numchars + HorMin->cm_numchars <= 3) { DirectMin = &WarpDirect[DIRECT]; /* A dummy ... */ DirectMin->cm_numchars = 100; } else { WarpDirect[DIRECT].cm_numchars = CM ? strlen(Cmstr = tgoto(CM, col, line)) : 1000; WarpDirect[HOME].cm_numchars = HOlen + line + WarpHor[RETFORWARD].cm_numchars; WarpDirect[LOWER].cm_numchars = LLlen + ((ILI - line) * UPlen) + WarpHor[RETFORWARD].cm_numchars; CursMin(DirectMin, WarpDirect, NUMDIRECT); } if (HorMin->cm_numchars + VertMin->cm_numchars < DirectMin->cm_numchars) { if (line != CapLine) (*(void (*)ptrproto((int)))VertMin->cm_proc)(line); if (col != CapCol) {#ifdef ID_CHAR if (IN_INSmode) /* We may use real characters ... */ INSmode(OFF);#endif (*(void (*)ptrproto((int)))HorMin->cm_proc)(col); } } else {#ifdef ID_CHAR if (IN_INSmode && !MI) INSmode(OFF);#endif (*(void (*)ptrproto((int, int)))DirectMin->cm_proc)(line, col); }}#define abs(x) ((x) >= 0 ? (x) : -(x))private intForNum(from, to)register int from;int to;{ register int tabgoal, tabstp = phystab; int numchars = 0; if (from >= to) return from - to; if (TABS && (tabstp > 0)) { tabgoal = to + (tabstp / 2); tabgoal -= (tabgoal % tabstp); if (tabgoal >= CO) tabgoal -= tabstp; numchars = (tabgoal / tabstop) - (from / tabstp); from = tabgoal; } return numchars + abs(from - to);}#ifdef WIRED_TERMSprivate voidBGi_lines(top, bottom, num)int top, bottom, num;{ writef("\033[%d;%dr\033[%dL\033[r", top + 1, bottom + 1, num); CapCol = CapLine = 0;}private voidSUNi_lines(top, bottom, num)int top, bottom, num;{ Placur(bottom - num + 1, 0); writef("\033[%dM", num); Placur(top, 0); writef("\033[%dL", num);}private voidC100i_lines(top, bottom, num)int top, bottom, num;{ if (num <= 1) { GENi_lines(top, bottom, num); return; } writef("\033v%c%c%c%c", ' ', ' ', ' ' + bottom + 1, ' ' + CO); CapLine = CapCol = 0; Placur(top, 0); while (num--) putpad(AL, ILI - CapLine); writef("\033v%c%c%c%c", ' ', ' ', ' ' + LI, ' ' + CO); CapLine = CapCol = 0;}#endif /* WIRED_TERMS */private voidGENi_lines(top, bottom, num)int top, bottom, num;{ register int i; if (CS) { putpad(tgoto(CS, bottom, top), 1); CapCol = CapLine = 0; Placur(top, 0); if (M_SR && (num > 1)) { char minibuf[16]; sprintf(minibuf, M_SR, num); putpad(minibuf, bottom - top); } else { for (i = 0; i < num; i++) putpad(SR, bottom - top); } putpad(tgoto(CS, ILI, 0), 1); CapCol = CapLine = 0; } else { Placur(bottom - num + 1, 0); if (M_DL && (num > 1)) { putargpad(M_DL, num, ILI - CapLine); } else { for (i = 0; i < num; i++) putpad(DL, ILI - CapLine); } Placur(top, 0); if (M_AL && (num > 1)) { putargpad(M_AL, num, ILI - CapLine); } else { for (i = 0; i < num; i++) putpad(AL, ILI - CapLine); } }}#ifdef WIRED_TERMSprivate voidBGd_lines(top, bottom, num)int top, bottom, num;{ writef("\033[%d;%dr\033[%dM\033[r", top + 1, bottom + 1, num); CapCol = CapLine = 0;}private voidSUNd_lines(top, bottom, num)int top, bottom, num;{ Placur(top, 0); writef("\033[%dM", num); Placur(bottom + 1 - num, 0); writef("\033[%dL", num);}private voidC100d_lines(top, bottom, num)int top, bottom, num;{ if (num <= 1) { GENd_lines(top, bottom, num); return; } writef("\033v%c%c%c%c", ' ', ' ', ' ' + bottom + 1, ' ' + CO); CapLine = CapCol = 0; Placur(top, 0); while (num--) putpad(DL, ILI - CapLine); writef("\033v%c%c%c%c", ' ', ' ', ' ' + LI, ' ' + CO); CapLine = CapCol = 0;}#endif /* WIRED_TERMS */private voidGENd_lines(top, bottom, num)int top, bottom, num;{ register int i; if (CS) { putpad(tgoto(CS, bottom, top), 1); CapCol = CapLine = 0; Placur(bottom, 0); if (M_SF && (num > 1)) { char minibuf[16]; sprintf(minibuf, M_SF, num); putpad(minibuf, bottom - top); } else { for (i = 0; i < num; i++) putpad(SF, bottom - top); } putpad(tgoto(CS, ILI, 0), 1); CapCol = CapLine = 0; } else { Placur(top, 0); if (M_DL && (num > 1)) { putargpad(M_DL, num, ILI - top); } else { for (i = 0; i < num; i++) putpad(DL, ILI - top); } Placur(bottom + 1 - num, 0); if (M_AL && (num > 1)) { putargpad(M_AL, num, ILI - CapLine); } else { for (i = 0; i < num; i++) putpad(AL, ILI - CapLine); } }}private const struct ID_lookup { char *ID_name; void (*I_proc) proto((int, int, int)); /* proc to insert lines */ void (*D_proc) proto((int, int, int)); /* proc to delete lines */} ID_trms[] = { "generic", GENi_lines, GENd_lines, /* This should stay here */#ifdef WIRED_TERMS "sun", SUNi_lines, SUNd_lines, "bg", BGi_lines, BGd_lines, "c1", C100i_lines, C100d_lines,#endif /* WIRED_TERMS */ NULL, 0, 0};voidIDline_setup(tname)char *tname;{ register const struct ID_lookup *idp; for (idp = &ID_trms[1]; idp->ID_name; idp++) if (strncmp(idp->ID_name, tname, strlen(idp->ID_name)) == 0) break; if (idp->ID_name == NULL) idp = &ID_trms[0]; TTins_line = idp->I_proc; TTdel_line = idp->D_proc;}#endif /* TERMCAP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -