]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/RCS/install-mh.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / uip / RCS / install-mh.c,v
1 head 1.8;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.8
9 date 92.12.15.00.20.22; author jromine; state Exp;
10 branches;
11 next 1.7;
12
13 1.7
14 date 92.11.04.00.44.07; author jromine; state Exp;
15 branches;
16 next 1.6;
17
18 1.6
19 date 92.02.03.17.57.22; author jromine; state Exp;
20 branches;
21 next 1.5;
22
23 1.5
24 date 92.02.03.16.35.36; author jromine; state Exp;
25 branches;
26 next 1.4;
27
28 1.4
29 date 92.01.31.22.11.43; author jromine; state Exp;
30 branches;
31 next 1.3;
32
33 1.3
34 date 90.04.05.15.01.19; author sources; state Exp;
35 branches;
36 next 1.2;
37
38 1.2
39 date 90.02.06.13.20.21; author sources; state Exp;
40 branches;
41 next 1.1;
42
43 1.1
44 date 90.02.06.13.19.47; author sources; state Exp;
45 branches;
46 next ;
47
48
49 desc
50 @@
51
52
53 1.8
54 log
55 @endif sugar
56 @
57 text
58 @/* install-mh.c - initialize the MH environment */
59 #ifndef lint
60 static char ident[] = "@@(#)$Id: install-mh.c,v 1.7 1992/11/04 00:44:07 jromine Exp jromine $";
61 #endif /* lint */
62
63 #include "../h/mh.h"
64 #include <pwd.h>
65 #include <stdio.h>
66 #include <sys/types.h>
67 #include <sys/stat.h>
68 #ifdef LOCALE
69 #include <locale.h>
70 #endif
71
72 /* \f */
73
74 static char *message[] = {
75 "Prior to using MH, it is necessary to have a file in your login",
76 "directory (%s) named %s which contains information",
77 "to direct certain MH operations. The only item which is required",
78 "is the path to use for all MH folder operations. The suggested MH",
79 "path for you is %s/Mail...",
80 NULL
81 };
82
83
84 static char *geta ();
85
86 #ifndef __STDC__
87 #ifdef SYS5
88 struct passwd *getpwuid ();
89 #endif
90 #endif /* !__STDC__ */
91
92 /* \f */
93
94 /* ARGSUSED */
95
96 main (argc, argv)
97 int argc;
98 char **argv;
99 {
100 int autof,
101 i;
102 char *cp,
103 *path;
104 struct node *np;
105 struct passwd *pw;
106 struct stat st;
107 FILE *in,
108 *out;
109
110 #ifdef LOCALE
111 setlocale(LC_ALL, "");
112 #endif
113 invo_name = r1bindex (argv[0], '/');
114
115 #ifdef COMPAT
116 if (argc == 2 && strcmp (argv[1], "-compat") == 0) {
117 context = "/dev/null"; /* hack past m_getdefs() */
118
119 m_getdefs ();
120 for (np = m_defs; np; np = np -> n_next)
121 if (uleq (pfolder, np -> n_name)
122 || ssequal ("atr-", np -> n_name)
123 || ssequal ("cur-", np -> n_name))
124 np -> n_context = 1;
125
126 ctxpath = getcpy (m_maildir (context = "context"));
127 ctxflags |= CTXMOD;
128 m_update ();
129
130 if ((out = fopen (defpath, "w")) == NULL)
131 adios (defpath, "unable to write");
132 for (np = m_defs; np; np = np -> n_next)
133 if (!np -> n_context)
134 fprintf (out, "%s: %s\n", np -> n_name, np -> n_field);
135 (void) fclose (out);
136
137 done (0);
138 }
139 #endif /* COMPAT */
140
141 autof = (argc == 2 && strcmp (argv[1], "-auto") == 0);
142 if (mypath == NULL) { /* straight from m_getdefs... */
143 if (mypath = getenv ("HOME"))
144 mypath = getcpy (mypath);
145 else
146 if ((pw = getpwuid (getuid ())) == NULL
147 || pw -> pw_dir == NULL
148 || *pw -> pw_dir == 0)
149 adios (NULLCP, "no HOME envariable");
150 else
151 mypath = getcpy (pw -> pw_dir);
152 if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
153 *cp = 0;
154 }
155 defpath = concat (mypath, "/", mh_profile, NULLCP);
156
157 if (stat (defpath, &st) != NOTOK)
158 if (autof)
159 adios (NULLCP, "invocation error");
160 else
161 adios (NULLCP,
162 "You already have an MH profile, use an editor to modify it");
163
164 if (!autof && gans ("Do you want help? ", anoyes)) {
165 (void) putchar ('\n');
166 for (i = 0; message[i]; i++) {
167 printf (message[i], mypath, mh_profile);
168 (void) putchar ('\n');
169 }
170 (void) putchar ('\n');
171 }
172
173 /* \f */
174
175 cp = concat (mypath, "/", "Mail", NULLCP);
176 if (stat (cp, &st) != NOTOK) {
177 if ((st.st_mode & S_IFMT) == S_IFDIR) {
178 cp = concat ("You already have the standard MH directory \"",
179 cp, "\".\nDo you want to use it for MH? ", NULLCP);
180 if (gans (cp, anoyes))
181 path = "Mail";
182 else
183 goto query;
184 }
185 else
186 goto query;
187 }
188 else {
189 if (autof)
190 printf ("I'm going to create the standard MH path for you.\n");
191 else
192 cp = concat ("Do you want the standard MH path \"",
193 mypath, "/", "Mail\"? ", NULLCP);
194 if (autof || gans (cp, anoyes))
195 path = "Mail";
196 else {
197 query: ;
198 if (gans ("Do you want a path below your login directory? ",
199 anoyes)) {
200 printf ("What is the path? %s/", mypath);
201 path = geta ();
202 }
203 else {
204 printf ("What is the whole path? /");
205 path = concat ("/", geta (), NULLCP);
206 }
207 }
208 }
209
210 (void) chdir (mypath);
211 if (chdir (path) == NOTOK) {
212 cp = concat ("\"", path, "\" doesn't exist; Create it? ", NULLCP);
213 if (autof || gans (cp, anoyes))
214 if (makedir (path) == 0)
215 adios (NULLCP, "unable to create %s", path);
216 }
217 else
218 printf ("[Using existing directory]\n");
219
220 /* \f */
221
222 np = m_defs = (struct node *) malloc (sizeof *np);
223 if (np == NULL)
224 adios (NULLCP, "unable to allocate profile storage");
225 np -> n_name = getcpy ("Path");
226 np -> n_field = getcpy (path);
227 np -> n_context = 0;
228 np -> n_next = NULL;
229
230 if (in = fopen (mh_defaults, "r")) {
231 m_readefs (&np -> n_next, in, mh_defaults, 0);
232 (void) fclose (in);
233 }
234
235 ctxpath = getcpy (m_maildir (context = "context"));
236 m_replace (pfolder, defalt);
237 m_update ();
238
239 if ((out = fopen (defpath, "w")) == NULL)
240 adios (defpath, "unable to write");
241 for (np = m_defs; np; np = np -> n_next)
242 if (!np -> n_context)
243 fprintf (out, "%s: %s\n", np -> n_name, np -> n_field);
244 (void) fclose (out);
245
246 done (0);
247 }
248
249 /* \f */
250
251 static char *geta () {
252 register char *cp;
253 static char line[BUFSIZ];
254
255 (void) fflush (stdout);
256 if (fgets (line, sizeof line, stdin) == NULL)
257 done (1);
258 if (cp = index (line, '\n'))
259 *cp = 0;
260 return line;
261 }
262 @
263
264
265 1.7
266 log
267 @LOCALE
268 @
269 text
270 @d3 2
271 a4 2
272 static char ident[] = "@@(#)$Id: install-mh.c,v 1.6 1992/02/03 17:57:22 jromine Exp jromine $";
273 #endif lint
274 d82 1
275 a82 1
276 #endif COMPAT
277 @
278
279
280 1.6
281 log
282 @STDC/SYS5/getpw
283 @
284 text
285 @d3 1
286 a3 1
287 static char ident[] = "@@(#)$Id: install-mh.c,v 1.5 1992/02/03 16:35:36 jromine Exp jromine $";
288 d11 3
289 d53 3
290 @
291
292
293 1.5
294 log
295 @fix
296 @
297 text
298 @d3 1
299 a3 1
300 static char ident[] = "@@(#)$Id: install-mh.c,v 1.4 1992/01/31 22:11:43 jromine Exp jromine $";
301 d27 1
302 d29 1
303 @
304
305
306 1.4
307 log
308 @kerberos
309 @
310 text
311 @d3 1
312 a3 1
313 static char ident[] = "@@(#)$Id: install-mh.c,v 1.3 1990/04/05 15:01:19 sources Exp jromine $";
314 d26 1
315 d28 1
316 @
317
318
319 1.3
320 log
321 @add ID
322 @
323 text
324 @d3 1
325 a3 1
326 static char ident[] = "@@(#)$Id:$";
327 d81 1
328 a81 1
329 || *pw -> pw_dir == NULL)
330 d86 1
331 a86 1
332 *cp = NULL;
333 d192 1
334 a192 1
335 *cp = NULL;
336 @
337
338
339 1.2
340 log
341 @ANSI Compilance
342 @
343 text
344 @d2 3
345 @
346
347
348 1.1
349 log
350 @Initial revision
351 @
352 text
353 @d21 1
354 a21 1
355 char *geta ();
356 @