Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / packf.c,v
1 head    1.4;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.4
9 date    92.12.15.00.20.22;      author jromine; state Exp;
10 branches;
11 next    1.3;
12
13 1.3
14 date    92.11.04.00.53.48;      author jromine; state Exp;
15 branches;
16 next    1.2;
17
18 1.2
19 date    92.01.31.22.19.47;      author jromine; state Exp;
20 branches;
21 next    1.1;
22
23 1.1
24 date    92.01.31.22.19.33;      author jromine; state Exp;
25 branches;
26 next    ;
27
28
29 desc
30 @@
31
32
33 1.4
34 log
35 @endif sugar
36 @
37 text
38 @/* packf.c - pack a folder (used to be called "pack") */
39 #ifndef lint
40 static char ident[] = "@@(#)$Id: packf.c,v 1.3 1992/11/04 00:53:48 jromine Exp jromine $";
41 #endif  /*  lint */
42
43 #include "../h/mh.h"
44 #include "../h/dropsbr.h"
45 #include <errno.h>
46 #include <stdio.h>
47 #include <sys/types.h>
48 #include <sys/stat.h>
49 #ifdef LOCALE
50 #include        <locale.h>
51 #endif
52
53 /* \f */
54
55 static struct swit switches[] = {
56 #define FILESW  0
57     "file name", 0,
58
59 #define HELPSW  1
60     "help", 4,
61
62     NULL, 0
63 };
64
65 /* \f */
66
67 extern int errno;
68
69
70 static int  md = NOTOK;
71
72 char   *file = NULL;
73
74 /* \f */
75
76 /* ARGSUSED */
77
78 main (argc, argv)
79 int     argc;
80 char  **argv;
81 {
82     int     msgp = 0,
83             fd,
84             msgnum;
85     char   *cp,
86            *maildir,
87            *msgnam,
88            *folder = NULL,
89             buf[100],
90           **ap,
91           **argp,
92            *arguments[MAXARGS],
93            *msgs[MAXARGS];
94     struct msgs *mp;
95     struct stat st;
96
97 #ifdef LOCALE
98         setlocale(LC_ALL, "");
99 #endif
100     invo_name = r1bindex (argv[0], '/');
101     if ((cp = m_find (invo_name)) != NULL) {
102         ap = brkstring (cp = getcpy (cp), " ", "\n");
103         ap = copyip (ap, arguments);
104     }
105     else
106         ap = arguments;
107     (void) copyip (argv + 1, ap);
108     argp = arguments;
109
110 /* \f */
111
112     while (cp = *argp++) {
113         if (*cp == '-')
114             switch (smatch (++cp, switches)) {
115                 case AMBIGSW: 
116                     ambigsw (cp, switches);
117                     done (1);
118                 case UNKWNSW: 
119                     adios (NULLCP, "-%s unknown", cp);
120                 case HELPSW: 
121                     (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
122                             invo_name);
123                     help (buf, switches);
124                     done (1);
125
126                 case FILESW: 
127                     if (file)
128                         adios (NULLCP, "only one file at a time!");
129                     if (!(file = *argp++) || *file == '-')
130                         adios (NULLCP, "missing argument to %s", argp[-2]);
131                     continue;
132             }
133         if (*cp == '+' || *cp == '@@') {
134             if (folder)
135                 adios (NULLCP, "only one folder at a time!");
136             folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
137         }
138         else
139             msgs[msgp++] = cp;
140     }
141
142 /* \f */
143
144     if (!file)
145         file = "./msgbox";
146     file = path (file, TFILE);
147     if (stat (file, &st) == NOTOK) {
148         if (errno != ENOENT)
149             adios (file, "error on file");
150         cp = concat ("Create file \"", file, "\"? ", NULLCP);
151         if (!getanswer (cp))
152             done (1);
153         free (cp);
154     }
155
156     if (!m_find ("path"))
157         free (path ("./", TFOLDER));
158     if (!msgp)
159         msgs[msgp++] = "all";
160     if (!folder)
161         folder = m_getfolder ();
162     maildir = m_maildir (folder);
163
164     if (chdir (maildir) == NOTOK)
165         adios (maildir, "unable to change directory to ");
166     if (!(mp = m_gmsg (folder)))
167         adios (NULLCP, "unable to read folder %s", folder);
168     if (mp -> hghmsg == 0)
169         adios (NULLCP, "no messages in %s", folder);
170
171     for (msgnum = 0; msgnum < msgp; msgnum++)
172         if (!m_convert (mp, msgs[msgnum]))
173             done (1);
174     m_setseq (mp);
175
176     if ((md = mbx_open (file, getuid (), getgid (), m_gmprot ())) == NOTOK)
177         adios (file, "unable to open");
178
179     for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
180         if (mp -> msgstats[msgnum] & SELECTED) {
181             if ((fd = open (msgnam = m_name (msgnum), 0)) == NOTOK) {
182                 admonish (msgnam, "unable to read message");
183                 break;
184             }
185
186             if (mbx_copy (file, md, fd, 1, NULLCP, 1) == NOTOK)
187                 adios (file, "error writing to file");
188
189             (void) close (fd);
190         }
191     (void) mbx_close (file, md);
192
193     m_replace (pfolder, folder);
194     if (mp -> hghsel != mp -> curmsg)
195         m_setcur (mp, mp -> lowsel);
196     m_sync (mp);
197     m_update ();
198
199     done (0);
200 }
201
202 /* \f */
203
204 void done (status)
205 int status;
206 {
207     (void) mbx_close (file, md);
208
209     exit (status);
210 }
211 @
212
213
214 1.3
215 log
216 @LOCALE
217 @
218 text
219 @d3 2
220 a4 2
221 static char ident[] = "@@(#)$Id: packf.c,v 1.2 1992/01/31 22:19:47 jromine Exp jromine $";
222 #endif  lint
223 @
224
225
226 1.2
227 log
228 @kerberos
229 @
230 text
231 @d3 1
232 a3 1
233 static char ident[] = "@@(#)$Id$";
234 d12 3
235 d60 3
236 @
237
238
239 1.1
240 log
241 @Initial revision
242 @
243 text
244 @d2 3
245 d22 1
246 a22 1
247     NULL, NULL
248 @