Removed note from BUGS section of several man pages saying
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / show.c,v
1 head    1.15;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.15
9 date    95.12.06.21.07.46;      author jromine; state Exp;
10 branches;
11 next    1.14;
12
13 1.14
14 date    93.10.26.20.09.21;      author jromine; state Exp;
15 branches;
16 next    1.13;
17
18 1.13
19 date    93.10.26.16.25.19;      author jromine; state Exp;
20 branches;
21 next    1.12;
22
23 1.12
24 date    92.12.15.00.20.22;      author jromine; state Exp;
25 branches;
26 next    1.11;
27
28 1.11
29 date    92.11.24.18.26.39;      author jromine; state Exp;
30 branches;
31 next    1.10;
32
33 1.10
34 date    92.11.04.01.02.58;      author jromine; state Exp;
35 branches;
36 next    1.9;
37
38 1.9
39 date    92.10.16.22.41.36;      author jromine; state Exp;
40 branches;
41 next    1.8;
42
43 1.8
44 date    92.05.19.21.04.45;      author jromine; state Exp;
45 branches;
46 next    1.7;
47
48 1.7
49 date    92.03.03.17.13.54;      author jromine; state Exp;
50 branches;
51 next    1.6;
52
53 1.6
54 date    92.02.01.00.34.45;      author jromine; state Exp;
55 branches;
56 next    1.5;
57
58 1.5
59 date    92.01.31.22.27.23;      author jromine; state Exp;
60 branches;
61 next    1.4;
62
63 1.4
64 date    92.01.31.16.35.17;      author jromine; state Exp;
65 branches;
66 next    1.3;
67
68 1.3
69 date    90.12.19.08.48.39;      author mh;      state Exp;
70 branches;
71 next    1.2;
72
73 1.2
74 date    90.04.05.15.03.16;      author sources; state Exp;
75 branches;
76 next    1.1;
77
78 1.1
79 date    90.02.09.10.50.48;      author sources; state Exp;
80 branches;
81 next    ;
82
83
84 desc
85 @@
86
87
88 1.15
89 log
90 @mime patch from mtr
91 @
92 text
93 @/* show.c - list messages */
94 #ifndef lint
95 static char ident[] = "@@(#)$Id: show.c,v 1.14 1993/10/26 20:09:21 jromine Exp jromine $";
96 #endif  /* lint */
97
98 #include "../h/mh.h"
99 #include <ctype.h>
100 #include <stdio.h>
101 #ifdef LOCALE
102 #include        <locale.h>
103 #endif
104
105 /* \f */
106
107 static struct swit switches[] = {
108 #define DRFTSW  0
109     "draft", 5,
110
111 #define FORMSW  1
112     "form formfile", 4,
113 #define PROGSW  2
114     "moreproc program", 4,
115 #define NPROGSW 3
116     "nomoreproc", 3,
117 #define LENSW   4
118     "length lines", 4,
119 #define WIDSW   5
120     "width columns", 4,
121
122 #define SHOWSW  6
123     "showproc program", 4,
124 #define NSHOWSW 7
125     "noshowproc", 3,
126
127 #define HEADSW  8
128     "header", 4,
129 #define NHEADSW 9
130     "noheader", 3,
131
132 #define FILESW  10
133     "file file", -4,            /* interface from showfile */
134
135 #define HELPSW  11
136     "help", 4,
137
138     NULL, 0
139 };
140
141 #ifdef  MIME
142 static int  nontext();
143 #endif
144
145 #define SHOW    0
146 #define NEXT    1
147 #define PREV    2
148
149 /* \f */
150
151 /* ARGSUSED */
152
153 main (argc, argv)
154 int     argc;
155 char  **argv;
156 {
157     int     draftsw = 0,
158             headersw = 1,
159             nshow = 0,
160             msgp = 0,
161             vecp = 1,
162             procp = 1,
163             isdf = 0,
164             mode = SHOW,
165             msgnum;
166     char   *cp,
167            *maildir,
168            *file = NULL,
169            *folder = NULL,
170            *proc,
171             buf[100],
172           **ap,
173           **argp,
174            *arguments[MAXARGS],
175            *msgs[MAXARGS],
176            *vec[MAXARGS];
177     struct msgs *mp;
178
179 #ifdef LOCALE
180         setlocale(LC_ALL, "");
181 #endif
182     invo_name = r1bindex (argv[0], '/');
183     if (uleq (invo_name, "next"))
184         mode = NEXT;
185     else
186         if (uleq (invo_name, "prev"))
187             mode = PREV;
188     if ((cp = m_find (invo_name)) != NULL) {
189         ap = brkstring (cp = getcpy (cp), " ", "\n");
190         ap = copyip (ap, arguments);
191     }
192     else
193         ap = arguments;
194     (void) copyip (argv + 1, ap);
195     argp = arguments;
196
197 /* \f */
198
199     while (cp = *argp++) {
200         if (*cp == '-')
201             switch (smatch (++cp, switches)) {
202                 case AMBIGSW: 
203                     ambigsw (cp, switches);
204                     done (1);
205                 case UNKWNSW: 
206                 case NPROGSW:
207                     vec[vecp++] = --cp;
208                     continue;
209                 case HELPSW: 
210                     (void) sprintf (buf,
211                            "%s [+folder] %s[switches] [switches for showproc]",
212                             invo_name, mode == SHOW ? "[msgs] ": "");
213                     help (buf, switches);
214                     done (1);
215
216                 case DRFTSW: 
217                     if (file)
218                         adios (NULLCP, "only one file at a time!");
219                     draftsw++;
220                     if (mode == SHOW)
221                         continue;
222             usage:  ;
223                     adios (NULLCP,
224                             "usage: %s [+folder] [switches] [switches for showproc]",
225                             invo_name);
226                 case FILESW: 
227                     if (mode != SHOW)
228                         goto usage;
229                     if (draftsw || file)
230                         adios (NULLCP, "only one file at a time!");
231                     if (!(cp = *argp++) || *cp == '-')
232                         adios (NULLCP, "missing argument to %s", argp[-2]);
233                     file = path (cp, TFILE);
234                     continue;
235
236                 case HEADSW: 
237                     headersw++;
238                     continue;
239                 case NHEADSW: 
240                     headersw = 0;
241                     continue;
242
243                 case FORMSW:
244                     vec[vecp++] = --cp;
245                     if (!(cp = *argp++) || *cp == '-')
246                         adios (NULLCP, "missing argument to %s", argp[-2]);
247                     vec[vecp++] = getcpy (libpath(cp));
248                     continue;
249
250                 case PROGSW:
251                 case LENSW:
252                 case WIDSW:
253                     vec[vecp++] = --cp;
254                     if (!(cp = *argp++) || *cp == '-')
255                         adios (NULLCP, "missing argument to %s", argp[-2]);
256                     vec[vecp++] = cp;
257                     continue;
258
259                 case SHOWSW: 
260                     if (!(showproc = *argp++) || *showproc == '-')
261                         adios (NULLCP, "missing argument to %s", argp[-2]);
262                     nshow = 0;
263                     continue;
264                 case NSHOWSW: 
265                     nshow++;
266                     continue;
267             }
268         if (*cp == '+' || *cp == '@@') {
269             if (folder)
270                 adios (NULLCP, "only one folder at a time!");
271             else
272                 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
273         }
274         else
275             if (mode != SHOW)
276                 goto usage;
277             else
278                 msgs[msgp++] = cp;
279     }
280     procp = vecp;
281
282 /* \f */
283
284     if (!m_find ("path"))
285         free (path ("./", TFOLDER));
286
287     if (draftsw || file) {
288         if (msgp)
289             adios (NULLCP, "only one file at a time!");
290         vec[vecp++] = draftsw
291             ? getcpy (m_draft (folder, msgp ? msgs[0] : NULL, 1, &isdf))
292             : file;
293         goto go_to_it;
294     }
295
296 #ifdef  WHATNOW
297     if (!msgp && !folder && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) {
298         draftsw++;
299         vec[vecp++] = cp;
300         goto go_to_it;
301     }
302 #endif  /* WHATNOW */
303
304     if (!msgp)
305         msgs[msgp++] = mode == NEXT ? "next" : mode == PREV ? "prev" : "cur";
306     if (!folder)
307         folder = m_getfolder ();
308     maildir = m_maildir (folder);
309
310     if (chdir (maildir) == NOTOK)
311         adios (maildir, "unable to change directory to");
312     if (!(mp = m_gmsg (folder)))
313         adios (NULLCP, "unable to read folder %s", folder);
314     if (mp -> hghmsg == 0)
315         adios (NULLCP, "no messages in %s", folder);
316
317     for (msgnum = 0; msgnum < msgp; msgnum++)
318         if (!m_convert (mp, msgs[msgnum]))
319             done (1);
320     for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
321         if (mp -> msgstats[msgnum] & SELECTED)
322             mp -> msgstats[msgnum] |= UNSEEN;
323     m_setseq (mp);
324     m_setvis (mp, 1);
325
326     if (mp -> numsel > MAXARGS - 2)
327         adios (NULLCP, "more than %d messages for show exec", MAXARGS - 2);
328     for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
329         if (mp -> msgstats[msgnum] & SELECTED)
330             vec[vecp++] = getcpy (m_name (msgnum));
331
332     m_replace (pfolder, folder);
333     if (mp -> hghsel != mp -> curmsg)
334         m_setcur (mp, mp -> hghsel);
335     m_sync (mp);
336     m_update ();
337
338     if (vecp == 2 && headersw)
339         printf ("(Message %s:%s)\n", folder, vec[1]);
340
341 /* \f */
342
343 go_to_it: ;
344     (void) fflush (stdout);
345
346     vec[vecp] = NULL;
347
348 #ifdef  MIME
349     if (!nshow && !getenv ("NOMHNPROC")) {
350         if (!(cp = m_find ("mhnproc")))
351             cp = "mhn";
352
353         if (draftsw || file) {
354             if (nontext (vec[vecp - 1])) {
355                 vec[vecp] = vec[vecp - 1];
356                 vec[vecp - 1] = "-file";
357                 vecp++;
358                 goto use_mmp;
359             }
360         }
361         else
362             for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
363                 if ((mp -> msgstats[msgnum] & SELECTED)
364                         && nontext (m_name (msgnum))) {
365 use_mmp: ;
366                     proc = cp;
367                     vec[vecp++] = "-show";
368                     vec[vecp] = NULL;
369                     goto finish;
370                 }
371     }
372 #endif  /* MIME */
373     if (nshow)
374         proc = "/bin/cat";
375     else {
376         if (folder && !draftsw && !file)
377             (void) m_putenv ("mhfolder", folder);
378         if (strcmp (r1bindex (showproc, '/'), "mhl") == 0) {
379             vec[0] = "mhl";
380             (void) mhl (vecp, vec);
381             done (0);
382         }
383         proc = showproc;
384     }
385
386     if (!draftsw
387             && !file
388             && chdir (maildir = concat (m_maildir (""), "/", NULLCP))
389             != NOTOK) {
390         mp -> foldpath = concat (mp -> foldpath, "/", NULLCP);
391         cp = ssequal (maildir, mp -> foldpath)
392             ? mp -> foldpath + strlen (maildir)
393             : mp -> foldpath;
394         for (msgnum = procp; msgnum < vecp; msgnum++)
395             vec[msgnum] = concat (cp, vec[msgnum], NULLCP);
396     }
397
398 finish:;
399     vec[0] = r1bindex (proc, '/');
400     execvp (proc, vec);
401     adios (proc, "unable to exec");
402 }
403
404 /* \f */
405
406 /* Cheat:  we are loaded with adrparse, which wants a routine called
407    OfficialName().  We call adrparse:getm() with the correct arguments
408    to prevent OfficialName() from being called.  Hence, the following
409    is to keep the loader happy.
410  */
411
412 char   *OfficialName (name)
413 register char  *name;
414 {
415     return name;
416 }
417
418 /* \f */
419
420 #ifdef MIME
421 #include "../h/mhn.h"
422
423
424 static int  nontext (msgnam)
425 char   *msgnam;
426 {
427     int     result,
428             state;
429     register char   *bp,
430                     *dp;
431     char   *chset,
432            *cp,
433             buf[BUFSIZ],
434             name[NAMESZ];
435     FILE   *fp;
436
437     if ((fp = fopen (msgnam, "r")) == NULL)
438         return 0;
439
440     if (!(chset = getenv ("MM_CHARSET")))
441         chset = "us-ascii";
442
443     for (state = FLD;;)
444         switch (state = m_getfld (state, name, buf, sizeof buf, fp)) {
445             case FLD:
446             case FLDPLUS:
447             case FLDEOF:
448                 if (uleq (name, TYPE_FIELD)) {
449                     int     passno;
450                     char     c;
451
452                     cp = add (buf, NULLCP);
453                     while (state == FLDPLUS) {
454                         state = m_getfld (state, name, buf, sizeof buf, fp);
455                         cp = add (buf, cp);
456                     }
457                     bp = cp;
458                     passno = 1;
459
460 again: ;
461                     for (; isspace (*bp); bp++)
462                         continue;
463                     if (*bp == '(') {
464                         int     i;
465
466                         for (bp++, i = 0;;) {
467                             switch (*bp++) {
468                                 case '\0':
469 invalid: ;
470                                     result = 0;
471                                     goto out;
472                                 case '\\':
473                                     if (*bp++ == '\0')
474                                         goto invalid;
475                                     continue;
476                                 case '(':
477                                     i++;
478                                     /* and fall... */
479                                 default:
480                                     continue;
481                                 case ')':
482                                     if (--i < 0)
483                                         break;
484                                 continue;
485                             }
486                             break;
487                         }
488                     }
489                     if (passno == 2) {
490                         if (*bp != '/')
491                             goto invalid;
492                         bp++;
493                         passno = 3;
494                         goto again;
495                     }
496                     for (dp = bp; istoken (*dp); dp++)
497                         continue;
498                     c = *dp, *dp = NULL;
499                     if (*bp == NULL)
500                         goto invalid;
501                     if (passno > 1) {
502                         if (result = !uleq (bp, "plain"))
503                             goto out;
504                         *dp = c;
505                         for (dp++; isspace (*dp); dp++)
506                             continue;
507                         if (result = !uprf (dp, "charset"))
508                             goto invalid;
509                         dp += sizeof "charset" - 1;
510                         while (isspace (*dp))
511                             dp++;
512                         if (*dp++ != '=')
513                             goto invalid;
514                         while (isspace (*dp))
515                             dp++;
516                         if (*dp == '"') {
517                             if (bp = index (++dp, '"'))
518                                 *bp = NULL;
519                         }
520                         else
521                             for (bp = dp; *bp; bp++)
522                                 if (isspace (*bp)) {
523                                     *bp = NULL;
524                                     break;
525                                 }
526                         if ((result = !uleq (dp, chset))
527                                 && uleq (dp, "us-ascii")
528                                 && uleq (chset, "iso-8859-1"))
529                             result = 0;
530                     }
531                     else
532                         if (!(result = !uleq (bp, "text"))) {
533                             *dp = c;
534                             bp = dp;
535                             passno = 2;
536                             goto again;
537                         }
538
539 out: ;
540                     free (cp);
541                     if (result) {
542                         (void) fclose (fp);
543                         return result;
544                     }
545                     break;
546                 }
547                 if (uleq (name, ENCODING_FIELD)) {
548                     cp = add (buf, NULLCP);
549                     while (state == FLDPLUS) {
550                         state = m_getfld (state, name, buf, sizeof buf, fp);
551                         cp = add (buf, cp);
552                     }
553                     for (bp = cp; isspace (*bp); bp++)
554                         continue;
555                     for (dp = bp; istoken (*dp); dp++)
556                         continue;
557                     *dp = NULL;
558                     result = !uleq (bp, "7bit")
559                                 && !uleq (bp, "8bit")
560                                 && !uleq (bp, "binary");
561
562                     free (cp);
563                     if (result) {
564                         (void) fclose (fp);
565                         return result;
566                     }
567                     break;
568                 }
569                 while (state == FLDPLUS)
570                     state = m_getfld (state, name, buf, sizeof buf, fp);
571                 break;
572
573             default:
574                 (void) fclose (fp);
575                 return 0;
576         }
577 }
578 #endif  /* MIME */
579 @
580
581
582 1.14
583 log
584 @test for iso-8859-1 (and us-ascii) charsets
585 @
586 text
587 @d3 1
588 a3 1
589 static char ident[] = "@@(#)$Id: show.c,v 1.12 1992/12/15 00:20:22 jromine Exp $";
590 d416 1
591 a416 1
592                             goto out;
593 @
594
595
596 1.13
597 log
598 @add MM_CHARSET
599 @
600 text
601 @d3 1
602 a3 1
603 static char ident[] = "@@(#)$Id: show.c,v 1.12 1992/12/15 00:20:22 jromine Exp jromine $";
604 d335 1
605 a335 2
606     int     chlen,
607             result,
608 d350 1
609 a350 1
610     chlen = strlen (chset);
611 d425 1
612 a425 3
613                             dp++;
614                             if (strlen (dp) >= chlen + 1
615                                     && *(bp = dp + chlen) == '"')
616 d429 9
617 a437 4
618                             if (strlen (dp) >= chlen
619                                     && isspace (*(bp = dp + chlen)))
620                                 *bp = NULL;
621                         result = !uleq (dp, chset);
622 @
623
624
625 1.12
626 log
627 @endif sugar
628 @
629 text
630 @d3 1
631 a3 1
632 static char ident[] = "@@(#)$Id: show.c,v 1.11 1992/11/24 18:26:39 jromine Exp jromine $";
633 d335 2
634 a336 1
635     int     result,
636 d340 2
637 a341 1
638     char   *cp,
639 d349 3
640 d427 2
641 a428 2
642                             if (strlen (dp) >= sizeof "us-ascii\""
643                                     && *(bp = dp + sizeof "us-ascii" - 1)=='"')
644 d432 2
645 a433 3
646                             if (strlen (dp) >= sizeof "us-ascii"
647                                     && isspace (*(bp =
648                                                 dp + sizeof "us-ascii" - 1)))
649 d435 1
650 a435 1
651                         result = !uleq (dp, "us-ascii");
652 d464 3
653 a466 1
654                     result = !uleq (bp, "7bit");
655 @
656
657
658 1.11
659 log
660 @add decl
661 @
662 text
663 @d3 2
664 a4 2
665 static char ident[] = "@@(#)$Id: show.c,v 1.10 1992/11/04 01:02:58 jromine Exp jromine $";
666 #endif  lint
667 d210 1
668 a210 1
669 #endif  WHATNOW
670 d478 1
671 a478 1
672 #endif MIME
673 @
674
675
676 1.10
677 log
678 @LOCALE
679 putenv
680 @
681 text
682 @d3 1
683 a3 1
684 static char ident[] = "@@(#)$Id: show.c,v 1.9 1992/10/16 22:41:36 jromine Exp jromine $";
685 d49 3
686 @
687
688
689 1.9
690 log
691 @MIME changes
692 @
693 text
694 @d3 1
695 a3 1
696 static char ident[] = "@@(#)$Id: show.c,v 1.8 1992/05/19 21:04:45 jromine Exp jromine $";
697 d9 3
698 d84 3
699 d282 1
700 a282 1
701             (void) putenv ("mhfolder", folder);
702 @
703
704
705 1.8
706 log
707 @AIX
708 @
709 text
710 @d3 1
711 a3 1
712 static char ident[] = "@@(#)$Id: show.c,v 1.7 1992/03/03 17:13:54 jromine Exp jromine $";
713 d247 5
714 a251 1
715     if (!nshow && (cp = m_find ("mhnproc")) && !getenv ("NOMHNPROC"))
716 d270 2
717 a271 1
718
719 d319 1
720 d326 6
721 a331 2
722     int     state;
723     char    buf[BUFSIZ],
724 d337 1
725 d344 2
726 a345 6
727                     int     passno,
728                             result;
729                     register char   *bp,
730                                     *dp;
731                     char     c,
732                             *cp;
733 d381 1
734 a381 1
735                             break;                          
736 d393 2
737 a394 2
738                     c = *dp, *dp = '\0';
739                     if (*bp == '\0')
740 d396 28
741 a423 2
742                     if (passno > 1)
743                         result = !uleq (bp, "plain");
744 d434 18
745 d453 6
746 a458 2
747                     (void) fclose (fp);
748                     return result;
749 d469 1
750 @
751
752
753 1.7
754 log
755 @fixes from mtr
756 @
757 text
758 @d3 1
759 a3 1
760 static char ident[] = "@@(#)$Id: show.c,v 1.6 1992/02/01 00:34:45 jromine Exp jromine $";
761 d356 1
762 a356 1
763                                 case NULL:
764 d361 1
765 a361 1
766                                     if (*bp++ == NULL)
767 d386 2
768 a387 2
769                     c = *dp, *dp = NULL;
770                     if (*bp == NULL)
771 @
772
773
774 1.6
775 log
776 @typo
777 @
778 text
779 @d3 1
780 a3 1
781 static char ident[] = "@@(#)$Id: show.c,v 1.5 1992/01/31 22:27:23 jromine Exp jromine $";
782 d7 1
783 @
784
785
786 1.5
787 log
788 @kerberos
789 @
790 text
791 @d3 1
792 a3 1
793 static char ident[] = "@@(#)$Id: show.c,v 1.4 1992/01/31 16:35:17 jromine Exp jromine $";
794 d291 1
795 @
796
797
798 1.4
799 log
800 @Multimedia MH
801 @
802 text
803 @d3 1
804 a3 1
805 static char ident[] = "@@(#)$Id: show.c,v 1.3 90/12/19 08:48:39 mh Exp $";
806 d42 1
807 a42 1
808     NULL, NULL
809 @
810
811
812 1.3
813 log
814 @show -draft bug fix
815 jlr
816 @
817 text
818 @d3 1
819 a3 1
820 static char ident[] = "@@(#)$Id: show.c,v 1.2 90/04/05 15:03:16 sources Exp Locker: mh $";
821 d186 1
822 a186 1
823         if (msgp > 1)
824 d195 1
825 a195 1
826     if (!msgp && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) {
827 d246 20
828 d269 1
829 a269 1
830         if (folder)
831 d308 103
832 @
833
834
835 1.2
836 log
837 @add ID
838 @
839 text
840 @d3 1
841 a3 1
842 static char ident[] = "@@(#)$Id:$";
843 d249 2
844 a250 1
845         (void) putenv ("mhfolder", folder);
846 @
847
848
849 1.1
850 log
851 @Initial revision
852 @
853 text
854 @d2 3
855 @