]> diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/subs/m_getdefs.c
Update XOAUTH2 documentation.
[nmh] / docs / historical / mh-nov-1983 / subs / m_getdefs.c
1 #include "mh.h"
2 #include <stdio.h>
3
4 char defpath[128];
5
6 struct procs {
7 char *procname;
8 char **procnaddr;
9 } procs [] = {
10 { "lsproc", &lsproc },
11 { "mh_deliver", &mh_deliver },
12 { "prproc", &prproc },
13 { "scanproc", &scanproc },
14 { "showproc", &showproc },
15 { "sendproc", &sendproc },
16 { "fileproc", &fileproc },
17 { 0, 0 },
18 };
19
20 m_getdefs()
21 {
22 register struct node *np;
23 register int state, wpid, pid;
24 register struct procs *ps;
25 int status;
26 FILE *ib;
27 char name[NAMESZ], field[128];
28
29 if(defpath[0])
30 return; /* We've already been called! */
31 if(!mypath)
32 if((mypath = getenv("HOME")) == NULL) {
33 fprintf(stderr, "HOME environment variable not set!\n");
34 done(1);
35 }
36 sprintf(defpath, "%s%s", mypath, mh_prof);
37 /*** copy(mh_prof, copy(mypath, defpath)); ***/
38
39 if((ib = fopen(defpath, "r")) == NULL) {
40 if((pid = fork()) == 0) {
41 execl(installproc, "install-mh", "-auto", 0);
42 fprintf(stderr, "Can't exec ");perror(installproc);
43 done(1);
44 } else if(pid == -1) {
45 fprintf(stderr, "No forks!\n");
46 done(1);
47 } else
48 while((wpid = wait(&status)) != -1 && wpid != pid)
49 ;
50 if(status || (ib = fopen(defpath, "r")) == NULL) {
51 fprintf(stderr, "[install-mh aborted]\n");
52 done(1);
53 }
54 }
55
56 #ifdef NEWS /* NOT CONVERTED TO V7!!! */
57 fstat(fildes(ib), field);
58 deftime = (&field)->i_atime;
59 #endif
60
61 np = (struct node *) &m_defs;
62 state = FLD;
63 for(;;)
64 switch(state = m_getfld(state,name,field,sizeof field,ib)) {
65 case FLD:
66 case FLDEOF:
67 np->n_next = (struct node *) malloc(sizeof *np);
68 np = np->n_next;
69 np->n_name = getcpy(name);
70 np->n_field = trimcpy(field);
71 np->n_next = 0;
72 for(ps = procs; ps->procname; ps++)
73 if(strcmp(np->n_name, ps->procname) == 0) {
74 *ps->procnaddr = np->n_field;
75 break;
76 }
77 if(state == FLDEOF) {
78 fclose(ib);
79 return(0);
80 }
81 continue;
82 case BODY:
83 case BODYEOF:
84 fprintf(stderr, ".mh_profile must not contain a body--it can't \
85 end with a blank line!\n");
86 default:
87 fprintf(stderr, "Bad format: .mh_profile!\n");
88 done(1);
89 }
90 }