|
|
1.1 root 1: /* misc.c */
2:
3: /* Author:
4: * Steve Kirkendall
5: * 14407 SW Teal Blvd. #C
6: * Beaverton, OR 97005
7: * [email protected]
8: */
9:
10:
11: /* This file contains functions which didn't seem happy anywhere else */
12:
13: #include "config.h"
14: #include "vi.h"
15:
16:
17: /* find a particular line & return a pointer to a copy of its text */
18: char *fetchline(line)
19: long line; /* line number of the line to fetch */
20: {
21: int i;
22: REG char *scan; /* used to search for the line in a BLK */
23: long l; /* line number counter */
24: static BLK buf; /* holds ONLY the selected line (as string) */
25: REG char *cpy; /* used while copying the line */
26: static long nextline; /* } These four variables are used */
27: static long chglevel; /* } to implement a shortcut when */
28: static char *nextscan; /* } consecutive lines are fetched */
29: static long nextlnum; /* } */
30:
31: /* can we do a shortcut? */
32: if (changes == chglevel && line == nextline)
33: {
34: scan = nextscan;
35: }
36: else
37: {
38: /* scan lnum[] to determine which block its in */
39: for (i = 1; line > lnum[i]; i++)
40: {
41: }
42: nextlnum = lnum[i];
43:
44: /* fetch text of the block containing that line */
45: scan = blkget(i)->c;
46:
47: /* find the line in the block */
48: for (l = lnum[i - 1]; ++l < line; )
49: {
50: while (*scan++ != '\n')
51: {
52: }
53: }
54: }
55:
56: /* copy it into a block by itself, with no newline */
57: for (cpy = buf.c; *scan != '\n'; )
58: {
59: *cpy++ = *scan++;
60: }
61: *cpy = '\0';
62:
63: /* maybe speed up the next call to fetchline() ? */
64: if (line < nextlnum)
65: {
66: nextline = line + 1;
67: chglevel = changes;
68: nextscan = scan + 1;
69: }
70: else
71: {
72: nextline = 0;
73: }
74:
75: /* Calls to fetchline() interfere with calls to pfetch(). Make sure
76: * that pfetch() resets itself on its next invocation.
77: */
78: pchgs = 0L;
79:
80: /* Return a pointer to the line's text */
81: return buf.c;
82: }
83:
84:
85: /* error message from the regexp code */
86: void regerror(txt)
87: char *txt; /* an error message */
88: {
89: msg("RE error: %s", txt);
90: }
91:
92: /* This function is equivelent to the pfetch() macro */
93: void pfetch(l)
94: long l; /* line number of line to fetch */
95: {
96: if(l != pline || changes != pchgs)
97: {
98: pline = (l);
99: ptext = fetchline(pline);
100: plen = strlen(ptext);
101: pchgs = changes;
102: }
103: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.