]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/subs/m_gmsg.c
Create new mh-format function %(ordinal)
[nmh] / docs / historical / mh-jun-1982 / subs / m_gmsg.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 extern char *malloc();
12 extern char *sprintf();
13
14 #define Block
15
16 struct msgs *mp;
17
18 /* Look through a folder.
19 /* Alloc a 'struct msgs' structure and fill it in
20 /* with such things as what the low, high, and current messages are.
21 /* Return a pointer to this structure or a null pointer if trouble.
22 /**/
23 struct msgs *
24 m_gmsg(name)
25 char *name;
26 {
27 FILE *ifp; /***/
28 register int i, j;
29 register char *cp;
30 int curfil;
31
32 struct {
33 struct {
34 short d_inum;
35 char d_name[14];
36 } ent;
37 int terminator;
38 } dir;
39
40 struct {
41 int xhghmsg,
42 xnummsg,
43 xlowmsg,
44 xcurmsg;
45 char xselist,
46 xflags,
47 xfiller,
48 xothers;
49 char xmsgs[MAXFOLDER + 1];
50 } msgbuf;
51
52 if((ifp = fopen(".", "r")) == 0)
53 return(0);
54 for(j = 0; j <= MAXFOLDER; j++)
55 msgbuf.xmsgs[j] = 0;
56 msgbuf.xcurmsg = 0;
57 msgbuf.xnummsg = 0;
58 msgbuf.xselist = 0;
59 msgbuf.xothers = 0;
60 msgbuf.xlowmsg = 5000;
61 msgbuf.xhghmsg = 0;
62 msgbuf.xflags = (access(".",2) == -1)? READONLY:0; /*RAND sys call*/
63 curfil = 0;
64 dir.terminator = 0;
65 cp = dir.ent.d_name;
66 for(;;) {
67 if(fread(&dir, sizeof dir.ent, 1, ifp) != 1)
68 break;
69 if(dir.ent.d_inum)
70 if(j = mu_atoi(cp)) {
71 if(j > msgbuf.xhghmsg)
72 msgbuf.xhghmsg = j;
73 msgbuf.xnummsg++;
74 if(j < msgbuf.xlowmsg)
75 msgbuf.xlowmsg = j;
76 msgbuf.xmsgs[j] = EXISTS;
77 } else if(*cp != ',' && *cp != '.')
78 if(strcmp(cp, current) == 0)
79 curfil++;
80 else if(strcmp(cp, listname) == 0)
81 msgbuf.xselist++;
82 else
83 msgbuf.xothers++;
84 }
85 if(!msgbuf.xhghmsg)
86 msgbuf.xlowmsg = 0;
87 VOID fclose(ifp);
88 if(msgbuf.xflags&READONLY) Block {
89 char buf[132];
90 VOID sprintf(buf, "cur-%s", name);
91 /*** copy(name, copy("cur-", buf)); ***/
92 if((cp = m_find(buf)) != NULL)
93 if(j = mu_atoi(cp))
94 msgbuf.xcurmsg = j;
95 } else if(curfil && (i = open(current, 0)) >= 0) {
96 if((j = read(i, dir.ent.d_name, sizeof dir.ent.d_name)) >= 2){
97 dir.ent.d_name[j-1] = 0; /* Zap <lf> */
98 if(j = mu_atoi(dir.ent.d_name))
99 msgbuf.xcurmsg = j;
100 }
101 VOID close(i);
102 }
103 Block {
104 register struct msgs *msgp;
105 if( (char *) (msgp = (struct msgs *)
106 malloc((unsigned) (sizeof *mp + msgbuf.xhghmsg + 2)))
107 == (char *) 0)
108 return(0);
109 msgp->hghmsg = msgbuf.xhghmsg;
110 msgp->nummsg = msgbuf.xnummsg;
111 msgp->lowmsg = msgbuf.xlowmsg;
112 msgp->curmsg = msgbuf.xcurmsg;
113 msgp->selist = msgbuf.xselist;
114 msgp->msgflags = msgbuf.xflags;
115 msgp->others = msgbuf.xothers;
116 msgp->foldpath = name;
117 msgp->lowsel = 5000;
118 msgp->hghsel = 0;
119 msgp->numsel = 0;
120 for(j = 0; j <= msgbuf.xhghmsg; j++)
121 msgp->msgstats[j] = msgbuf.xmsgs[j];
122 return(msgp);
123 }
124 }