]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/RCS/path.c,v
Always check that mktemp()/mktemp2() succeeds before trying to
[nmh] / docs / historical / mh-6.8.5 / sbr / RCS / path.c,v
1 head 1.6;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.6
9 date 92.12.15.00.20.22; author jromine; state Exp;
10 branches;
11 next 1.5;
12
13 1.5
14 date 92.01.31.21.56.29; author jromine; state Exp;
15 branches;
16 next 1.4;
17
18 1.4
19 date 90.04.05.15.32.04; author sources; state Exp;
20 branches;
21 next 1.3;
22
23 1.3
24 date 90.04.05.14.49.26; author sources; state Exp;
25 branches;
26 next 1.2;
27
28 1.2
29 date 90.02.06.13.09.03; author sources; state Exp;
30 branches;
31 next 1.1;
32
33 1.1
34 date 90.02.06.13.06.03; author sources; state Exp;
35 branches;
36 next ;
37
38
39 desc
40 @@
41
42
43 1.6
44 log
45 @endif sugar
46 @
47 text
48 @/* path.c - return a pathname */
49 #ifndef lint
50 static char ident[] = "@@(#)$Id: path.c,v 1.5 1992/01/31 21:56:29 jromine Exp jromine $";
51 #endif /* lint */
52
53 #include "../h/mh.h"
54 #include <stdio.h>
55
56 #define CWD "./"
57 #define NCWD (sizeof CWD - 1)
58 #define DOT "."
59 #define DOTDOT ".."
60 #define PWD "../"
61 #define NPWD (sizeof PWD - 1)
62
63
64 static char *pwds;
65
66 static char *expath ();
67 static compath();
68
69
70 char *path (name, flag)
71 register char *name;
72 register int flag;
73 {
74 register char *cp,
75 *ep;
76
77 if ((cp = expath (name, flag))
78 && (ep = cp + strlen (cp) - 1) > cp
79 && *ep == '/')
80 *ep = 0;
81
82 return cp;
83 }
84
85 /* \f */
86
87 static char *expath (name, flag)
88 register char *name;
89 register int flag;
90 {
91 register char *cp,
92 *ep;
93 char buffer[BUFSIZ];
94
95 if (flag == TSUBCWF) {
96 (void) sprintf (buffer, "%s/%s", m_getfolder (), name);
97 name = m_mailpath (buffer);
98 compath (name);
99 (void) sprintf (buffer, "%s/", m_maildir (""));
100 if (ssequal (buffer, name)) {
101 cp = name;
102 name = getcpy (name + strlen (buffer));
103 free (cp);
104 }
105 flag = TFOLDER;
106 }
107
108 if (*name == '/'
109 || (flag == TFOLDER
110 && (strncmp (name, CWD, NCWD)
111 && strcmp (name, DOT)
112 && strcmp (name, DOTDOT)
113 && strncmp (name, PWD, NPWD))))
114 return getcpy (name);
115
116 if (pwds == NULL)
117 pwds = pwd ();
118
119 if (strcmp (name, DOT) == 0 || strcmp (name, CWD) == 0)
120 return getcpy (pwds);
121
122 ep = pwds + strlen (pwds);
123 if ((cp = rindex (pwds, '/')) == NULL)
124 cp = ep;
125 else
126 if (cp == pwds)
127 cp++;
128
129 if (strncmp (name, CWD, NCWD) == 0)
130 name += NCWD;
131
132 if (strcmp (name, DOTDOT) == 0 || strcmp (name, PWD) == 0) {
133 (void) sprintf (buffer, "%.*s", cp - pwds, pwds);
134 return getcpy (buffer);
135 }
136
137 if (strncmp (name, PWD, NPWD) == 0)
138 name += NPWD;
139 else
140 cp = ep;
141
142 (void) sprintf (buffer, "%.*s/%s", cp - pwds, pwds, name);
143 return getcpy (buffer);
144 }
145
146 /* \f */
147
148 static compath (f)
149 register char *f;
150 {
151 register char *cp,
152 *dp;
153
154 if (*f != '/')
155 return;
156
157 for (cp = f; *cp;)
158 if (*cp == '/') {
159 switch (*++cp) {
160 case 0:
161 if (--cp > f)
162 *cp = 0;
163 break;
164
165 case '/':
166 for (dp = cp; *dp == '/'; dp++)
167 continue;
168 (void) strcpy (cp--, dp);
169 continue;
170
171 case '.':
172 if (strcmp (cp, DOT) == 0) {
173 if (cp > f + 1)
174 cp--;
175 *cp = 0;
176 break;
177 }
178 if (strcmp (cp, DOTDOT) == 0) {
179 for (cp -= 2; cp > f; cp--)
180 if (*cp == '/')
181 break;
182 if (cp <= f)
183 cp = f + 1;
184 *cp = 0;
185 break;
186 }
187 if (strncmp (cp, PWD, NPWD) == 0) {
188 for (dp = cp - 2; dp > f; dp--)
189 if (*dp == '/')
190 break;
191 if (dp <= f)
192 dp = f;
193 (void) strcpy (dp, cp + NPWD - 1);
194 cp = dp;
195 continue;
196 }
197 if (strncmp (cp, CWD, NCWD) == 0) {
198 (void) strcpy (cp - 1, cp + NCWD - 1);
199 cp--;
200 continue;
201 }
202 continue;
203
204 default:
205 cp++;
206 continue;
207 }
208 break;
209 }
210 else
211 cp++;
212 }
213 @
214
215
216 1.5
217 log
218 @kerberos
219 @
220 text
221 @d3 2
222 a4 2
223 static char ident[] = "@@(#)$Id: path.c,v 1.4 1990/04/05 15:32:04 sources Exp jromine $";
224 #endif lint
225 @
226
227
228 1.4
229 log
230 @add ID
231 @
232 text
233 @d3 1
234 a3 1
235 static char ident[] = "@@(#)$Id:$";
236 d33 1
237 a33 1
238 *ep = NULL;
239 d113 1
240 a113 1
241 case NULL:
242 d115 1
243 a115 1
244 *cp = NULL;
245 d128 1
246 a128 1
247 *cp = NULL;
248 d137 1
249 a137 1
250 *cp = NULL;
251 @
252
253
254 1.3
255 log
256 @add ID
257 @
258 text
259 @d3 1
260 a3 1
261 static char ident[] = "$Id:";
262 @
263
264
265 1.2
266 log
267 @ANSI Compilance
268 @
269 text
270 @d2 3
271 @
272
273
274 1.1
275 log
276 @Initial revision
277 @
278 text
279 @d16 2
280 a17 1
281 char *expath ();
282 @