]> diplodocus.org Git - nmh/blob - docs/historical/SRI-NOSC/install-defs.c
expect this commit to be force-replaced periodically
[nmh] / docs / historical / SRI-NOSC / install-defs.c
1 #define TRUE 1
2 #include "mh.h"
3 #include "stat.h"
4
5 char *anoyes[], /* Std no/yes gans array */
6 mh_defs[],
7 defalt[];
8
9 int fout;
10 char *mypath, defpath[128];
11
12 main(argc, argv)
13 char *argv[];
14 {
15 register char *cp, *path;
16 register struct node *np;
17 int autof, detached, exitstat;
18 struct inode stbuf;
19
20 fout = dup(1);
21 autof = (argc == 2 && equal(argv[1], "-auto"));
22 detached = (argc == 2 && equal(argv[1], "-detached"));
23 exitstat = 1; /* Assume errors will occur */
24 mypath = getpath(getruid()); /* to prevent recursion via m_getdefs */
25 copy(mh_defs, copy(mypath, defpath));
26 if(stat(defpath, &stbuf) != -1) {
27 if(autof)
28 printf("Install-defs invocation error!\n");
29 else if (!detached)
30 printf("You already have an MH profile... use an editor \
31 to modify it.\n");
32 goto leave;
33
34 }
35 if(!detached && (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 .mh_defs which contains information\n",mypath);
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.i_mode&IFMT) == IFDIR) {
45 cp = concat("You already have the standard MH directory \"",
46 cp, "\".\nDo you want to use it for MH? ", 0);
47 if( detached ? TRUE : 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( detached ? TRUE : 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 = getans();
62 } else {
63 printf("What is the whole path?? /");
64 path = concat("/", getans(), 0);
65 }
66 }
67 }
68 chdir(mypath);
69 if(chdir(path) == -1) {
70 cp = concat("\"", path, "\" doesn't exist; Create it? ", 0);
71 if( detached ? TRUE : gans(cp, anoyes))
72 if(makedir(path) == 0) {
73 if (!detached) printf("Can't create it!\n");
74 goto leave;
75 }
76 } else
77 if (!detached) printf("[Using existing directory]\n");
78
79 np = m_defs = alloc(sizeof *np);
80 np->n_name = "Path";
81 np->n_field = path;
82 np->n_next = 0;
83 m_replace("folder", defalt);
84 exitstat = 0;
85
86 leave:
87 m_update();
88 flush();
89 exit(exitstat);
90 }
91
92
93 getans()
94 {
95 static char line[128];
96 register char *cp;
97 register int c;
98
99 flush();
100 cp = line;
101 while(c = getchar()) {
102 if(c == '\n') {
103 *cp = 0;
104 return(line);
105 }
106 if(cp < (&line) + 1)
107 *cp++ = c;
108 }
109 exit(1);
110 }