]> diplodocus.org Git - nmh/blobdiff - uip/mhshowsbr.c
Remove msh(1).
[nmh] / uip / mhshowsbr.c
index 72ef158403b6760e8a54c97e6438818229cc974d..45c73cbe676a1d61b2170957462292540a837f90 100644 (file)
@@ -62,7 +62,7 @@ static int show_external (CT, int, int, int, int, struct format *);
 static int parse_display_string (CT, char *, int *, int *, char *, char *,
                                 size_t, int multipart);
 static int convert_content_charset (CT, char **);
-static struct format *compile_marker(char *, char *);
+static struct format *compile_marker(char *);
 static void output_marker (CT, struct format *);
 static void free_markercomps (void);
 static int pidcheck(int);
@@ -92,8 +92,8 @@ static struct param_comp_list *dispo_pc_list = NULL;
  */
 
 void
-show_all_messages (CT *cts, int concat, int textonly, int inlineonly,
-                  char *markerform, char *markerformat)
+show_all_messages (CT *cts, int concatsw, int textonly, int inlineonly,
+                  char *markerform)
 {
     CT ct, *ctp;
     struct format *fmt;
@@ -108,7 +108,7 @@ show_all_messages (CT *cts, int concat, int textonly, int inlineonly,
     /*
      * Compile the content marker format line
      */
-    fmt = compile_marker(markerform, markerformat);
+    fmt = compile_marker(markerform);
 
     /*
      * If form is "mhl.null", suppress display of header.
@@ -121,7 +121,8 @@ show_all_messages (CT *cts, int concat, int textonly, int inlineonly,
 
        /* if top-level type is ok, then display message */
        if (type_ok (ct, 1))
-           show_single_message (ct, formsw, concat, textonly, inlineonly, fmt);
+           show_single_message (ct, formsw, concatsw, textonly, inlineonly,
+                                fmt);
     }
 
     free_markercomps();
@@ -134,7 +135,7 @@ show_all_messages (CT *cts, int concat, int textonly, int inlineonly,
  */
 
 static void
-show_single_message (CT ct, char *form, int concat, int textonly,
+show_single_message (CT ct, char *form, int concatsw, int textonly,
                     int inlineonly, struct format *fmt)
 {
     sigset_t set, oset;
@@ -150,10 +151,10 @@ show_single_message (CT ct, char *form, int concat, int textonly,
      * the message headers.
      */
     if (form)
-       DisplayMsgHeader(ct, form, concat);
+       DisplayMsgHeader(ct, form, concatsw);
 
     /* Show the body of the message */
-    show_switch (ct, 0, concat, textonly, inlineonly, fmt);
+    show_switch (ct, 0, concatsw, textonly, inlineonly, fmt);
 
     if (ct->c_fp) {
        fclose (ct->c_fp);
@@ -170,7 +171,7 @@ show_single_message (CT ct, char *form, int concat, int textonly,
     sigaddset (&set, SIGTERM);
     sigprocmask (SIG_BLOCK, &set, &oset);
 
-    while (!concat && wait (&status) != NOTOK) {
+    while (!concatsw && wait (&status) != NOTOK) {
        pidcheck (status);
        continue;
     }
@@ -187,7 +188,7 @@ show_single_message (CT ct, char *form, int concat, int textonly,
  */
 
 static void
-DisplayMsgHeader (CT ct, char *form, int concat)
+DisplayMsgHeader (CT ct, char *form, int concatsw)
 {
     pid_t child_id;
     int i, vecp;
@@ -204,7 +205,7 @@ DisplayMsgHeader (CT ct, char *form, int concat)
      * If we've specified -(no)moreproc,
      * then just pass that along.
      */
-    if (nomore || concat) {
+    if (nomore || concatsw) {
        vec[vecp++] = getcpy("-nomoreproc");
     } else if (progsw) {
        vec[vecp++] = getcpy("-moreproc");
@@ -244,12 +245,12 @@ DisplayMsgHeader (CT ct, char *form, int concat)
  */
 
 static int
-show_switch (CT ct, int alternate, int concat, int textonly, int inlineonly,
+show_switch (CT ct, int alternate, int concatsw, int textonly, int inlineonly,
             struct format *fmt)
 {
     switch (ct->c_type) {
        case CT_MULTIPART:
-           return show_multi (ct, alternate, concat, textonly,
+           return show_multi (ct, alternate, concatsw, textonly,
                               inlineonly, fmt);
 
        case CT_MESSAGE:
@@ -258,7 +259,7 @@ show_switch (CT ct, int alternate, int concat, int textonly, int inlineonly,
                    return show_partial (ct, alternate);
 
                case MESSAGE_EXTERNAL:
-                   return show_external (ct, alternate, concat, textonly,
+                   return show_external (ct, alternate, concatsw, textonly,
                                          inlineonly, fmt);
 
                case MESSAGE_RFC822:
@@ -267,7 +268,7 @@ show_switch (CT ct, int alternate, int concat, int textonly, int inlineonly,
            }
 
        case CT_TEXT:
-           return show_text (ct, alternate, concat);
+           return show_text (ct, alternate, concatsw);
 
        case CT_AUDIO:
        case CT_IMAGE:
@@ -299,7 +300,7 @@ show_content (CT ct, int alternate, int textonly, int inlineonly,
      * the content-type.
      */
 
-    if (textonly || (inlineonly && is_inline(ct))) {
+    if (textonly || (inlineonly && !is_inline(ct))) {
        output_marker(ct, fmt);
        return OK;
     }
@@ -357,12 +358,12 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked)
            some code rearrangement.  And to make this really ugly,
            only do it in mhshow, not mhfixmsg, mhn, or mhstore. */
         if (convert_content_charset (ct, &file) == OK) {
-            close_encoding (ct);
+            (*ct->c_ceclosefnx) (ct);
             if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
                 return NOTOK;
         } else {
-            admonish (NULL, "unable to convert character set%s to %s",
-                      ct->c_partno  ?  "of part "  :  "",
+            admonish (NULL, "unable to convert character set%s%s to %s",
+                      ct->c_partno  ?  " of part "  :  "",
                       ct->c_partno  ?  ct->c_partno  :  "",
                       content_charset (ct));
         }
@@ -465,7 +466,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer,
            close (fd);
            execvp (file, vec);
            fprintf (stderr, "unable to exec ");
-           perror ("/bin/sh");
+           perror (buffer);
            _exit (-1);
            /* NOTREACHED */
 
@@ -486,7 +487,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer,
  */
 
 static int
-show_text (CT ct, int alternate, int concat)
+show_text (CT ct, int alternate, int concatsw)
 {
     char *cp, buffer[BUFSIZ];
     CI ci = &ct->c_ctinfo;
@@ -507,9 +508,12 @@ show_text (CT ct, int alternate, int concat)
      * if it is not a text part of a multipart/alternative
      */
     if (!alternate || ct->c_subtype == TEXT_PLAIN) {
-       if (concat)
-           snprintf(buffer, sizeof(buffer), "%%l");
-       else
+       if (concatsw) {
+           if (ct->c_termproc)
+               snprintf(buffer, sizeof(buffer), "%%lcat");
+           else
+               snprintf(buffer, sizeof(buffer), "%%l");
+       } else
            snprintf (buffer, sizeof(buffer), "%%l%s %%F", progsw ? progsw :
                      moreproc && *moreproc ? moreproc : DEFAULT_PAGER);
        cp = (ct->c_showproc = add (buffer, NULL));
@@ -525,7 +529,7 @@ show_text (CT ct, int alternate, int concat)
  */
 
 static int
-show_multi (CT ct, int alternate, int concat, int textonly, int inlineonly,
+show_multi (CT ct, int alternate, int concatsw, int textonly, int inlineonly,
            struct format *fmt)
 {
     char *cp, buffer[BUFSIZ];
@@ -550,7 +554,7 @@ show_multi (CT ct, int alternate, int concat, int textonly, int inlineonly,
      * unknown types are displayable, since they're treated as mixed
      * per RFC 2046.
      */
-    return show_multi_internal (ct, alternate, concat, textonly,
+    return show_multi_internal (ct, alternate, concatsw, textonly,
                                inlineonly, fmt);
 }
 
@@ -561,7 +565,7 @@ show_multi (CT ct, int alternate, int concat, int textonly, int inlineonly,
  */
 
 static int
-show_multi_internal (CT ct, int alternate, int concat, int textonly,
+show_multi_internal (CT ct, int alternate, int concatsw, int textonly,
                     int inlineonly, struct format *fmt)
 {
     int        alternating, nowalternate, result;
@@ -590,7 +594,7 @@ show_multi_internal (CT ct, int alternate, int concat, int textonly,
        if (part_ok (p, 1) && type_ok (p, 1)) {
            int inneresult;
 
-           inneresult = show_switch (p, nowalternate, concat, textonly,
+           inneresult = show_switch (p, nowalternate, concatsw, textonly,
                                      inlineonly, fmt);
            switch (inneresult) {
                case NOTOK:
@@ -703,7 +707,7 @@ show_message_rfc822 (CT ct, int alternate)
 
     /* default method for message/rfc822 */
     if (ct->c_subtype == MESSAGE_RFC822) {
-       cp = (ct->c_showproc = add ("%pecho -file %F", NULL));
+       cp = (ct->c_showproc = add ("%pshow -file %F", NULL));
        return show_content_aux (ct, alternate, cp, NULL);
     }
 
@@ -737,7 +741,7 @@ show_partial (CT ct, int alternate)
  */
 
 static int
-show_external (CT ct, int alternate, int concat, int textonly, int inlineonly,
+show_external (CT ct, int alternate, int concatsw, int textonly, int inlineonly,
               struct format *fmt)
 {
     struct exbody *e = (struct exbody *) ct->c_ctparams;
@@ -746,7 +750,7 @@ show_external (CT ct, int alternate, int concat, int textonly, int inlineonly,
     if (!type_ok (p, 0))
        return OK;
 
-    return show_switch (p, alternate, concat, textonly, inlineonly, fmt);
+    return show_switch (p, alternate, concatsw, textonly, inlineonly, fmt);
 }
 
 
@@ -1042,6 +1046,8 @@ convert_charset (CT ct, char *dest_charset, int *message_mods) {
         size_t end;
         int opened_input_file = 0;
         char src_buffer[BUFSIZ];
+       size_t dest_buffer_size = BUFSIZ;
+       char *dest_buffer = mh_xmalloc(dest_buffer_size);
         HF hf;
         char *tempfile;
 
@@ -1088,16 +1094,30 @@ convert_charset (CT ct, char *dest_charset, int *message_mods) {
             while ((inbytes = fread (src_buffer, 1,
                                      min (bytes_to_read, sizeof src_buffer),
                                      *fp)) > 0) {
-                char dest_buffer[BUFSIZ];
                 ICONV_CONST char *ib = src_buffer;
                 char *ob = dest_buffer;
-                size_t outbytes = sizeof dest_buffer;
+                size_t outbytes = dest_buffer_size;
                 size_t outbytes_before = outbytes;
 
                 if (end > 0) bytes_to_read -= inbytes;
 
+iconv_start:
                 if (iconv (conv_desc, &ib, &inbytes, &ob, &outbytes) ==
                     (size_t) -1) {
+                   if (errno == E2BIG) {
+                       /*
+                        * Bump up the buffer by at least a factor of 2
+                        * over what we need.
+                        */
+                       size_t bumpup = inbytes * 2, ob_off = ob - dest_buffer;
+                       dest_buffer_size += bumpup;
+                       dest_buffer = mh_xrealloc(dest_buffer,
+                                                 dest_buffer_size);
+                       ob = dest_buffer + ob_off;
+                       outbytes += bumpup;
+                       outbytes_before += bumpup;
+                       goto iconv_start;
+                   }
                     status = NOTOK;
                     break;
                 } else {
@@ -1160,11 +1180,13 @@ convert_charset (CT ct, char *dest_charset, int *message_mods) {
         } else {
             (void) m_unlink (dest);
         }
+       free(dest_buffer);
 #else  /* ! HAVE_ICONV */
         NMH_UNUSED (message_mods);
 
         advise (NULL, "Can't convert %s to %s without iconv", src_charset,
                 dest_charset);
+        errno = ENOSYS;
         status = NOTOK;
 #endif /* ! HAVE_ICONV */
     }
@@ -1207,7 +1229,7 @@ convert_content_charset (CT ct, char **file) {
                       "%|%{ctype-name}%> ]"
 
 static struct format *
-compile_marker(char *markerform, char *markerformat)
+compile_marker(char *markerform)
 {
     struct format *fmt;
     char *fmtstring;
@@ -1215,7 +1237,7 @@ compile_marker(char *markerform, char *markerformat)
     unsigned int bucket;
     struct param_comp_list *pc_entry;
 
-    fmtstring = new_fs(markerform, markerformat, DEFAULT_MARKER);
+    fmtstring = new_fs(markerform, NULL, DEFAULT_MARKER);
 
     (void) fmt_compile(fmtstring, &fmt, 1);
     free(fmtstring);