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