Mercurial > hg > Applications > mh
comparison sbr/m_sync.c @ 0:bce86c4163a3
Initial revision
author | kono |
---|---|
date | Mon, 18 Apr 2005 23:46:02 +0900 |
parents | |
children | 441a2190cfae |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bce86c4163a3 |
---|---|
1 /* m_sync.c - synchronize message sequences */ | |
2 #ifndef lint | |
3 static char ident[] = "@(#)$Id$"; | |
4 #endif /* lint */ | |
5 | |
6 #include "../h/mh.h" | |
7 #include <stdio.h> | |
8 #include <signal.h> | |
9 #ifndef sigmask | |
10 #define sigmask(s) (1 << ((s) - 1)) | |
11 #endif /* not sigmask */ | |
12 | |
13 | |
14 /* decision logic | |
15 1. public and folder readonly: make it private | |
16 2a. public: add it to the sequences file | |
17 2b. private: add it to the profile | |
18 */ | |
19 | |
20 | |
21 void m_sync (mp) | |
22 register struct msgs *mp; | |
23 { | |
24 int bits; | |
25 register int i; | |
26 register char *cp; | |
27 char flags, | |
28 attr[BUFSIZ], | |
29 seq[BUFSIZ * 2]; | |
30 register FILE *fp; | |
31 #ifndef BSD42 | |
32 TYPESIG (*hstat) (), (*istat) (), (*qstat) (), (*tstat) (); | |
33 #else /* BSD42 */ | |
34 int smask; | |
35 #endif /* BSD42 */ | |
36 | |
37 if (!(mp -> msgflags & SEQMOD)) | |
38 return; | |
39 mp -> msgflags &= ~SEQMOD; | |
40 | |
41 m_getdefs (); | |
42 /* (void) sprintf (seq, "%s/%s", mp -> foldpath, mh_seq); */ | |
43 (void) sprintf (seq, "%s/%s", mp -> foldpath, mh_seq? mh_seq: ""); | |
44 bits = FFATTRSLOT; | |
45 fp = NULL; | |
46 | |
47 flags = mp -> msgflags; | |
48 if (mh_seq == NULL || *mh_seq == 0) | |
49 mp -> msgflags |= READONLY; | |
50 | |
51 for (i = 0; mp -> msgattrs[i]; i++) { | |
52 (void) sprintf (attr, "atr-%s-%s", mp -> msgattrs[i], mp -> foldpath); | |
53 if (mp -> msgflags & READONLY | |
54 || mp -> attrstats & (1 << (bits + i))) { | |
55 priv: ; | |
56 if (cp = m_seq (mp, mp -> msgattrs[i])) | |
57 m_replace (attr, cp); | |
58 else | |
59 (void) m_delete (attr); | |
60 } | |
61 else { | |
62 (void) m_delete (attr); | |
63 if ((cp = m_seq (mp, mp -> msgattrs[i])) == NULL) | |
64 continue; | |
65 if (fp == NULL) { | |
66 if ((fp = fopen (seq, "w")) == NULL | |
67 && (unlink (seq) == NOTOK || | |
68 (fp = fopen (seq, "w")) == NULL)) { | |
69 admonish (attr, "unable to write"); | |
70 goto priv; | |
71 } | |
72 #ifndef BSD42 | |
73 hstat = signal (SIGHUP, SIG_IGN); | |
74 istat = signal (SIGINT, SIG_IGN); | |
75 qstat = signal (SIGQUIT, SIG_IGN); | |
76 tstat = signal (SIGTERM, SIG_IGN); | |
77 #else /* BSD42 */ | |
78 smask = sigblock (sigmask (SIGHUP) | sigmask (SIGINT) | |
79 | sigmask (SIGQUIT) | sigmask (SIGTERM)); | |
80 #endif /* BSD42 */ | |
81 } | |
82 fprintf (fp, "%s: %s\n", mp -> msgattrs[i], cp); | |
83 } | |
84 } | |
85 | |
86 if (fp) { | |
87 (void) fclose (fp); | |
88 #ifndef BSD42 | |
89 (void) signal (SIGHUP, hstat); | |
90 (void) signal (SIGINT, istat); | |
91 (void) signal (SIGQUIT, qstat); | |
92 (void) signal (SIGTERM, tstat); | |
93 #else /* BSD42 */ | |
94 (void) sigsetmask (smask); | |
95 #endif /* BSD42 */ | |
96 } | |
97 else | |
98 if (!(mp -> msgflags & READONLY)) | |
99 (void) unlink (seq); | |
100 | |
101 mp -> msgflags = flags; | |
102 } |