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