]> diplodocus.org Git - nmh/blob - docs/historical/SRI-NOSC/subs.dir/m_getdefs.c
show and mhl now decode more addresses in header fields.
[nmh] / docs / historical / SRI-NOSC / subs.dir / m_getdefs.c
1 #include "/m/mh/mh.h"
2 #include "/m/mh/iobuf.h"
3
4 char *mypath, defpath[128];
5 char mh_defs[];
6 char installproc[];
7
8 m_getdefs()
9 {
10 register struct node *np;
11 register int state, pid;
12 int status;
13 struct iobuf ib;
14 char name[NAMESZ], field[128];
15
16 if(defpath[0])
17 return; /* We've already been called! */
18 if(!mypath)
19 mypath = getpath(getruid());
20 copy(mh_defs, copy(mypath, defpath));
21
22 if(fopen(defpath, &ib) < 0) {
23 if((pid = fork()) == 0) {
24 execl(installproc, "install-defs", "-detached", 0);
25 printf("Can't install .mh_defs!!\n");
26 flush(); exit(1);
27 } else if(pid == -1) {
28 printf("No forks!\n");
29 flush(); exit(1);
30 } else
31 while((state = waita(&status)) != -1 && state != pid)
32 ;
33 if(status || fopen(defpath, &ib) < 0) {
34 printf("[install-defs aborted]\n");
35 flush(); exit(1);
36 }
37 }
38
39 #ifdef NEWS
40 fstat(ib.b_fildes, field);
41 deftime = (&field)->i_atime;
42 #endif
43
44 np = &m_defs;
45 state = FLD;
46 for(;;)
47 switch(state = m_getfld(state,name,field,sizeof field,&ib)) {
48 case FLD:
49 case FLDEOF:
50 np->n_next = alloc(sizeof *np);
51 np = np->n_next;
52 np->n_name = getcpy(name);
53 np->n_field = trimcpy(field);
54 np->n_next = 0;
55 if(state == FLDEOF) {
56 close(ib.b_fildes);
57 return(0);
58 }
59 continue;
60 case BODY:
61 case BODYEOF:
62 printf(".mh_defs must not contain a body--it can't \
63 end with a blank line!\n");
64 default:
65 printf("Bad format: .mh_defs!\n");
66 flush();
67 exit(1);
68 }
69 }