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
|
$NetBSD: patch-be,v 1.1 2001/08/15 06:09:02 fredb Exp $
--- src/expand.c.orig Fri Jan 9 11:16:29 1998
+++ src/expand.c
@@ -110,49 +110,46 @@
return dest;
}
-char *expand_path(char *file_name)
+char *expand_save_text(char *src)
{
- char *path = NULL;
+ char *dest = NULL;
long len = 0, pos = 0;
char ch;
- if (file_name[0] == '~' && file_name[1] == '/')
- file_name += 2;
-
- for (ch = *file_name++ ; ch != '\0' ; ch = *file_name++) {
+ for (ch = *src++ ; ch != '\0' ; ch = *src++) {
if (pos + 8 > len) {
len = pos + 256;
- path = XtRealloc(path, len);
+ dest = XtRealloc(dest, len);
}
if (ch != '%')
- path[pos++] = ch;
+ dest[pos++] = ch;
else {
char *p, *c = NULL;
int cap = False;
int slash = False;
int clen = 0;
- ch = *file_name++;
+ ch = *src++;
switch (ch) {
case '%':
- path[pos++] = '%';
+ dest[pos++] = '%';
continue; /* don't fall through */
case 'a':
case 'A':
if (global.mode != NewsModeGroup &&
global.mode != NewsModeThread) {
fputs("knews: Not in a newsgroup!\n", stderr);
- XtFree(path);
+ XtFree(dest);
return NULL;
}
if (!global.curr_art) {
fputs("knews: No selected article!\n", stderr);
- XtFree(path);
+ XtFree(dest);
return NULL;
}
- sprintf(path + pos, "%ld", global.curr_art->no);
- pos += strlen(path + pos);
+ sprintf(dest + pos, "%ld", global.curr_art->no);
+ pos += strlen(dest + pos);
continue;
case 'g':
slash = True;
@@ -180,7 +177,7 @@
c = global.nntp_server;
if (!c) {
fputs("knews: nntp_server is NULL!\n", stderr);
- XtFree(path);
+ XtFree(dest);
return NULL;
}
p = strchr(c, ':');
@@ -192,7 +189,7 @@
default:
fprintf(stderr,
"knews: %%%c: Unknown format specifier.\n", ch);
- XtFree(path);
+ XtFree(dest);
return NULL;
}
@@ -202,7 +199,7 @@
clen = strlen(c);
} else {
fputs("knews: Not in a newsgroup.\n", stderr);
- XtFree(path);
+ XtFree(dest);
return NULL;
}
@@ -210,7 +207,7 @@
continue;
if (pos + clen + 8 > len) {
len = pos + clen + 256;
- path = XtRealloc(path, len);
+ dest = XtRealloc(dest, len);
}
ch = *c++;
@@ -219,18 +216,32 @@
if (cap && islower((unsigned char)ch))
ch = toupper((unsigned char)ch);
- path[pos++] = ch;
+ dest[pos++] = ch;
while (clen-- > 0) {
ch = *c++;
if (ch == '.' && slash)
ch ='/';
- path[pos++] = ch;
+ dest[pos++] = ch;
}
- path[pos] = '\0';
+ dest[pos] = '\0';
}
}
- path[pos] = '\0';
+ dest[pos] = '\0';
+
+ return dest;
+}
+
+char *expand_path(char *file_name)
+{
+ char *path = NULL;
+
+ if (file_name[0] == '~' && file_name[1] == '/')
+ file_name += 2;
+
+ path = expand_save_text(file_name);
+ if (!path)
+ return NULL;
return path;
}
|