Repository navigation
Expand file tree
/
Copy patheequer.c
More file actions
executable file
·189 lines (174 loc) · 4.57 KB
/
Copy patheequer.c
File metadata and controls
executable file
·189 lines (174 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
* This software is quasi-public; it may be used freely with
* like software, but may NOT be sold or made part of licensed
* products without permission of the author.
*/
/*
* EEQUER Query-Replace and Replace-String functions
*/
#include "elle.h" /* include structure definitions */
/* EFUN: "Query Replace" */
/* Crude approximation of EMACS function.
*/
f_querep()
{ static struct majmode iqrpmode = { "Query Replace" };
ed_dorep(0, &iqrpmode);
}
/* EFUN: "Replace String" */
/* Similar to Query Replace and uses same code.
*/
f_repstr()
{ static struct majmode irepmode = { "Replace String" };
ed_dorep(1, &irepmode);
}
#if FX_REPLINE
/* EFUN: "Replace in Line" (not EMACS) */
/* Acts like Replace String but only operates on current line.
** Currently a big crock.
** Feature of crockishness is that Unkill Pop (M-Y) will restore old
** line.
*/
f_repline()
{
extern struct buffer *make_buf();
struct buffer *b, *oldb = cur_buf;
static struct majmode rlmode = { "Replace in Line" };
if(!(b = make_buf(" **LINE**")))
{ ring_bell();
return;
}
f_kline(); /* Kill line(s) from original buffer */
chg_buf(b); /* Switch to temp buffer */
f_unkill(); /* Get killed stuff into temp buffer */
e_gosetcur((chroff)0); /* Starting at beginning, */
ed_dorep(1, &rlmode); /* Execute Replace String on it. */
ed_kill((chroff)0, e_blen()); /* Now kill everything in it, */
chg_buf(oldb); /* switch back to original buffer, */
f_unkill(); /* and restore new stuff! */
kill_buf(b); /* Now flush temporary buffer. */
}
#endif
/* Note that the major mode is set without changing the buffer's major
* mode. When the function is done, the current major mode is reset
* from the buffer mode.
*/
ed_dorep(type, mode) /* 0 = Query Replace, 1 = Replace String */
int type;
struct majmode *mode;
{ register int c;
register int olen, allflg;
char *srch_ask();
char *opromp, *npromp;
char *nstr, *ostr; /* Note ostr is == to srch_str */
int nlen;
chroff last_loc;
#if IMAGEN
int nrepled = 0;
char replmsg[64];
#endif /*IMAGEN*/
/* Set mode, then get search string and replace string */
#if IMAGEN
cur_win->w_buf->b_flags |= B_QUERYREP;
#else
cur_mode = mode; /* Set major mode pointer */
#endif /*-IMAGEN*/
redp(RD_MODE);
nstr = 0;
#if IMAGEN
opromp = "Old string: ";
npromp = "New string: ";
#else
opromp = "Replace string: ";
npromp = "with string: ";
#endif /*-IMAGEN*/
if((ostr = srch_ask(opromp)) == 0)
goto done;
olen = srch_len; /* srch_ask sets this! */
if((nstr = ask("%s%s %s", opromp, ostr, npromp)) == 0)
goto done;
nlen = ask_len;
/* Now enter search and subcommand loop */
allflg = type; /* Unless 0 for Query Rep, replace all */
for(;;)
{ last_loc = cur_dot;
if(e_search(ostr,olen,0) == 0)
break;
ed_setcur(); /* Cursor moved */
redisp:
if(!allflg) redisplay(); /* Update screen */
getcmd:
if(!allflg) c = cmd_read();
else c = SP;
switch(c)
{
#if IMAGEN
case 'n':
#endif /*IMAGEN*/
case DEL: /* Don't replace, go on */
continue;
#if IMAGEN
case ',':
#endif /*IMAGEN*/
case '.': /* Replace and exit */
case SP: /* Replace, go on */
ed_delete(cur_dot,(chroff)(cur_dot-olen));
ed_nsins(nstr,nlen);
#if IMAGEN
++nrepled;
#endif /*IMAGEN*/
if(c == '.') goto done;
continue;
#if IMAGEN
default:
#endif /*IMAGEN*/
case '?': /* Show options */
#if IMAGEN
saynow("\
' '=>change, 'n'=>don't, '.'=>change, quit, '!'=>change rest, '^'=>back up");
#else
saynow("\
SP=Replace, DEL=Don't, ESC=Stop, !=Replace all, ^=Back up, .=Replace & Stop");
#endif /*-IMAGEN*/
goto getcmd;
case '^': /* Return to last place found */
ed_go(last_loc);
goto redisp;
case CTRL('G'):
case ESC: /* Exit where we are */
goto done;
case CTRL('L'): /* Redisplay */
redp(RD_SCREEN);
goto redisp;
case '!': /* Replace all the rest */
allflg++;
goto getcmd;
#if !(IMAGEN)
case ',': /* Replace and show */
case CTRL('R'): /* Enter edit mode recursively */
case CTRL('W'): /* Delete once and ^R */
saynow("not implemented");
goto getcmd;
default: /* Exit and re-read char */
unrchf = c;
goto done;
#endif /*-IMAGEN*/
}
}
done:
#if IMAGEN
cur_win->w_buf->b_flags &= ~B_QUERYREP;
#else
cur_mode = cur_buf->b_mode;
#endif /*-IMAGEN*/
redp(RD_MODE);
if(nstr) /* Free nstr (but not ostr, it's == srch_str!) */
chkfree(nstr);
#if IMAGEN
if (nrepled <= 0)
saynow("No replacements done");
else
{ sprintf(replmsg, "Replaced %d occurences", nrepled);
saynow(replmsg);
}
#endif /*IMAGEN*/
}