]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/RCS/dist.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / uip / RCS / dist.c,v
1 head 1.5;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.5
9 date 92.12.15.00.20.22; author jromine; state Exp;
10 branches;
11 next 1.4;
12
13 1.4
14 date 92.11.04.00.41.21; author jromine; state Exp;
15 branches;
16 next 1.3;
17
18 1.3
19 date 92.02.04.17.46.56; author jromine; state Exp;
20 branches;
21 next 1.2;
22
23 1.2
24 date 92.01.31.22.09.12; author jromine; state Exp;
25 branches;
26 next 1.1;
27
28 1.1
29 date 92.01.31.22.08.51; author jromine; state Exp;
30 branches;
31 next ;
32
33
34 desc
35 @@
36
37
38 1.5
39 log
40 @endif sugar
41 @
42 text
43 @/* dist.c - re-distribute a message */
44 #ifndef lint
45 static char ident[] = "@@(#)$Id: dist.c,v 1.4 1992/11/04 00:41:21 jromine Exp jromine $";
46 #endif /* lint */
47
48 #include "../h/mh.h"
49 #include <stdio.h>
50 #include <sys/types.h>
51 #include <sys/stat.h>
52 #ifdef LOCALE
53 #include <locale.h>
54 #endif
55
56 /* \f */
57
58 static struct swit switches[] = {
59 #define ANNOSW 0
60 "annotate", 0,
61 #define NANNOSW 1
62 "noannotate", 0,
63
64 #define DFOLDSW 2
65 "draftfolder +folder", 0,
66 #define DMSGSW 3
67 "draftmessage msg", 0,
68 #define NDFLDSW 4
69 "nodraftfolder", 0,
70
71 #define EDITRSW 5
72 "editor editor", 0,
73 #define NEDITSW 6
74 "noedit", 0,
75
76 #define FORMSW 7
77 "form formfile", 0,
78
79 #define INPLSW 8
80 "inplace", 0,
81 #define NINPLSW 9
82 "noinplace", 0,
83
84 #define WHATSW 10
85 "whatnowproc program", 0,
86 #define NWHATSW 11
87 "nowhatnowproc", 0,
88
89 #define HELPSW 12
90 "help", 4,
91
92 #define FILESW 13
93 "file file", -4, /* interface from msh */
94
95 NULL, 0
96 };
97
98 /* \f */
99
100 static struct swit aqrnl[] = {
101 #define NOSW 0
102 "quit", 0,
103 #define YESW 1
104 "replace", 0,
105 #define LISTDSW 2
106 "list", 0,
107 #define REFILSW 3
108 "refile +folder", 0,
109 #define NEWSW 4
110 "new", 0,
111
112 NULL, 0
113 };
114
115
116 static struct swit aqrl[] = {
117 "quit", 0,
118 "replace", 0,
119 "list", 0,
120 "refile +folder", 0,
121
122 NULL, 0
123 };
124
125 /* \f */
126
127 /* ARGSUSED */
128
129 main (argc, argv)
130 int argc;
131 char *argv[];
132 {
133 int anot = 0,
134 inplace = 0,
135 nedit = 0,
136 nwhat = 0,
137 i,
138 in,
139 isdf = 0,
140 out;
141 char *cp,
142 *cwd,
143 *maildir,
144 *msgnam,
145 *dfolder = NULL,
146 *dmsg = NULL,
147 *ed = NULL,
148 *file = NULL,
149 *folder = NULL,
150 *form = NULL,
151 *msg = NULL,
152 buf[100],
153 drft[BUFSIZ],
154 **ap,
155 **argp,
156 *arguments[MAXARGS];
157 struct msgs *mp = NULL;
158 struct stat st;
159
160 #ifdef LOCALE
161 setlocale(LC_ALL, "");
162 #endif
163 invo_name = r1bindex (argv[0], '/');
164 if ((cp = m_find (invo_name)) != NULL) {
165 ap = brkstring (cp = getcpy (cp), " ", "\n");
166 ap = copyip (ap, arguments);
167 }
168 else
169 ap = arguments;
170 (void) copyip (argv + 1, ap);
171 argp = arguments;
172
173 /* \f */
174
175 while (cp = *argp++) {
176 if (*cp == '-')
177 switch (smatch (++cp, switches)) {
178 case AMBIGSW:
179 ambigsw (cp, switches);
180 done (1);
181 case UNKWNSW:
182 adios (NULLCP, "-%s unknown", cp);
183 case HELPSW:
184 (void) sprintf (buf, "%s [+folder] [msg] [switches]",
185 invo_name);
186 help (buf, switches);
187 done (1);
188
189 case ANNOSW:
190 anot++;
191 continue;
192 case NANNOSW:
193 anot = 0;
194 continue;
195
196 case EDITRSW:
197 if (!(ed = *argp++) || *ed == '-')
198 adios (NULLCP, "missing argument to %s", argp[-2]);
199 nedit = 0;
200 continue;
201 case NEDITSW:
202 nedit++;
203 continue;
204
205 case WHATSW:
206 if (!(whatnowproc = *argp++) || *whatnowproc == '-')
207 adios (NULLCP, "missing argument to %s", argp[-2]);
208 nwhat = 0;
209 continue;
210 case NWHATSW:
211 nwhat++;
212 continue;
213
214 case FILESW:
215 if (file)
216 adios (NULLCP, "only one file at a time!");
217 if (!(cp = *argp++) || *cp == '-')
218 adios (NULLCP, "missing argument to %s", argp[-2]);
219 file = path (cp, TFILE);
220 continue;
221 case FORMSW:
222 if (!(form = *argp++) || *form == '-')
223 adios (NULLCP, "missing argument to %s", argp[-2]);
224 continue;
225
226 case INPLSW:
227 inplace++;
228 continue;
229 case NINPLSW:
230 inplace = 0;
231 continue;
232
233 case DFOLDSW:
234 if (dfolder)
235 adios (NULLCP, "only one draft folder at a time!");
236 if (!(cp = *argp++) || *cp == '-')
237 adios (NULLCP, "missing argument to %s", argp[-2]);
238 dfolder = path (*cp == '+' || *cp == '@@' ? cp + 1 : cp,
239 *cp != '@@' ? TFOLDER : TSUBCWF);
240 continue;
241 case DMSGSW:
242 if (dmsg)
243 adios (NULLCP, "only one draft message at a time!");
244 if (!(dmsg = *argp++) || *dmsg == '-')
245 adios (NULLCP, "missing argument to %s", argp[-2]);
246 continue;
247 case NDFLDSW:
248 dfolder = NULL;
249 isdf = NOTOK;
250 continue;
251 }
252 if (*cp == '+' || *cp == '@@') {
253 if (folder)
254 adios (NULLCP, "only one folder at a time!");
255 else
256 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
257 }
258 else
259 if (msg)
260 adios (NULLCP, "only one message at a time!");
261 else
262 msg = cp;
263 }
264
265 /* \f */
266
267 cwd = getcpy (pwd ());
268
269 if (!m_find ("path"))
270 free (path ("./", TFOLDER));
271 if (file && (msg || folder))
272 adios (NULLCP, "can't mix files and folders/msgs");
273
274 if (form) {
275 if ((in = open (libpath (form), 0)) == NOTOK)
276 adios (form, "unable to open form file");
277 }
278 else {
279 if ((in = open (libpath (distcomps), 0)) == NOTOK)
280 adios (distcomps, "unable to open default components file");
281 form = distcomps;
282 }
283
284 try_it_again: ;
285 (void) strcpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf));
286 if (stat (drft, &st) != NOTOK) {
287 printf ("Draft \"%s\" exists (%ld bytes).", drft, st.st_size);
288 for (i = LISTDSW; i != YESW;) {
289 if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl)))
290 done (1);
291 switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) {
292 case NOSW:
293 done (0);
294 case NEWSW:
295 dmsg = NULL;
296 goto try_it_again;
297 case YESW:
298 break;
299 case LISTDSW:
300 (void) showfile (++argp, drft);
301 break;
302 case REFILSW:
303 if (refile (++argp, drft) == 0)
304 i = YESW;
305 break;
306 default:
307 advise (NULLCP, "say what?");
308 break;
309 }
310 }
311 }
312 if ((out = creat (drft, m_gmprot ())) == NOTOK)
313 adios (drft, "unable to create");
314
315 cpydata (in, out, form, drft);
316 (void) close (in);
317 (void) close (out);
318
319 /* \f */
320
321 if (file) {
322 anot = 0;
323 goto go_to_it;
324 }
325
326 if (!msg)
327 msg = "cur";
328 if (!folder)
329 folder = m_getfolder ();
330 maildir = m_maildir (folder);
331
332 if (chdir (maildir) == NOTOK)
333 adios (maildir, "unable to change directory to");
334 if (!(mp = m_gmsg (folder)))
335 adios (NULLCP, "unable to read folder %s", folder);
336 if (mp -> hghmsg == 0)
337 adios (NULLCP, "no messages in %s", folder);
338
339 if (!m_convert (mp, msg))
340 done (1);
341 m_setseq (mp);
342
343 if (mp -> numsel > 1)
344 adios (NULLCP, "only one message at a time!");
345
346 go_to_it: ;
347 if ((in = open (msgnam = file ? file : getcpy (m_name (mp -> lowsel)), 0))
348 == NOTOK)
349 adios (msgnam, "unable to open message");
350
351 if (!file) {
352 m_replace (pfolder, folder);
353 if (mp -> lowsel != mp -> curmsg)
354 m_setcur (mp, mp -> lowsel);
355 m_sync (mp);
356 m_update ();
357 }
358
359 if (nwhat)
360 done (0);
361 (void) what_now (ed, nedit, NOUSE, drft, msgnam, 1, mp,
362 anot ? "Resent" : NULLCP, inplace, cwd);
363 done (1);
364 }
365 @
366
367
368 1.4
369 log
370 @LOCALE
371 @
372 text
373 @d3 2
374 a4 2
375 static char ident[] = "@@(#)$Id: dist.c,v 1.3 1992/02/04 17:46:56 jromine Exp jromine $";
376 #endif lint
377 @
378
379
380 1.3
381 log
382 @rename m_whatnow() to what_now() since it's not a m_ routine
383 @
384 text
385 @d3 1
386 a3 1
387 static char ident[] = "@@(#)$Id: dist.c,v 1.2 1992/01/31 22:09:12 jromine Exp jromine $";
388 d10 3
389 d118 3
390 @
391
392
393 1.2
394 log
395 @kerberos
396 @
397 text
398 @d3 1
399 a3 1
400 static char ident[] = "@@(#)$Id: scan.c,v 1.9 1992/01/23 23:06:45 jromine Exp $";
401 d313 1
402 a313 1
403 (void) m_whatnow (ed, nedit, NOUSE, drft, msgnam, 1, mp,
404 @
405
406
407 1.1
408 log
409 @Initial revision
410 @
411 text
412 @d2 3
413 d50 1
414 a50 1
415 NULL, NULL
416 d67 1
417 a67 1
418 NULL, NULL
419 d77 1
420 a77 1
421 NULL, NULL
422 @