]> diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/cmds/install-mh.c
Removed --depth 1 from git clone invocation.
[nmh] / docs / historical / mh-nov-1983 / cmds / install-mh.c
1 #include "mh.h"
2 #include <stdio.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5
6 char *anoyes[]; /* Std no/yes gans array */
7
8 char defpath[128];
9
10 main(argc, argv)
11 char *argv[];
12 {
13 register char *cp, *path;
14 register struct node *np;
15 int autof, exitstat;
16 struct stat stbuf;
17 char *geta();
18 extern char _sobuf[];
19
20 setbuf(stdout, _sobuf);
21 autof = (argc == 2 && strcmp(argv[1], "-auto") == 0);
22 exitstat = 1; /* Assume errors will occur */
23 mypath = getenv("HOME");
24 /*** mypath = getpath(getruid()); /* to prevent recursion via m_getdefs */
25 copy(mh_prof, copy(mypath, defpath));
26 if(stat(defpath, &stbuf) != -1) {
27 if(autof)
28 printf("Install-defs invocation error!\n");
29 else
30 printf("You already have an MH profile... use an editor \
31 to modify it.\n");
32 goto leave;
33
34 }
35 if(autof || gans("Do you want help? ", anoyes)) {
36 printf("\nPrior to using MH, it is necessary to have a file in your login\n");
37 printf("directory (%s) named %s which contains information\n",mypath,mh_prof+1);
38 printf("to direct certain MH operations. The only item which is required\n");
39 printf("is the path to use for all MH folder operations. The suggested MH\n");
40 printf("path for you is %s/Mail...\n\n", mypath);
41 }
42 cp = concat(mypath, "/", "Mail", 0);
43 if(stat(cp, &stbuf) != -1) {
44 if((stbuf.st_mode&S_IFMT) == S_IFDIR) {
45 cp = concat("You already have the standard MH directory \"",
46 cp, "\".\nDo you want to use it for MH? ", 0);
47 if(gans(cp, anoyes))
48 path = "Mail";
49 else
50 goto xyz;
51 }
52 } else {
53 cp = concat("Do you want the standard MH path \"", mypath,
54 "/", "Mail\"? ", 0);
55 if(gans(cp, anoyes))
56 path = "Mail";
57 else {
58 xyz: if(gans("Do you want a path below your login directory? ",
59 anoyes)) {
60 printf("What is the path ?? %s/", mypath);
61 path = geta();
62 } else {
63 printf("What is the whole path?? /");
64 path = concat("/", geta(), 0);
65 }
66 }
67 }
68 chdir(mypath);
69 if(chdir(path) == -1) {
70 cp = concat("\"", path, "\" doesn't exist; Create it? ", 0);
71 if(gans(cp, anoyes))
72 if(makedir(path) == 0) {
73 printf("Can't create it!\n");
74 goto leave;
75 }
76 } else
77 printf("[Using existing directory]\n");
78
79 np = m_defs = (struct node *) malloc(sizeof *np);
80 np->n_name = "Path";
81 np->n_field = path;
82 np->n_next = 0;
83 m_replace(pfolder, defalt);
84 exitstat = 0;
85
86 leave:
87 m_update();
88 done(exitstat);
89 }
90
91
92 char *geta()
93 {
94 static char line[128];
95 register char *cp;
96 register int c;
97
98 fflush(stdout);
99 cp = line;
100 while((c = getchar()) != EOF) {
101 if(c == '\n') {
102 *cp = 0;
103 return(line);
104 }
105 if(cp < &line[128])
106 *cp++ = c;
107 }
108 done(1);
109 }