-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathex_args.c
58 lines (56 loc) · 1007 Bytes
/
ex_args.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
#
/*
* Ex - a text editor
* Version 1.0 September, 1977
*/
#include "ex.h"
int
getargs(void)
{
int c;
register char *cp, *fp;
char **dp;
cp = linebuf, dp = (char **)genbuf;
for (;;) {
c = ex_getchar();
if (endcmd(c))
break;
if (white(c))
continue;
*dp = cp;
do {
switch (c) {
case '\\':
c = ex_getchar() | 0200;
default:
if (cp > &linebuf[LBSIZE - 2])
flong:
error("Argument buffer overflow@- limit 510 characters");
*cp++ = c;
break;
case '`':
fp = altfile;
if (*fp == 0)
error("No alternate filename@to substitute for `");
goto filexp;
case '%':
fp = savedfile;
if (*fp == 0)
error("No current filename@to substitute for %%");
filexp:
while (*fp) {
if (cp > &linebuf[LBSIZE - 2])
goto flong;
*cp++ = *fp++;
}
break;
}
c = ex_getchar();
} while (!white(c) && !endcmd(c));
ungetchar(c);
*cp++ = 0;
dp++;
}
*dp = 0;
return (dp - (char **)genbuf);
}