Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / sbr / RCS / m_gmsg.c,v
1 head    2.10;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 2.10
9 date    92.10.20.22.46.29;      author jromine; state Exp;
10 branches;
11 next    2.9;
12
13 2.9
14 date    92.05.12.22.11.10;      author jromine; state Exp;
15 branches;
16 next    2.8;
17
18 2.8
19 date    92.02.11.21.32.04;      author jromine; state Exp;
20 branches;
21 next    2.7;
22
23 2.7
24 date    92.02.05.06.40.22;      author jromine; state Exp;
25 branches;
26 next    2.6;
27
28 2.6
29 date    92.02.03.16.35.10;      author jromine; state Exp;
30 branches;
31 next    2.5;
32
33 2.5
34 date    90.04.05.15.30.20;      author sources; state Exp;
35 branches;
36 next    2.4;
37
38 2.4
39 date    90.04.05.14.43.48;      author sources; state Exp;
40 branches;
41 next    2.3;
42
43 2.3
44 date    90.03.20.15.57.29;      author sources; state Exp;
45 branches;
46 next    2.2;
47
48 2.2
49 date    90.02.06.13.08.58;      author sources; state Exp;
50 branches;
51 next    2.1;
52
53 2.1
54 date    90.02.01.14.07.33;      author sources; state Exp;
55 branches;
56 next    2.0;
57
58 2.0
59 date    89.11.17.15.57.24;      author sources; state Exp;
60 branches;
61 next    1.1;
62
63 1.1
64 date    89.06.26.14.31.47;      author sources; state Exp;
65 branches;
66 next    ;
67
68
69 desc
70 @@
71
72
73 2.10
74 log
75 @NULL fix
76 @
77 text
78 @/* m_gmsg.c - read a folder */
79 #ifndef lint
80 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.9 1992/05/12 22:11:10 jromine Exp jromine $";
81 #endif /* lint */
82
83 #include "../h/mh.h"
84 #include "../h/local.h"
85 #include <stdio.h>
86
87
88 #define NINFO   (MAXFOLDER / 5) /* PLEASE be non-trivial... */
89 struct info {
90     int     msgno;
91     int     stats;
92 };
93
94 static int  len=0;
95 static struct info *head;
96
97 static          m_getatr();
98 static int      m_setatr();
99 /* \f */
100
101 struct msgs *m_gmsg (name)
102 register char   *name;
103 {
104 #ifdef  COMPAT
105     register int    cur,
106                     fd;
107 #endif /* COMPAT */
108     register int    i,
109                     j;
110     register struct info *rover,
111                          *tail;
112 #ifdef  COMPAT
113     register char  *cp;
114     char    buffer[BUFSIZ];
115 #endif /* COMPAT */
116     register struct msgs   *mp;
117 #ifdef SYS5DIR
118     register struct dirent *dp;
119                 DIR * dd;
120 #else /* SYS5DIR */
121     register struct direct *dp;
122     register    DIR * dd;
123 #endif /* SYS5DIR */
124     struct stat st;
125
126     if ((dd = opendir (name = m_mailpath (name))) == NULL) {
127         free (name);
128         return NULL;
129     }
130     (void) fstat (dd -> dd_fd, &st);
131
132     mp = (struct msgs  *) malloc (MHSIZE (mp, 0, 0));
133     if (mp == NULL)
134         adios (NULLCP, "unable to allocate folder storage");
135     mp -> lowmsg = mp -> hghmsg = mp -> nummsg = 0;
136     mp -> curmsg = 0;
137     mp -> lowsel = mp -> hghsel = mp -> numsel = 0;
138     mp -> foldpath = name;
139     mp -> msgflags = 0;
140     if (st.st_uid != getuid () || access (name, 02) == NOTOK)
141         mp -> msgflags |= READONLY;
142 #ifdef  COMPAT
143     cur = 0;
144 #endif /* COMPAT */
145     j = strlen (SBACKUP);
146     if (head == NULL)
147         if ((head = (struct info *)
148                 malloc ((unsigned) ((len = NINFO) * sizeof *head))) == NULL)
149             adios (NULLCP, "unable to allocate info storage");
150     tail = (rover = head) + len;
151
152     while (dp = readdir (dd))
153         if (i = m_atoi (dp -> d_name)) {
154             if (rover >= tail) {
155                 register int curlen = tail - head;
156
157                 if ((tail = (struct info *) realloc ((char *) head,
158                              (unsigned) ((len += NINFO) * sizeof *head)))
159                         == NULL)
160                     adios (NULLCP, "unable to allocate info storage");
161                 else
162                     rover = tail + curlen, head = tail, tail += len;
163             }
164             if (i > mp -> hghmsg)
165                 mp -> hghmsg = i;
166             mp -> nummsg++;
167             if (mp -> lowmsg == 0 || i < mp -> lowmsg)
168                 mp -> lowmsg = i;
169             rover -> msgno = i;
170             rover -> stats = EXISTS;
171 #ifdef  notdef
172             rover -> stats &= ~DELETED;
173 #endif /* notdef */
174             rover++;
175         }
176         else
177             switch (dp -> d_name[0]) {
178                 case '.': 
179                     continue;
180
181                 case ',': 
182 #ifdef  notdef
183                     if ((i = m_atoi (dp -> d_name + 1)) {
184                         register struct info *l;
185
186                         for (l = head; l < rover; l++)
187                             if (l -> msgno == i) {
188                                 if (!(l -> stats & EXISTS))
189                                     l -> stats |= DELETED;
190                                 break;
191                             }
192                     }
193 #endif /* notdef */
194                     continue;
195
196 #ifdef  MHE
197                 case '+': 
198                     continue;
199 #endif /* MHE */
200
201 #ifdef  UCI
202                 case '_': 
203                 case '#': 
204                     continue;
205 #endif /* UCI */
206
207                 default: 
208 #ifdef  COMPAT
209                     if (strcmp (dp -> d_name, current) == 0) {
210                         cur++;
211                         continue;
212                     }
213 #endif /* COMPAT */
214                     if (strcmp (dp -> d_name, LINK) == 0
215                             || strncmp (dp -> d_name, SBACKUP, j) == 0)
216                         continue;
217                     mp -> msgflags |= OTHERS;
218                     continue;
219             }
220
221     closedir (dd);
222
223 /* \f */
224
225 #ifdef  COMPAT
226     (void) sprintf (buffer, "%s-%s", current, name);
227     if (cp = m_find (buffer)) {
228         i = m_atoi (cp);
229         (void) m_delete(buffer);
230         if (i > 0)
231             mp -> curmsg = i;
232     }
233     if (mp -> curmsg == 0 && cur && (fd = open (current, 0)) != NOTOK) {
234             if ((i = read (fd, buffer, sizeof buffer)) > 0) {
235                 if (cp = index (buffer, '\n'))
236                     *cp = 0;
237                 if ((i = m_atoi (buffer)) > 0)
238                     mp -> curmsg = i;
239             }
240             (void) close (fd);
241         }
242     if (cur && !(mp -> msgflags & READONLY)){   /* sneaky... */
243         (void) sprintf (buffer, "%s/%s", name, current);
244         (void) unlink (buffer);
245     }
246 #endif /* COMPAT */
247
248 #ifndef MTR
249     mp -> lowoff = 1;
250 #else /* MTR */
251     mp -> lowoff = mp -> lowmsg;
252 #endif /* MTR */
253     mp -> hghoff = mp -> hghmsg + 1;/* for "new" in m_convert */
254
255     mp = (struct msgs  *)
256                 realloc ((char *) mp, MHSIZE (mp, mp -> lowoff, mp -> hghoff));
257     if (mp == NULL)
258         adios (NULLCP, "unable to allocate folder storage");
259 #ifndef MTR
260     for (i = mp -> lowmsg; i <= mp -> hghmsg; i++)
261         mp -> msgstats[i] = 0;
262 #else /* MTR */
263     mp -> msgstats = (int *)
264                 calloc ((unsigned) 1, MHSIZEX (mp, mp -> lowmsg, mp -> hghmsg));
265     if (mp -> msgstats == NULL)
266         adios (NULLCP, "unable to allocate messages storage");
267     mp -> msgstats = (mp -> msgbase = mp -> msgstats) - mp -> lowoff;
268     if (mp -> msgstats < (int *)0)      /* non portable */
269         adios (NULLCP, "m_gmsg() botch -- you lose big");
270 #endif /* MTR */
271     for (tail = head; tail < rover; tail++)
272         mp -> msgstats[tail -> msgno] = tail -> stats;
273     m_getatr (mp);
274
275     return mp;
276 }
277
278 /* \f */
279
280 static m_getatr (mp)
281 register struct msgs *mp;
282 {
283     int     alen,
284             bits,
285             i,
286             j,
287             plen,
288             state;
289     register char  *cp;
290     char    name[NAMESZ],
291             field[BUFSIZ * 2];
292     register struct node   *np;
293     register    FILE * fp;
294
295     bits = FFATTRSLOT;
296
297     mp -> msgattrs[i = 0] = getcpy (current);
298     mp -> msgattrs[++i] = '\0';
299     mp -> attrstats = 0;        /* initially, all public */
300
301     m_getdefs ();
302     if (mh_seq == '\0' || *mh_seq == '\0')
303         goto private_only;
304
305     (void) sprintf (field, "%s/%s", mp -> foldpath, mh_seq);
306     if (fp = fopen (field, "r")) {
307         for (state = FLD;;) {
308             switch (state = m_getfld (state, name, field, sizeof field, fp)) {
309                 case FLD: 
310                 case FLDEOF: 
311                     (void) m_setatr (mp, getcpy (name), trimcpy (field));
312                     if (state == FLDEOF)
313                         break;
314                     continue;
315
316                 case BODY: 
317                 case BODYEOF: 
318                     adios (NULLCP,
319                             "no blank lines are permitted in %s/%s",
320                             mp -> foldpath, mh_seq);/* fall */
321
322                 case FILEEOF:
323                     break;
324
325                 default: 
326                     adios (NULLCP, "%s/%s is poorly formatted",
327                             mp -> foldpath, mh_seq);
328             }
329             break;
330         }
331         (void) fclose (fp);
332     }
333
334 private_only: ;
335     alen = strlen ("atr-");
336     plen = strlen (mp -> foldpath) + 1;
337
338     for (np = m_defs; np; np = np -> n_next)
339         if (ssequal ("atr-", np -> n_name)
340                 && (j = strlen (np -> n_name) - plen) > alen
341                 && *(np -> n_name + j) == '-'
342                 && strcmp (mp -> foldpath, np -> n_name + j + 1) == 0) {
343             cp = getcpy (np -> n_name + alen);
344             *(cp + j - alen) = '\0';
345             if ((i = m_setatr (mp, cp, getcpy (np -> n_field))) != NOTOK)
346                 mp -> attrstats |= 1 << (bits + i);/* private */
347         }
348 }
349
350 /* \f */
351
352 static int  m_setatr (mp, name, field)
353 register struct msgs *mp;
354 register char   *name,
355                 *field;
356 {
357     int     bits,
358             hack;
359     register int    i,
360                     j,
361                     k;
362     register char  *cp,
363                   **ap;
364
365     bits = FFATTRSLOT;
366     hack = strcmp (current, name) == 0;/* hack... */
367     /* if we're going to use UNSEEN, it should be set here! */
368
369     for (i = 0; mp -> msgattrs[i]; i++)
370         if (strcmp (mp -> msgattrs[i], name) == 0) {
371             for (j = mp -> lowmsg; j <= mp -> hghmsg; j++)
372                 mp -> msgstats[j] &= ~(1 << (bits + i));
373             break;
374         }
375     if (i >= NATTRS) {
376         free (name);
377         free (field);
378         return NOTOK;
379     }
380
381     if (mp -> msgattrs[i] == NULL) {
382         mp -> msgattrs[i] = name;
383         mp -> msgattrs[i + 1] = NULL;
384     }
385     else
386         free (name);
387
388     for (ap = brkstring (field, " ", "\n");
389             *ap;
390             ap++) {
391         if (cp = index (*ap, '-'))
392             *cp++ = '\0';
393         if ((j = m_atoi (*ap)) > 0) {
394 #ifdef  notdef
395             if (hack && j >= mp -> lowmsg && j <= mp -> hghmsg
396                     && (mp -> msgstats[j] & EXISTS))
397                 mp -> curmsg = j;
398 #else /* not notdef */
399             if (hack)
400                 mp -> curmsg = j;
401 #endif /* not notdef */
402             for (k = cp ? m_atoi (cp) : j; j <= k; j++)
403                 if (j >= mp -> lowmsg && j <= mp -> hghmsg
404                         && (mp -> msgstats[j] & EXISTS))
405                     mp -> msgstats[j] |= 1 << (bits + i);
406         }
407     }
408     free (field);
409
410     return i;
411 }
412 @
413
414
415 2.9
416 log
417 @fix ifdefs
418 @
419 text
420 @d3 1
421 a3 1
422 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.8 1992/02/11 21:32:04 jromine Exp jromine $";
423 d159 1
424 a159 1
425                     *cp = NULL;
426 @
427
428
429 2.8
430 log
431 @put sequences in an "int"
432 @
433 text
434 @d3 2
435 a4 2
436 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.7 1992/02/05 06:40:22 jromine Exp $";
437 #endif  lint
438 d30 1
439 a30 1
440 #endif  COMPAT
441 d38 1
442 a38 1
443 #endif  COMPAT
444 d43 1
445 a43 1
446 #else  SYS5DIR
447 d46 1
448 a46 1
449 #endif SYS5DIR
450 d62 1
451 a62 1
452     mp -> msgflags = NULL;
453 d67 1
454 a67 1
455 #endif  COMPAT
456 d96 1
457 a96 1
458 #endif  notdef
459 d116 1
460 a116 1
461 #endif  notdef
462 d122 1
463 a122 1
464 #endif  MHE
465 d128 1
466 a128 1
467 #endif  UCI
468 d136 1
469 a136 1
470 #endif  COMPAT
471 d169 1
472 a169 1
473 #endif  COMPAT
474 d173 1
475 a173 1
476 #else   MTR
477 d175 1
478 a175 1
479 #endif  MTR
480 d185 1
481 a185 1
482 #else   MTR
483 d193 1
484 a193 1
485 #endif  MTR
486 d221 1
487 a221 1
488     mp -> msgattrs[++i] = NULL;
489 d225 1
490 a225 1
491     if (mh_seq == NULL || *mh_seq == NULL)
492 d267 1
493 a267 1
494             *(cp + j - alen) = NULL;
495 d315 1
496 a315 1
497             *cp++ = NULL;
498 d321 1
499 a321 1
500 #else   not notdef
501 d324 1
502 a324 1
503 #endif  not notdef
504 @
505
506
507 2.7
508 log
509 @comment
510 @
511 text
512 @d3 1
513 a3 1
514 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.6 1992/02/03 16:35:10 jromine Exp jromine $";
515 d14 1
516 a14 2
517     short   stats;
518     char    pad[sizeof (int) - sizeof (short)];
519 d186 1
520 a186 1
521     mp -> msgstats = (short *)
522 d191 1
523 a191 1
524     if (mp -> msgstats < (short *)0)    /* non portable */
525 @
526
527
528 2.6
529 log
530 @fix
531 @
532 text
533 @d3 1
534 a3 1
535 static char ident[] = "@@(#)$Id: m_gmsg.c,v 2.5 1990/04/05 15:30:20 sources Exp jromine $";
536 d291 1
537 @
538
539
540 2.5
541 log
542 @add ID
543 @
544 text
545 @d3 1
546 a3 1
547 static char ident[] = "@@(#)$Id:$";
548 d56 1
549 a56 1
550     mp = (struct msgs  *) malloc (MSIZE (mp, 0, 0));
551 d180 1
552 a180 1
553                 realloc ((char *) mp, MSIZE (mp, mp -> lowoff, mp -> hghoff));
554 d188 1
555 a188 1
556                 calloc ((unsigned) 1, MSIZEX (mp, mp -> lowmsg, mp -> hghmsg));
557 @
558
559
560 2.4
561 log
562 @add ID
563 @
564 text
565 @d3 1
566 a3 1
567 static char ident[] = "$Id:";
568 @
569
570
571 2.3
572 log
573 @cast null pointer
574 @
575 text
576 @d2 3
577 @
578
579
580 2.2
581 log
582 @ANSI Compilance
583 @
584 text
585 @d189 1
586 a189 1
587     if (mp -> msgstats < 0)
588 @
589
590
591 2.1
592 log
593 @increase message sequence buffer size by factor of 2.  I hope this
594 is worth it, since it'll make things bigger.
595 @
596 text
597 @d18 2
598 @
599
600
601 2.0
602 log
603 @changes for SUN40 shared libraries and NNTP under bbc
604 @
605 text
606 @d210 1
607 a210 1
608             field[BUFSIZ];
609 @
610
611
612 1.1
613 log
614 @Initial revision
615 @
616 text
617 @d36 4
618 d42 1
619 @