9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.11.04.00.44.07; author jromine; state Exp;
19 date 92.02.03.17.57.22; author jromine; state Exp;
24 date 92.02.03.16.35.36; author jromine; state Exp;
29 date 92.01.31.22.11.43; author jromine; state Exp;
34 date 90.04.05.15.01.19; author sources; state Exp;
39 date 90.02.06.13.20.21; author sources; state Exp;
44 date 90.02.06.13.19.47; author sources; state Exp;
58 @/* install-mh.c - initialize the MH environment */
60 static char ident[] = "@@(#)$Id: install-mh.c,v 1.7 1992/11/04 00:44:07 jromine Exp jromine $";
66 #include <sys/types.h>
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...",
88 struct passwd *getpwuid ();
90 #endif /* !__STDC__ */
111 setlocale(LC_ALL, "");
113 invo_name = r1bindex (argv[0], '/');
116 if (argc == 2 && strcmp (argv[1], "-compat") == 0) {
117 context = "/dev/null"; /* hack past 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))
126 ctxpath = getcpy (m_maildir (context = "context"));
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);
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);
146 if ((pw = getpwuid (getuid ())) == NULL
147 || pw -> pw_dir == NULL
148 || *pw -> pw_dir == 0)
149 adios (NULLCP, "no HOME envariable");
151 mypath = getcpy (pw -> pw_dir);
152 if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
155 defpath = concat (mypath, "/", mh_profile, NULLCP);
157 if (stat (defpath, &st) != NOTOK)
159 adios (NULLCP, "invocation error");
162 "You already have an MH profile, use an editor to modify it");
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');
170 (void) putchar ('\n');
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))
190 printf ("I'm going to create the standard MH path for you.\n");
192 cp = concat ("Do you want the standard MH path \"",
193 mypath, "/", "Mail\"? ", NULLCP);
194 if (autof || gans (cp, anoyes))
198 if (gans ("Do you want a path below your login directory? ",
200 printf ("What is the path? %s/", mypath);
204 printf ("What is the whole path? /");
205 path = concat ("/", geta (), NULLCP);
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);
218 printf ("[Using existing directory]\n");
222 np = m_defs = (struct node *) malloc (sizeof *np);
224 adios (NULLCP, "unable to allocate profile storage");
225 np -> n_name = getcpy ("Path");
226 np -> n_field = getcpy (path);
230 if (in = fopen (mh_defaults, "r")) {
231 m_readefs (&np -> n_next, in, mh_defaults, 0);
235 ctxpath = getcpy (m_maildir (context = "context"));
236 m_replace (pfolder, defalt);
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);
251 static char *geta () {
253 static char line[BUFSIZ];
255 (void) fflush (stdout);
256 if (fgets (line, sizeof line, stdin) == NULL)
258 if (cp = index (line, '\n'))
272 static char ident[] = "@@(#)$Id: install-mh.c,v 1.6 1992/02/03 17:57:22 jromine Exp jromine $";
287 static char ident[] = "@@(#)$Id: install-mh.c,v 1.5 1992/02/03 16:35:36 jromine Exp jromine $";
300 static char ident[] = "@@(#)$Id: install-mh.c,v 1.4 1992/01/31 22:11:43 jromine Exp jromine $";
313 static char ident[] = "@@(#)$Id: install-mh.c,v 1.3 1990/04/05 15:01:19 sources Exp jromine $";
326 static char ident[] = "@@(#)$Id:$";
329 || *pw -> pw_dir == NULL)