]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/RCS/repl.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / uip / RCS / repl.c,v
1 head 1.9;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.9
9 date 95.12.06.21.07.03; author jromine; state Exp;
10 branches;
11 next 1.8;
12
13 1.8
14 date 92.12.15.00.20.22; author jromine; state Exp;
15 branches;
16 next 1.7;
17
18 1.7
19 date 92.11.04.00.58.27; author jromine; state Exp;
20 branches;
21 next 1.6;
22
23 1.6
24 date 92.02.04.17.46.56; author jromine; state Exp;
25 branches;
26 next 1.5;
27
28 1.5
29 date 92.01.31.22.25.39; author jromine; state Exp;
30 branches;
31 next 1.4;
32
33 1.4
34 date 90.04.05.15.03.54; author sources; state Exp;
35 branches;
36 next 1.3;
37
38 1.3
39 date 90.04.04.21.30.31; author sources; state Exp;
40 branches;
41 next 1.2;
42
43 1.2
44 date 90.03.18.20.28.26; author sources; state Exp;
45 branches;
46 next 1.1;
47
48 1.1
49 date 90.03.18.20.27.44; author sources; state Exp;
50 branches;
51 next ;
52
53
54 desc
55 @@
56
57
58 1.9
59 log
60 @add repl -mime
61 @
62 text
63 @/* repl.c - reply to a message */
64 #ifndef lint
65 static char ident[] = "@@(#)$Id: repl.c,v 1.8 1992/12/15 00:20:22 jromine Exp jromine $";
66 #endif /* lint */
67
68 #include "../h/mh.h"
69 #include <stdio.h>
70 #include <sys/types.h>
71 #include <sys/stat.h>
72 #ifdef LOCALE
73 #include <locale.h>
74 #endif
75
76 #ifndef MIME
77 #define MIMEminc(a) (a)
78 #else /* MIME */
79 #define MIMEminc(a) 0
80 #endif /* MIME */
81
82 /* \f */
83
84 static struct swit switches[] = {
85 #define ANNOSW 0
86 "annotate", 0,
87 #define NANNOSW 1
88 "noannotate", 0,
89
90 #define CCSW 2
91 "cc type", 0,
92 #define NCCSW 3
93 "nocc type", 0,
94
95 #define DFOLDSW 4
96 "draftfolder +folder", 0,
97 #define DMSGSW 5
98 "draftmessage msg", 0,
99 #define NDFLDSW 6
100 "nodraftfolder", 0,
101
102 #define EDITRSW 7
103 "editor editor", 0,
104 #define NEDITSW 8
105 "noedit", 0,
106
107 #define FCCSW 9
108 "fcc folder", 0,
109
110 #define FILTSW 10
111 "filter filterfile", 0,
112 #define FORMSW 11
113 "form formfile", 0,
114
115 #define FRMTSW 12
116 "format", -5,
117 #define NFRMTSW 13
118 "noformat", -7,
119
120 #define INPLSW 14
121 "inplace", 0,
122 #define NINPLSW 15
123 "noinplace", 0,
124
125 #define MIMESW 16
126 "mime", MIMEminc(-4),
127 #define NMIMESW 17
128 "nomime", MIMEminc(-6),
129
130 #define QURYSW 18
131 "query", 0,
132 #define NQURYSW 19
133 "noquery", 0,
134
135 #define WHATSW 20
136 "whatnowproc program", 0,
137 #define NWHATSW 21
138 "nowhatnowproc", 0,
139
140 #define WIDTHSW 22
141 "width columns", 0,
142
143 #define HELPSW 23
144 "help", 4,
145
146 #define FILESW 24
147 "file file", -4, /* interface from msh */
148
149 #ifdef MHE
150 #define BILDSW 25
151 "build", -5, /* interface from mhe */
152 #endif /* MHE */
153
154 NULL, 0
155 };
156
157
158 static struct swit ccswitches[] = {
159 #define CTOSW 0
160 "to", 0,
161 #define CCCSW 1
162 "cc", 0,
163 #define CMESW 2
164 "me", 0,
165 #define CALSW 3
166 "all", 0,
167
168 NULL, 0
169 };
170
171 /* \f */
172
173 static struct swit aqrnl[] = {
174 #define NOSW 0
175 "quit", 0,
176 #define YESW 1
177 "replace", 0,
178 #define LISTDSW 2
179 "list", 0,
180 #define REFILSW 3
181 "refile +folder", 0,
182 #define NEWSW 4
183 "new", 0,
184
185 NULL, 0
186 };
187
188
189 static struct swit aqrl[] = {
190 "quit", 0,
191 "replace", 0,
192 "list", 0,
193 "refile +folder", 0,
194
195 NULL, 0
196 };
197
198 /* \f */
199
200 #ifndef ATHENA
201 #define CCDFLT 1
202 #else /* ATHENA */
203 #define CCDFLT 0
204 #endif /* ATHENA */
205
206 short ccto = CCDFLT; /* global for replsbr */
207 short cccc = CCDFLT;
208 short ccme = CCDFLT;
209 short format = 1;
210 short outputlinelen = OUTPUTLINELEN;
211 short querysw = 0;
212
213 extern int mime;
214
215 char *fcc = NULL; /* global for replsbr */
216 char *filter = NULL;
217 char *form = NULL;
218
219 /* \f */
220
221 /* ARGSUSED */
222
223 main (argc, argv)
224 int argc;
225 char *argv[];
226 {
227 int i,
228 isdf = 0,
229 anot = 0,
230 inplace = 0,
231 #ifdef MHE
232 buildsw = 0,
233 #endif /* MHE */
234 nedit = 0,
235 nwhat = 0;
236 char *cp,
237 *cwd,
238 *dp,
239 *maildir,
240 *file = NULL,
241 *folder = NULL,
242 *msg = NULL,
243 *dfolder = NULL,
244 *dmsg = NULL,
245 *ed = NULL,
246 drft[BUFSIZ],
247 buf[100],
248 **ap,
249 **argp,
250 *arguments[MAXARGS];
251 struct msgs *mp = NULL;
252 struct stat st;
253 FILE *in;
254
255 #ifdef LOCALE
256 setlocale(LC_ALL, "");
257 #endif
258 invo_name = r1bindex (argv[0], '/');
259 if ((cp = m_find (invo_name)) != NULL) {
260 ap = brkstring (cp = getcpy (cp), " ", "\n");
261 ap = copyip (ap, arguments);
262 }
263 else
264 ap = arguments;
265 (void) copyip (argv + 1, ap);
266 argp = arguments;
267
268 /* \f */
269
270 while (cp = *argp++) {
271 if (*cp == '-')
272 switch (smatch (++cp, switches)) {
273 case AMBIGSW:
274 ambigsw (cp, switches);
275 done (1);
276 case UNKWNSW:
277 adios (NULLCP, "-%s unknown", cp);
278 case HELPSW:
279 (void) sprintf (buf, "%s: [+folder] [msg] [switches]",
280 invo_name);
281 help (buf, switches);
282 done (0);
283
284 case ANNOSW:
285 anot++;
286 continue;
287 case NANNOSW:
288 anot = 0;
289 continue;
290
291 case CCSW:
292 if (!(cp = *argp++) || *cp == '-')
293 adios (NULLCP, "missing argument to %s", argp[-2]);
294 docc (cp, 1);
295 continue;
296 case NCCSW:
297 if (!(cp = *argp++) || *cp == '-')
298 adios (NULLCP, "missing argument to %s", argp[-2]);
299 docc (cp, 0);
300 continue;
301
302 case EDITRSW:
303 if (!(ed = *argp++) || *ed == '-')
304 adios (NULLCP, "missing argument to %s", argp[-2]);
305 nedit = 0;
306 continue;
307 case NEDITSW:
308 nedit++;
309 continue;
310
311 case WHATSW:
312 if (!(whatnowproc = *argp++) || *whatnowproc == '-')
313 adios (NULLCP, "missing argument to %s", argp[-2]);
314 nwhat = 0;
315 continue;
316 #ifdef MHE
317 case BILDSW:
318 buildsw++; /* fall... */
319 #endif /* MHE */
320 case NWHATSW:
321 nwhat++;
322 continue;
323
324 case FCCSW:
325 if (!(cp = *argp++) || *cp == '-')
326 adios (NULLCP, "missing argument to %s", argp[-2]);
327 dp = NULL;
328 if (*cp == '@@')
329 cp = dp = path (cp + 1, TSUBCWF);
330 if (fcc)
331 fcc = add (", ", fcc);
332 fcc = add (cp, fcc);
333 if (dp)
334 free (dp);
335 continue;
336
337 case FILESW:
338 if (file)
339 adios (NULLCP, "only one file at a time!");
340 if (!(cp = *argp++) || *cp == '-')
341 adios (NULLCP, "missing argument to %s", argp[-2]);
342 file = path (cp, TFILE);
343 continue;
344 case FILTSW:
345 if (!(cp = *argp++) || *cp == '-')
346 adios (NULLCP, "missing argument to %s", argp[-2]);
347 filter = getcpy (libpath (cp));
348 mime = 0;
349 continue;
350 case FORMSW:
351 if (!(form = *argp++) || *form == '-')
352 adios (NULLCP, "missing argument to %s", argp[-2]);
353 continue;
354
355 case FRMTSW:
356 format++;
357 continue;
358 case NFRMTSW:
359 format = 0;
360 continue;
361
362 case INPLSW:
363 inplace++;
364 continue;
365 case NINPLSW:
366 inplace = 0;
367 continue;
368
369 case MIMESW:
370 #ifdef MIME
371 mime++;
372 filter = NULL;
373 #endif
374 continue;
375 case NMIMESW:
376 mime = 0;
377 continue;
378
379 case QURYSW:
380 querysw++;
381 continue;
382 case NQURYSW:
383 querysw = 0;
384 continue;
385
386 case WIDTHSW:
387 if (!(cp = *argp++) || *cp == '-')
388 adios (NULLCP, "missing argument to %s", argp[-2]);
389 if ((outputlinelen = atoi (cp)) < 10)
390 adios (NULLCP, "impossible width %d", outputlinelen);
391 continue;
392
393 case DFOLDSW:
394 if (dfolder)
395 adios (NULLCP, "only one draft folder at a time!");
396 if (!(cp = *argp++) || *cp == '-')
397 adios (NULLCP, "missing argument to %s", argp[-2]);
398 dfolder = path (*cp == '+' || *cp == '@@' ? cp + 1 : cp,
399 *cp != '@@' ? TFOLDER : TSUBCWF);
400 continue;
401 case DMSGSW:
402 if (dmsg)
403 adios (NULLCP, "only one draft message at a time!");
404 if (!(dmsg = *argp++) || *dmsg == '-')
405 adios (NULLCP, "missing argument to %s", argp[-2]);
406 continue;
407 case NDFLDSW:
408 dfolder = NULL;
409 isdf = NOTOK;
410 continue;
411 }
412 if (*cp == '+' || *cp == '@@') {
413 if (folder)
414 adios (NULLCP, "only one folder at a time!");
415 else
416 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
417 }
418 else
419 if (msg)
420 adios (NULLCP, "only one message at a time!");
421 else
422 msg = cp;
423 }
424
425 /* \f */
426
427 cwd = getcpy (pwd ());
428
429 if (!m_find ("path"))
430 free (path ("./", TFOLDER));
431 if (file && (msg || folder))
432 adios (NULLCP, "can't mix files and folders/msgs");
433
434 try_it_again: ;
435 #ifndef MHE
436 (void) strcpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf));
437 if (stat (drft, &st) != NOTOK) {
438 #else /* MHE */
439 (void) strcpy (drft, buildsw ? m_maildir ("reply")
440 : m_draft (dfolder, NULLCP, NOUSE, &isdf));
441 if (!buildsw && stat (drft, &st) != NOTOK) {
442 #endif /* MHE */
443 printf ("Draft \"%s\" exists (%ld bytes).", drft, st.st_size);
444 for (i = LISTDSW; i != YESW;) {
445 if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl)))
446 done (1);
447 switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) {
448 case NOSW:
449 done (0);
450 case NEWSW:
451 dmsg = NULL;
452 goto try_it_again;
453 case YESW:
454 break;
455 case LISTDSW:
456 (void) showfile (++argp, drft);
457 break;
458 case REFILSW:
459 if (refile (++argp, drft) == 0)
460 i = YESW;
461 break;
462 default:
463 advise (NULLCP, "say what?");
464 break;
465 }
466 }
467 }
468
469 /* \f */
470
471 if (file) {
472 anot = 0;
473 goto go_to_it;
474 }
475
476 if (!msg)
477 msg = "cur";
478 if (!folder)
479 folder = m_getfolder ();
480 maildir = m_maildir (folder);
481
482 if (chdir (maildir) == NOTOK)
483 adios (maildir, "unable to change directory to");
484 if (!(mp = m_gmsg (folder)))
485 adios (NULLCP, "unable to read folder %s", folder);
486 if (mp -> hghmsg == 0)
487 adios (NULLCP, "no messages in %s", folder);
488
489 if (!m_convert (mp, msg))
490 done (1);
491 m_setseq (mp);
492
493 if (mp -> numsel > 1)
494 adios (NULLCP, "only one message at a time!");
495
496 m_replace (pfolder, folder);
497 if (mp -> lowsel != mp -> curmsg)
498 m_setcur (mp, mp -> lowsel);
499 m_sync (mp);
500 m_update ();
501
502 go_to_it: ;
503 msg = file ? file : getcpy (m_name (mp -> lowsel));
504
505 if ((in = fopen (msg, "r")) == NULL)
506 adios (msg, "unable to open");
507
508 replout (in, msg, drft, mp);
509 (void) fclose (in);
510
511 if (nwhat)
512 done (0);
513 (void) what_now (ed, nedit, NOUSE, drft, msg, 0, mp,
514 anot ? "Replied" : NULLCP, inplace, cwd);
515 done (1);
516 }
517
518 /* \f */
519
520 docc (cp, ccflag)
521 register char *cp;
522 int ccflag;
523 {
524 switch (smatch (cp, ccswitches)) {
525 case AMBIGSW:
526 ambigsw (cp, ccswitches);
527 done (1);
528 case UNKWNSW:
529 adios (NULLCP, "-%scc %s unknown", ccflag ? "" : "no", cp);
530
531 case CTOSW:
532 ccto = ccflag;
533 break;
534
535 case CCCSW:
536 cccc = ccflag;
537 break;
538
539 case CMESW:
540 ccme = ccflag;
541 break;
542
543 case CALSW:
544 ccto = cccc = ccme = ccflag;
545 break;
546 }
547 }
548 @
549
550
551 1.8
552 log
553 @endif sugar
554 @
555 text
556 @d3 1
557 a3 1
558 static char ident[] = "@@(#)$Id: repl.c,v 1.7 1992/11/04 00:58:27 jromine Exp jromine $";
559 d14 6
560 d63 6
561 a68 1
562 #define QURYSW 16
563 d70 1
564 a70 1
565 #define NQURYSW 17
566 d73 1
567 a73 1
568 #define WHATSW 18
569 d75 1
570 a75 1
571 #define NWHATSW 19
572 d78 1
573 a78 1
574 #define WIDTHSW 20
575 d81 1
576 a81 1
577 #define HELPSW 21
578 d84 1
579 a84 1
580 #define FILESW 22
581 d88 1
582 a88 1
583 #define BILDSW 23
584 d151 2
585 d286 1
586 d307 10
587 d446 1
588 a446 1
589 replout (in, msg, drft);
590 @
591
592
593 1.7
594 log
595 @LOCALE
596 @
597 text
598 @d3 2
599 a4 2
600 static char ident[] = "@@(#)$Id: repl.c,v 1.6 1992/02/04 17:46:56 jromine Exp jromine $";
601 #endif lint
602 d79 1
603 a79 1
604 #endif MHE
605 d129 1
606 a129 1
607 #else ATHENA
608 d131 1
609 a131 1
610 #endif ATHENA
611 d158 1
612 a158 1
613 #endif MHE
614 d244 1
615 a244 1
616 #endif MHE
617 d352 1
618 a352 1
619 #else MHE
620 d356 1
621 a356 1
622 #endif MHE
623 @
624
625
626 1.6
627 log
628 @rename m_whatnow() to what_now() since it's not a m_ routine
629 @
630 text
631 @d3 1
632 a3 1
633 static char ident[] = "@@(#)$Id: repl.c,v 1.5 1992/01/31 22:25:39 jromine Exp jromine $";
634 d10 3
635 d180 3
636 @
637
638
639 1.5
640 log
641 @kerberos
642 @
643 text
644 @d3 1
645 a3 1
646 static char ident[] = "@@(#)$Id: repl.c,v 1.4 1990/04/05 15:03:54 sources Exp jromine $";
647 d421 1
648 a421 1
649 (void) m_whatnow (ed, nedit, NOUSE, drft, msg, 0, mp,
650 @
651
652
653 1.4
654 log
655 @add ID
656 @
657 text
658 @d3 1
659 a3 1
660 static char ident[] = "@@(#)$Id:$";
661 d78 1
662 a78 1
663 NULL, NULL
664 d92 1
665 a92 1
666 NULL, NULL
667 d109 1
668 a109 1
669 NULL, NULL
670 d119 1
671 a119 1
672 NULL, NULL
673 @
674
675
676 1.3
677 log
678 @search for filter file with libpath
679 @
680 text
681 @d2 3
682 @
683
684
685 1.2
686 log
687 @make -[no]format invisible. they don't seem to used anymore
688 @
689 text
690 @d263 1
691 a263 1
692 filter = getcpy (m_maildir (cp));
693 @
694
695
696 1.1
697 log
698 @Initial revision
699 @
700 text
701 @d42 1
702 a42 1
703 "format", 5,
704 d44 1
705 a44 1
706 "noformat", 7,
707 @