]> diplodocus.org Git - nmh/commitdiff
Removed redundant quoting of %f and %F in display strings. Now,
authorDavid Levine <levinedl@acm.org>
Wed, 19 Feb 2014 03:16:06 +0000 (21:16 -0600)
committerDavid Levine <levinedl@acm.org>
Wed, 19 Feb 2014 03:16:06 +0000 (21:16 -0600)
the code checks to see if those escapes are quoted before quoting
them.  Removed quoting of them in mhn.defaults.sh because it isn't
(and wasn't) necessary.

etc/mhn.defaults.sh
man/mh-profile.man
man/mhshow.man
uip/mhshowsbr.c

index cbe7215..b7cecd5 100755 (executable)
@@ -36,7 +36,7 @@ elif [ ! -z "`$SEARCHPROG $SEARCHPATH lynx`" ]; then
 expand | sed -e 's/^   //' -e 's/  *$//'" >> $TMP
 elif [ ! -z "`$SEARCHPROG $SEARCHPATH elinks`" ]; then
   echo "mhfixmsg-format-text/html: elinks -dump -force-html -no-numbering \
 expand | sed -e 's/^   //' -e 's/  *$//'" >> $TMP
 elif [ ! -z "`$SEARCHPROG $SEARCHPATH elinks`" ]; then
   echo "mhfixmsg-format-text/html: elinks -dump -force-html -no-numbering \
--eval 'set document.browse.margin_width = 0' '%F'" >> $TMP
+-eval 'set document.browse.margin_width = 0' %F" >> $TMP
 fi
 
 
 fi
 
 
@@ -61,7 +61,7 @@ fi
 
 PGM="`$SEARCHPROG $SEARCHPATH xv`"
 if [ ! -z "$PGM" ]; then
 
 PGM="`$SEARCHPROG $SEARCHPATH xv`"
 if [ ! -z "$PGM" ]; then
-    echo "mhshow-show-image: %p$PGM -geometry =-0+0 '%f'" >> $TMP
+    echo "mhshow-show-image: %p$PGM -geometry =-0+0 %f" >> $TMP
 elif [ ! -z $"NETPBM" -a ! -z "$XWUD" ]; then
     echo "mhshow-show-image/gif: %p${NETPBMDIR}giftopnm | ${NETPBMDIR}ppmtopgm | ${NETPBMDIR}pgmtopbm | ${NETPBMDIR}pnmtoxwd | $XWUD -geometry =-0+0" >> $TMP
     echo "mhshow-show-image/x-pnm: %p${NETPBMDIR}pnmtoxwd | $XWUD -geometry =-0+0" >> $TMP
 elif [ ! -z $"NETPBM" -a ! -z "$XWUD" ]; then
     echo "mhshow-show-image/gif: %p${NETPBMDIR}giftopnm | ${NETPBMDIR}ppmtopgm | ${NETPBMDIR}pgmtopbm | ${NETPBMDIR}pnmtoxwd | $XWUD -geometry =-0+0" >> $TMP
     echo "mhshow-show-image/x-pnm: %p${NETPBMDIR}pnmtoxwd | $XWUD -geometry =-0+0" >> $TMP
@@ -79,7 +79,7 @@ if [ -f "/dev/audioIU" ]; then
     PGM="`$SEARCHPROG $SEARCHPATH recorder`"
     if [ ! -z "$PGM" ]; then
        echo "mhstore-store-audio/basic: %m%P.au" >> $TMP
     PGM="`$SEARCHPROG $SEARCHPATH recorder`"
     if [ ! -z "$PGM" ]; then
        echo "mhstore-store-audio/basic: %m%P.au" >> $TMP
-        echo "mhbuild-compose-audio/basic: ${AUDIODIR}recorder '%f' -au -pause > /dev/tty" >> $TMP
+        echo "mhbuild-compose-audio/basic: ${AUDIODIR}recorder %f -au -pause > /dev/tty" >> $TMP
         echo "mhshow-show-audio/basic: %p${AUDIODIR}splayer -au" >> $TMP
     fi
 elif [ -f "/dev/audio" ]; then
         echo "mhshow-show-audio/basic: %p${AUDIODIR}splayer -au" >> $TMP
     fi
 elif [ -f "/dev/audio" ]; then
@@ -90,7 +90,7 @@ elif [ -f "/dev/audio" ]; then
         echo "mhstore-store-audio/x-next: %m%P.au" >> $TMP
        AUDIOTOOL="`$SEARCHPROG $SEARCHPATH audiotool`"
        if [ ! -z "$AUDIOTOOL" ]; then
         echo "mhstore-store-audio/x-next: %m%P.au" >> $TMP
        AUDIOTOOL="`$SEARCHPROG $SEARCHPATH audiotool`"
        if [ ! -z "$AUDIOTOOL" ]; then
-           echo "mhbuild-compose-audio/basic: $AUDIOTOOL '%f' && ${AUDIODIR}raw2audio -F < '%f'" >> $TMP
+           echo "mhbuild-compose-audio/basic: $AUDIOTOOL %f && ${AUDIODIR}raw2audio -F < %f" >> $TMP
        else
            echo "mhbuild-compose-audio/basic: trap \"exit 0\" 2 && ${AUDIODIR}record | ${AUDIODIR}raw2audio -F" >> $TMP
        fi
        else
            echo "mhbuild-compose-audio/basic: trap \"exit 0\" 2 && ${AUDIODIR}record | ${AUDIODIR}raw2audio -F" >> $TMP
        fi
@@ -100,14 +100,14 @@ elif [ -f "/dev/audio" ]; then
        if [ ! -z "$PGM" ]; then
            DIR="`echo $PGM | awk -F/ '{ for(i=2;i<NF;i++)printf "/%s", $i;}'`"/
            if [ ! -z "$AUDIOTOOL" ]; then
        if [ ! -z "$PGM" ]; then
            DIR="`echo $PGM | awk -F/ '{ for(i=2;i<NF;i++)printf "/%s", $i;}'`"/
            if [ ! -z "$AUDIOTOOL" ]; then
-               echo "mhbuild-compose-audio/x-next: $AUDIOTOOL '%f' && ${DIR}adpcm_enc < '%f'" >> $TMP
+               echo "mhbuild-compose-audio/x-next: $AUDIOTOOL %f && ${DIR}adpcm_enc < %f" >> $TMP
            else
                echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record | ${DIR}adpcm_enc" >> $TMP
            fi
            echo "mhshow-show-audio/x-next: %p${DIR}adpcm_dec | ${AUDIODIR}play" >> $TMP
        else
            if [ ! -z "$AUDIOTOOL" ]; then
            else
                echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record | ${DIR}adpcm_enc" >> $TMP
            fi
            echo "mhshow-show-audio/x-next: %p${DIR}adpcm_dec | ${AUDIODIR}play" >> $TMP
        else
            if [ ! -z "$AUDIOTOOL" ]; then
-               echo "mhbuild-compose-audio/x-next: $AUDIOTOOL '%f'" >> $TMP
+               echo "mhbuild-compose-audio/x-next: $AUDIOTOOL %f" >> $TMP
            else
                echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record" >> $TMP
            fi
            else
                echo "mhbuild-compose-audio/x-next: ${AUDIODIR}record" >> $TMP
            fi
@@ -121,27 +121,27 @@ fi
 
 PGM="`$SEARCHPROG $SEARCHPATH mpeg_play`"
 if [ ! -z "$PGM" ]; then
 
 PGM="`$SEARCHPROG $SEARCHPATH mpeg_play`"
 if [ ! -z "$PGM" ]; then
-       echo "mhshow-show-video/mpeg: %p$PGM '%f'" >> $TMP
+       echo "mhshow-show-video/mpeg: %p$PGM %f" >> $TMP
 fi
 
 PGM="`$SEARCHPROG $SEARCHPATH okular`"
 if [ ! -z "$PGM" ]; then
 fi
 
 PGM="`$SEARCHPROG $SEARCHPATH okular`"
 if [ ! -z "$PGM" ]; then
-       echo "mhshow-show-application/PostScript: %pokular '%F'" >> $TMP
+       echo "mhshow-show-application/PostScript: %pokular %F" >> $TMP
 else
     PGM="`$SEARCHPROG $SEARCHPATH evince`"
     if [ ! -z "$PGM" ]; then
 else
     PGM="`$SEARCHPROG $SEARCHPATH evince`"
     if [ ! -z "$PGM" ]; then
-       echo "mhshow-show-application/PostScript: %pevince '%F'" >> $TMP
+       echo "mhshow-show-application/PostScript: %pevince %F" >> $TMP
     else
        PGM="`$SEARCHPROG $SEARCHPATH gv`"
        if [ ! -z "$PGM" ]; then
     else
        PGM="`$SEARCHPROG $SEARCHPATH gv`"
        if [ ! -z "$PGM" ]; then
-           echo "mhshow-show-application/PostScript: %pgv '%F'" >> $TMP
+           echo "mhshow-show-application/PostScript: %pgv %F" >> $TMP
        fi
     fi
 fi
 
 PGM="`$SEARCHPROG $SEARCHPATH ivs_replay`"
 if [ ! -z "$PGM" ]; then
        fi
     fi
 fi
 
 PGM="`$SEARCHPROG $SEARCHPATH ivs_replay`"
 if [ ! -z "$PGM" ]; then
-       echo "mhshow-show-application/x-ivs: %p$PGM -o '%F'" >> $TMP
+       echo "mhshow-show-application/x-ivs: %p$PGM -o %F" >> $TMP
 fi
 
 # The application/vnd.openxmlformats-officedocument.wordprocessingml.document
 fi
 
 # The application/vnd.openxmlformats-officedocument.wordprocessingml.document
@@ -251,18 +251,18 @@ fi
 
 PGM="`$SEARCHPROG $SEARCHPATH richtext`"
 if [ ! -z "$PGM" ]; then
 
 PGM="`$SEARCHPROG $SEARCHPATH richtext`"
 if [ ! -z "$PGM" ]; then
-       echo "mhshow-show-text/richtext: %p$PGM -p '%F'" >> $TMP
+       echo "mhshow-show-text/richtext: %p$PGM -p %F" >> $TMP
 else
     PGM="`$SEARCHPROG $SEARCHPATH rt2raw`"
     if [ ! -z "$PGM" ]; then
 else
     PGM="`$SEARCHPROG $SEARCHPATH rt2raw`"
     if [ ! -z "$PGM" ]; then
-       echo "mhshow-show-text/richtext: %p$PGM < '%f' | fmt -78 | more" >> $TMP
+       echo "mhshow-show-text/richtext: %p$PGM < %f | fmt -78 | more" >> $TMP
     fi
 fi
 
 # staroffice to read .doc files
 PGM="`$SEARCHPROG $SEARCHPATH soffice`"
 if [ ! -z "$PGM" ]; then
     fi
 fi
 
 # staroffice to read .doc files
 PGM="`$SEARCHPROG $SEARCHPATH soffice`"
 if [ ! -z "$PGM" ]; then
-       echo "mhshow-show-application/msword: %psoffice '%F'" >> $TMP
+       echo "mhshow-show-application/msword: %psoffice %F" >> $TMP
        echo "mhshow-suffix-application/msword: .doc" >> $TMP
 fi
 
        echo "mhshow-suffix-application/msword: .doc" >> $TMP
 fi
 
@@ -279,7 +279,7 @@ if [ "$DISPLAY" = "unix:0.0" -a ! -z "$PGM" ]; then
 else
     PGM="`$SEARCHPROG $SEARCHPATH gs`"
     if [ ! -z "$PGM" ]; then
 else
     PGM="`$SEARCHPROG $SEARCHPATH gs`"
     if [ ! -z "$PGM" ]; then
-       echo "mhshow-show-application/PostScript: %p$PGM -- '%F'" >> $TMP
+       echo "mhshow-show-application/PostScript: %p$PGM -- %F" >> $TMP
        echo "mhshow-suffix-application/PostScript: .ps" >> $TMP
     fi
 fi
        echo "mhshow-suffix-application/PostScript: .ps" >> $TMP
     fi
 fi
@@ -288,5 +288,5 @@ fi
 
 PGM="`$SEARCHPROG $SEARCHPATH ivs_record`"
 if [ ! -z "$PGM" ]; then
 
 PGM="`$SEARCHPROG $SEARCHPATH ivs_record`"
 if [ ! -z "$PGM" ]; then
-       echo "mhbuild-compose-application/x-ivs: $PGM -u localhost '%F'" >> $TMP
+       echo "mhbuild-compose-application/x-ivs: $PGM -u localhost %F" >> $TMP
 fi
 fi
index 901d69f..f991860 100644 (file)
@@ -459,7 +459,7 @@ can be used to select alternate programs if the
 user wishes.  The default values are given in the examples.
 .PP
 If the profile element contains spaces, the element is split at spaces
 user wishes.  The default values are given in the examples.
 .PP
 If the profile element contains spaces, the element is split at spaces
-into tokens and each token is given as a seperate argument to the
+into tokens and each token is given as a separate argument to the
 .IR execvp (2)
 system call.  If the element contains shell metacharacters then the entire
 element is executed using
 .IR execvp (2)
 system call.  If the element contains shell metacharacters then the entire
 element is executed using
index 2237bdd..d25e6eb 100644 (file)
@@ -1,4 +1,4 @@
-.TH MHSHOW %manext1% "February 16, 2014" "%nmhversion%"
+.TH MHSHOW %manext1% "February 18, 2014" "%nmhversion%"
 .\"
 .\" %nmhwarning%
 .\"
 .\"
 .\" %nmhwarning%
 .\"
@@ -258,6 +258,20 @@ control-\\) will tell
 .B mhshow
 to wrap things up immediately.
 .PP
 .B mhshow
 to wrap things up immediately.
 .PP
+The {charset} escape is typically used in a command line argument that
+should only be present if it has a non-null value.  Shell parameter
+expansion can construct the argument only when it is non-null, e.g.,
+.PP
+.RS 5
+.nf
+mhshow-show-text/html: charset="%{charset}";
+  w3m ${charset:+-I $charset} -T text/html %F
+.fi
+.RE
+.PP
+That example also shows the use of indentation to signify continuation:
+the two text lines combine to form a single entry.
+.PP
 Note that if the content being displayed is multipart, but not one of
 the subtypes listed above, then the f- and F-escapes expand to multiple
 filenames, one for each subordinate content.  Further, stdin is not
 Note that if the content being displayed is multipart, but not one of
 the subtypes listed above, then the f- and F-escapes expand to multiple
 filenames, one for each subordinate content.  Further, stdin is not
@@ -269,8 +283,8 @@ behaves as if these profile entries were supplied and supported:
 .PP
 .RS 5
 .nf
 .PP
 .RS 5
 .nf
-mhshow-show-text/plain: %pmoreproc '%F'
-mhshow-show-message/rfc822: %pshow -file '%F'
+mhshow-show-text/plain: %pmoreproc %F
+mhshow-show-message/rfc822: %pshow -file %F
 .fi
 .RE
 .PP
 .fi
 .RE
 .PP
@@ -300,14 +314,13 @@ Example entries might be:
 .RS 5
 .nf
 mhshow-show-audio/basic: raw2audio 2>/dev/null | play
 .RS 5
 .nf
 mhshow-show-audio/basic: raw2audio 2>/dev/null | play
-mhshow-show-image: xv '%f'
+mhshow-show-image: xv %f
 mhshow-show-application/PostScript: lpr -Pps
 .fi
 .RE
 .PP
 mhshow-show-application/PostScript: lpr -Pps
 .fi
 .RE
 .PP
-Note that when using the f- or F-escape, it's a good idea to use
-single-quotes around the escape.  This prevents misinterpretation by
-the shell of any funny characters that might be present in the filename.
+If an f- or F-escape is not quoted with single quotes, double quotes,
+or backticks, its expansion will be wrapped with single quotes.
 .PP
 Finally,
 .B mhshow
 .PP
 Finally,
 .B mhshow
index d87cd93..601830c 100644 (file)
@@ -842,29 +842,46 @@ parse_display_string (CT ct, char *cp, int *xstdin, int *xlist, int *xpause,
                    for (part = m->mp_parts; part; part = part->mp_next) {
                        p = part->mp_part;
 
                    for (part = m->mp_parts; part; part = part->mp_next) {
                        p = part->mp_part;
 
-                       snprintf (bp, buflen, "%s'%s'", s, p->c_storage);
+                       /* Don't quote filename if it's already quoted.  Assume
+                          it's quoted if previous character was a quote. */
+                       if (p->c_storage  &&  (*(p->c_storage-1) == '\'' ||
+                                              *(p->c_storage-1) == '"' ||
+                                              *(p->c_storage-1) == '`')) {
+                           snprintf (bp, buflen, "%s%s", s, p->c_storage);
+                       } else {
+                           snprintf (bp, buflen, "%s'%s'", s, p->c_storage);
+                       }
+
                        len = strlen (bp);
                        bp += len;
                        buflen -= len;
                        s = " ";
                    }
                        len = strlen (bp);
                        bp += len;
                        buflen -= len;
                        s = " ";
                    }
-                   /* set our starting pointer back to bp, to avoid
-                    * requoting the filenames we just added
-                    */
-                   pp = bp;
                } else {
                    /* insert filename containing content */
                } else {
                    /* insert filename containing content */
-                   snprintf (bp, buflen, "'%s'", file);
+                   if (bp > buffer  &&
+                        (*(bp-1) == '\'' || *(bp-1) == '"' || *(bp-1) == '`')) {
+                       /* Don't quote filename if it's already quoted.  Assume
+                          it's quoted if previous character was a quote. */
+                       snprintf (bp, buflen, "%s", file);
+                   } else {
+                       snprintf (bp, buflen, "'%s'", file);
+                   }
+
                    /* since we've quoted the file argument, set things up
                     * to look past it, to avoid problems with the quoting
                     * logic below.  (I know, I should figure out what's
                     * broken with the quoting logic, but..)
                     */
                    len = strlen(bp);
                    /* since we've quoted the file argument, set things up
                     * to look past it, to avoid problems with the quoting
                     * logic below.  (I know, I should figure out what's
                     * broken with the quoting logic, but..)
                     */
                    len = strlen(bp);
-                   buflen -= len;
                    bp += len;
                    bp += len;
-                   pp = bp;
+                   buflen -= len;
                }
                }
+
+               /* set our starting pointer back to bp, to avoid
+                * requoting the filenames we just added
+                */
+                pp = bp;
                break;
 
            case 'p':
                break;
 
            case 'p':
@@ -906,8 +923,8 @@ parse_display_string (CT ct, char *cp, int *xstdin, int *xlist, int *xpause,
                     * broken with the quoting logic, but..)
                     */
                    len = strlen(bp);
                     * broken with the quoting logic, but..)
                     */
                    len = strlen(bp);
-                   buflen -= len;
                    bp += len;
                    bp += len;
+                   buflen -= len;
                    pp = bp;
 
                    break;
                    pp = bp;
 
                    break;