-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmore.c
367 lines (323 loc) · 6.58 KB
/
more.c
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
/*_ more.c Mon Dec 10 2001 */
/* $Header$ */
/*
* Due to my (Bjorn Benson) laziness, the functions will all
* work with a positive argument, but may or may not with
* a negative.
*/
#include <stdio.h>
#include <ctype.h>
#include "ed.h"
int Dnoask_search = FALSE; /* TRUE for the search again function */
/*
* The multiple delete buffers
*/
#define DK_CUT 0
#define DK_LINE 1
#define DK_WORD 2
#define DK_CHAR 3
#define SETMARK { curwp->w_markp = curwp->w_dotp; curwp->w_marko = curwp->w_doto; }
/*
* Current direction that things happen in
*/
#define ADVANCE 0
#define BACKUP 1
static int Dcur_direction = ADVANCE;
Dsearch(f, n)
{
if( Dcur_direction == ADVANCE )
return( forwsearch(f, n) );
else return( backsearch(f, n) );
}
Dsearchagain(f, n)
{
register int s;
Dnoask_search = TRUE;
if( Dcur_direction == ADVANCE )
s = forwsearch(f, n);
else s = backsearch(f, n);
Dnoask_search = FALSE;
return( s );
}
Ddelline(f, n)
{
register int s = TRUE;
kill_setbuffer(DK_LINE);
kill_freebuffer();
while( n-- > 0 && s )
{ curwp->w_doto = 0;
s &= line_delete(llength(curwp->w_dotp) + 1, TRUE);
}
kill_setbuffer(DK_CUT);
return( s );
}
Dundelline(f, n)
{
register int s = TRUE;
kill_setbuffer(DK_LINE);
while( n-- > 0 && s )
{
curwp->w_doto = 0;
s = random_yank(TRUE, 1);
backline(FALSE, 1);
curwp->w_doto = 0;
}
kill_setbuffer(DK_CUT);
return( s );
}
Ddelword(f, n)
{
register int s = TRUE;
kill_setbuffer(DK_WORD);
kill_freebuffer();
while( n-- > 0 && s )
{
SETMARK;
s = word_forw(FALSE, 1);
if( !s ) break;
s = region_kill(FALSE, 1);
}
kill_setbuffer(DK_CUT);
return( s );
}
Ddelbword(f, n)
{
register int s = TRUE;
kill_setbuffer(DK_WORD);
kill_freebuffer();
while( n-- > 0 && s )
{
SETMARK;
s = word_back(FALSE, 1);
if( !s ) break;
s = region_kill(FALSE, 1);
}
kill_setbuffer(DK_CUT);
return( s );
}
Dundelword(f, n)
{
register int s = TRUE;
kill_setbuffer(DK_WORD);
while( n-- > 0 && s )
s &= random_yank(TRUE, 1);
kill_setbuffer(DK_CUT);
return( s );
}
Dadvance()
{
Dcur_direction = ADVANCE;
return( TRUE );
}
Dbackup()
{
Dcur_direction = BACKUP;
return( TRUE );
}
Dignore()
{
/* Ignore this command. Useful for ^S and ^Q flow control */
/* sent out by some terminals. */
return TRUE;
}
Dpause()
{
#ifdef hpux
return FALSE;
#else
#if BSDUNIX || LINUX
extern int sgarbf;
(*term.t_move)( term.t_nrow - 1, 0 );
(*term.t_eeop)();
ttflush();
ttclose();
killpg(getpgrp(0), 18); /* SIGTSTP -- stop the current program */
ttopen();
sgarbf = TRUE;
window_refresh(FALSE, 1);
#endif
return( TRUE );
#endif
}
/*********************************
* Decide whether to uppercase a word or a region.
*/
misc_upper(f,n)
int f,n;
{
if (curwp->w_markp)
return region_upper(f,n);
else
return word_upper(f,n);
}
/*********************************
* Decide whether to lowercase a word or a region.
*/
misc_lower(f,n)
int f,n;
{
if (curwp->w_markp)
return region_lower(f,n);
else
return word_lower(f,n);
}
/*********************************
* Insert file name and date at top of file.
*/
Dinsertdate(f,n)
int f,n;
{ int s,b;
char buf[100],*p;
if (!gotobob(FALSE,0)) /* move to beginning of buffer */
goto err;
/* search for "_ " */
strcpy(pat,"_ "); /* load search pattern */
b = Dnoask_search;
Dnoask_search = TRUE; /* don't prompt for search string */
s = forwsearch(FALSE,0); /* search forward for "_ " */
pat[0] = 0; /* eliminate search pattern */
Dnoask_search = b; /* restore to original value */
if (!s) /* if search failed */
goto err; /* quit */
if (!random_kill(FALSE,0)) /* delete to end of line */
goto err;
/* load up string to be inserted */
p = curbp->b_fname;
p += strlen(p);
while (p > curbp->b_fname && p[-1] != '/'
#if MSDOS || _WIN32
&& p[-1] != '\\' && p[-1] != ':'
#endif
) p--;
strcpy(buf,p); /* file name */
strcat(buf," "); /* followed by spaces */
#if !__OpenBSD__ || __FreeBSD__
#if BSDUNIX || LINUX || MSDOS || _WIN32
{ long t,time();
char *ctime(),*getlogin(),*getenv();
t = time((long *) NULL);
p = ctime(&t); /* p -> time string */
p[10] = 0;
p[24] = 0; /* remove the '\n' */
strcat(buf,p);
strcat(buf,p + 10 + 9);
p = getenv("NAME"); /* get user's name */
#if BSDUNIX || LINUX
if (!p)
p = getlogin(); /* get login name */
#endif
if (p)
{ strcat(buf," Modified by: ");
strcat(buf,p);
}
}
#endif
#endif
strcat(buf," */"); /* end of comment */
/* insert the string */
for (p = buf; *p; p++)
{ if (line_insert(1,*p) == FALSE)
goto err;
}
return TRUE; /* all succeeded */
err: return FALSE;
}
/***********************************
* Remove trailing whitespace from line.
*/
void deblank()
{ int len;
int n;
int c;
int i;
len = llength(curwp->w_dotp);
for (i = len - 1; i >= 0; i--)
{
c = lgetc(curwp->w_dotp, i);
if (!isspace(c))
break;
}
n = (len - 1) - i;
if (n)
{
curwp->w_doto = i + 1;
line_delete(n,FALSE);
}
}
/*********************************
* Convert C comment to C++ comment.
*/
int Dcppcomment(int f,int n)
{
int c;
int i;
struct LINE *dotpsave;
int dotosave;
if (n < 0)
goto err;
if (window_marking(curwp))
{ REGION region;
int s;
if ((s = getregion(®ion)) != TRUE)
return s;
dotpsave = curwp->w_dotp;
dotosave = curwp->w_doto;
curwp->w_dotp = region.r_linep;
curwp->w_doto = region.r_offset;
n = region.r_nlines;
}
while (n--)
{ int len;
deblank();
len = llength(curwp->w_dotp);
if (len)
{
for (i = 0; i + 3 < len; i++)
{
c = lgetc(curwp->w_dotp, i);
if (c == '/' && lgetc(curwp->w_dotp, i + 1) == '*')
{
if (lgetc(curwp->w_dotp, len - 2) == '*' &&
lgetc(curwp->w_dotp, len - 1) == '/')
{
curwp->w_doto = i + 1;
line_delete(1,FALSE);
line_insert(1,'/');
curwp->w_doto = len - 2;
line_delete(2,FALSE);
deblank();
break;
}
}
}
curwp->w_doto = 0; /* move to beginning of line */
}
if (forwline(FALSE,1) == FALSE)
goto err;
}
if (window_marking(curwp))
{
if (dotosave > llength(dotpsave))
dotosave = llength(dotpsave);
curwp->w_dotp = dotpsave;
curwp->w_doto = dotosave;
}
return TRUE;
err:
return FALSE;
}
/************************************
* Open browser on URL.
*/
int openBrowser(int f, int n)
{
struct LINE *dotp = curwp->w_dotp;
char *s = getURL(dotp->l_text, llength(dotp), curwp->w_doto);
if (s)
{
browse(s);
free(s);
return TRUE;
}
return FALSE;
}