📄 scroll.c
字号:
while (i > 0 || j > 0) { p = matrix + i * (window_size + 1) + j; tem = p->insertcost; if (tem < p->writecost && tem < p->deletecost) { /* Insert should be done at vpos i-1, plus maybe some before */ queue[qi].count = p->insertcount; i -= p->insertcount; queue[qi++].pos = i + unchanged_at_top; } else if (p->deletecost < p->writecost) { /* Old line at vpos j-1, and maybe some before it, should be deleted */ j -= p->deletecount; if (!window) { set_terminal_window (window_size + unchanged_at_top); window = 1; } ins_del_lines (j + unchanged_at_top, - p->deletecount); } else { /* Best thing done here is no insert or delete */ /* Old line at vpos j-1 ends up at vpos i-1 */ current_screen->contents[i + offset - 1] = temp_screen->contents[j + offset - 1]; current_screen->used[i + offset - 1] = temp_screen->used[j + offset - 1]; current_screen->highlight[i + offset - 1] = temp_screen->highlight[j + offset - 1]; temp_screen->enable[j + offset - 1] = 1; i--; j--; } } if (!window && qi) { set_terminal_window (window_size + unchanged_at_top); window = 1; } /* Now do all insertions */ next = unchanged_at_top; for (i = qi - 1; i >= 0; i--) { ins_del_lines (queue[i].pos, queue[i].count); /* Mark the inserted lines as clear, and put into them the line-contents strings that were discarded during the deletions. Those are the ones for which temp_screen->enable was not set. */ tem = queue[i].pos; for (j = tem + queue[i].count - 1; j >= tem; j--) { current_screen->enable[j] = 0; while (temp_screen->enable[next]) next++; current_screen->contents[j] = temp_screen->contents[next++]; } } if (window) set_terminal_window (0);}/* Return number of lines in common between current screen contents and the text to be displayed, considering only vpos range START to END (not including END). Ignores short lines (length < 20) on the assumption that avoiding redrawing such a line will have little weight. */intscrolling_max_lines_saved (start, end, oldhash, newhash, cost) int start, end; int *oldhash, *newhash, *cost;{ struct { int hash; int count; } lines[01000]; register int i, h; register int matchcount = 0; bzero (lines, sizeof lines); /* Put new lines' hash codes in hash table. */ for (i = start; i < end; i++) { if (cost[i] > 20) { h = newhash[i] & 0777; lines[h].hash = newhash[i]; lines[h].count++; } } /* Look up old line hash codes in the hash table. Count number of matches between old lines and new. */ for (i = start; i < end; i++) { h = oldhash[i] & 0777; if (oldhash[i] == lines[h].hash) { matchcount++; if (--lines[h].count == 0) lines[h].hash = 0; } } return matchcount;}/* Return a measure of the cost of moving the lines starting with vpos FROM, up to but not including vpos TO, down by AMOUNT lines (AMOUNT may be negative). These are the same arguments that might be given to scroll_screen_lines to perform this scrolling. */scroll_cost (from, to, amount) int from, to, amount;{ /* Compute how many lines, at bottom of screen, will not be involved in actual motion. */ int ok_below = screen_height - to; if (amount > 0) ok_below -= amount; if (! scroll_region_ok) ok_below = 0; if (amount == 0) return 0; if (amount < 0) { int temp = to; to = from + amount; from = temp + amount; amount = - amount; } from += ok_below; to += ok_below; return (ILcost[from] + (amount - 1) * ILncost[from] + DLcost[to] + (amount - 1) * DLncost[to]);}/* Calculate the insert and delete line costs. We keep the ID costs in a precomputed array based on the position at which the I or D is performed. Also, there are two kinds of ID costs: the "once-only" and the "repeated". This is to handle both those terminals that are able to insert N lines at a time (once- only) and those that must repeatedly insert one line. The cost to insert N lines at line L is [tt.t_ILov + (screen_height + 1 - L) * tt.t_ILpf] + N * [tt.t_ILnov + (screen_height + 1 - L) * tt.t_ILnpf] ILov represents the basic insert line overhead. ILpf is the padding required to allow the terminal time to move a line: insertion at line L changes (screen_height + 1 - L) lines. The first bracketed expression above is the overhead; the second is the multiply factor. Both are dependent only on the position at which the insert is performed. We store the overhead in ILcost and the multiply factor in ILncost. Note however that any insertion must include at least one multiply factor. Rather than compute this as ILcost[line]+ILncost[line], we add ILncost into ILcost. This is reasonable because of the particular algorithm used in calcM. Deletion is essentially the same as insertion. */CalcIDCosts (ins_line_string, multi_ins_string, del_line_string, multi_del_string, setup_string, cleanup_string) char *ins_line_string, *multi_ins_string; char *del_line_string, *multi_del_string; char *setup_string, *cleanup_string;{ /* Discourage long scrolls slightly on fast lines. This says that scrolling nearly the full length of the screen is not worth it if reprinting takes less than 1/4 second. */ int extra = baud_rate / (10 * 4 * screen_height); if (ILcost != 0) { ILcost = (int *) xrealloc (ILcost, screen_height * sizeof (int)); DLcost = (int *) xrealloc (DLcost, screen_height * sizeof (int)); ILncost = (int *) xrealloc (ILncost, screen_height * sizeof (int)); DLncost = (int *) xrealloc (DLncost, screen_height * sizeof (int)); } else { ILcost = (int *) xmalloc (screen_height * sizeof (int)); DLcost = (int *) xmalloc (screen_height * sizeof (int)); ILncost = (int *) xmalloc (screen_height * sizeof (int)); DLncost = (int *) xmalloc (screen_height * sizeof (int)); } CalcIDCosts1 (ins_line_string, multi_ins_string, setup_string, cleanup_string, ILcost, ILncost, extra); CalcIDCosts1 (del_line_string, multi_del_string, setup_string, cleanup_string, DLcost, DLncost, 0);}CalcIDCosts1 (one_line_string, multi_string, setup_string, cleanup_string, costvec, ncostvec, extra) char *one_line_string, *multi_string; char *setup_string, *cleanup_string; int *costvec, *ncostvec; int extra;{ if (calculate_costs_hook) (*calculate_costs_hook) (extra, costvec, ncostvec); else if (dont_calculate_costs) CalcLID (0, 0, 0, 0, costvec, ncostvec); else if (multi_string) CalcLID (string_cost (multi_string), per_line_cost (multi_string), extra, 0, costvec, ncostvec); else if (one_line_string) CalcLID (string_cost (setup_string) + string_cost (cleanup_string), 0, string_cost (one_line_string) + extra, per_line_cost (one_line_string), costvec, ncostvec); else CalcLID (9999, 0, 9999, 0, costvec, ncostvec);}/* Calculate the line ID overhead and multiply factor values */CalcLID (ov1, pf1, ovn, pfn, ov, mf) int ov1, ovn; int pf1, pfn; register int *ov, *mf;{ register int i; register int insert_overhead = ov1 * 10 + screen_height * pf1; register int next_insert_cost = ovn * 10 + screen_height * pfn; for (i = 0; i < screen_height; i++) { *mf++ = next_insert_cost / 10; next_insert_cost -= pfn; *ov++ = (insert_overhead + next_insert_cost) / 10; insert_overhead -= pf1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -