groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 03/03: grap2graph: Parallelize changes with pic2graph.


From: G. Branden Robinson
Subject: [groff] 03/03: grap2graph: Parallelize changes with pic2graph.
Date: Tue, 1 May 2018 04:32:22 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 40b1fd9c694cdfe2a6d9545a669f0a62ea71430b
Author: G. Branden Robinson <address@hidden>
Date:   Sat Apr 28 03:54:02 2018 -0400

    grap2graph: Parallelize changes with pic2graph.
    
    contrib/grap2graph/grap2graph.sh:
    * Refactor temp directory handling.
    * Handle embedded whitespace in temp dir.
    * Adapt to old convert(1) programs.
    
    contrib/grap2graph/grap2graph.1.man:
    * Make editorial/style changes and minor corrections.
    
    Signed-off-by: G. Branden Robinson <address@hidden>
---
 ChangeLog                           |  20 ++++-
 NEWS                                |  14 +--
 contrib/grap2graph/grap2graph.1.man | 166 ++++++++++++++++++++++--------------
 contrib/grap2graph/grap2graph.sh    |  54 ++++++++----
 4 files changed, 166 insertions(+), 88 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 18edd8a..90b3436 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2018-04-28  G. Branden Robinson <address@hidden>
+
+       grap2graph: Parallelize changes with pic2graph.
+
+       contrib/grap2graph/grap2graph.sh:
+       * Refactor temp directory handling.
+       * Handle embedded whitespace in temp dir.
+       * Adapt to old convert(1) programs.
+
+       contrib/grap2graph/grap2graph.1.man:
+       * Make editorial/style changes and minor corrections.
+
 2018-04-26  G. Branden Robinson <address@hidden>
 
        eqn2graph: Remove -unsafe option.
@@ -18,11 +30,13 @@
        eqn2graph: Parallelize changes with pic2graph.
 
        contrib/eqn2graph/eqn2graph.sh:
-       contrib/eqn2graph/eqn2graph.1.man:
        * Refactor temp directory handling.
        * Handle embedded whitespace in temp dir.
        * Adapt to old convert(1) programs.
 
+       contrib/eqn2graph/eqn2graph.1.man:
+       * Make editorial/style changes and minor corrections.
+
 2018-04-25  G. Branden Robinson <address@hidden>
 
        pic2graph: Refactor temp directory handling.
@@ -76,6 +90,10 @@
 
 2018-04-23  G. Branden Robinson <address@hidden>
 
+       pic2graph(1): Make editorial/style changes and minor corrections.
+
+2018-04-23  G. Branden Robinson <address@hidden>
+
        pic2graph: Adapt to old convert(1) programs.
 
        * contrib/pic2graph/pic2graph.sh: Grep convert's -help output
diff --git a/NEWS b/NEWS
index d3c7fc2..9cd1750 100644
--- a/NEWS
+++ b/NEWS
@@ -53,13 +53,13 @@ o New 'configure' option --with-compatibility-wrappers to 
control how groff
   compatibility wrappers for vendor-provided non-GNU macro sets are
   installed (See: ./configure --help).
 
-o eqn2graph and pic2graph now attempt to adapt to very old installed
-  versions of the ImageMagick and GraphicsMagick programs "convert".  They
-  search the output of convert(1)'s "-help" option, and use "-trim" if that
-  string is found; otherwise, the old "-crop 0x0" method (which produces
-  incompatible results on versions that _do_ support "-trim") is used.  The
-  programs emit a warning to standard error if the search fails and the old
-  method is used.
+o eqn2graph, grap2graph, and pic2graph now attempt to adapt to very old
+  installed versions of the ImageMagick and GraphicsMagick programs
+  "convert".  They search the output of convert's "-help" option, and use
+  "-trim" if that string is found; otherwise, the old "-crop 0x0" method
+  (which produces incompatible results on versions that _do_ support
+  "-trim") is used.  The programs emit a warning to standard error if the
+  search fails and the old method is used.
 
 o eqn2graph no longer supports the "-unsafe" option.  It did nothing.
 
diff --git a/contrib/grap2graph/grap2graph.1.man 
b/contrib/grap2graph/grap2graph.1.man
index 3fec152..36475f6 100644
--- a/contrib/grap2graph/grap2graph.1.man
+++ b/contrib/grap2graph/grap2graph.1.man
@@ -1,8 +1,12 @@
 .TH GRAP2GRAPH @MAN1EXT@ "@MDATE@" "groff @VERSION@"
 .SH NAME
-grap2graph \- convert a grap diagram into a cropped bitmap image
+grap2graph \- convert a GRAP diagram into a cropped image
 .
 .
+.\" ====================================================================
+.\" Legalese
+.\" ====================================================================
+.\"
 .\" This documentation is released to the public domain.
 .
 .
@@ -10,54 +14,71 @@ grap2graph \- convert a grap diagram into a cropped bitmap 
image
 .SH SYNOPSIS
 .\" ====================================================================
 .
-.B grap2graph
-[
-.B \-unsafe
-]
-[
-.BI \-format\  fmt
-]
+.SY grap2graph
+.OP \-unsafe
+.OP \-format output-format
+.RI [ \%convert-arguments ]
+.YS
+.
+.SY grap2graph
+.B \-\-help
+.SY grap2graph
+.RB { \-v | \-\-version }
+.YS
 .
 .
 .\" ====================================================================
 .SH DESCRIPTION
 .\" ====================================================================
 .
-Reads a grap program as input; produces an image file (by default in
-Portable Network Graphics format) suitable for the Web as output.
-.
-For a description of the grap language, see
-.BR grap (1).
+.I grap2graph
+reads a
+.BR grap (1)
+program from the standard input and writes an image file,
+by default in Portable Network Graphics (PNG) format,
+to the standard output.
 .
 .
-.P
-Your graph specification should \fInot\fR be wrapped with the \&.G1 and
-\&.G2 macros that normally guard it within
+.PP
+The input
+.I GRAP
+code should
+.I not
+be wrapped with the
+.B \&.G1
+and
+.B \&.G2
+macros that normally guard it within
 .BR groff (@MAN1EXT@)
-macros.
+documents.
 .
 .
-.P
-The output image will be a black-on-white graphic clipped to the
-smallest possible bounding box that contains all the black pixels.
+.\" FIXME: How old?  This text hasn't been touched since 2008 at latest.
+.\" Older versions of
+.\" .I \%convert
+.\" will produce a black-on-white graphic; newer ones may produce a
+.\" black-on-transparent graphic.
 .
-By specifying command-line options to be passed to
-.BR convert (1)
-you can give it a border, set the background transparent, set the
-image's pixel density, or perform other useful transformations.
+.PP
+Arguments not recognized by
+.I grap2graph
+are passed to the ImageMagick or GraphicsMagick program
+.BR \%convert (1).
 .
 .
-.P
-This program uses
-.BR grap (1),
-.BR @address@hidden (@MAN1EXT@),
-.BR groff (@MAN1EXT@),
-and the ImageMagick
-.BR convert (1)
-program.
+By specifying these, you can give your image a border,
+.\" Transparent backgrounds are the default in 2018.
+.\" force the background transparent,
+set the image's pixel density,
+or perform other useful transformations.
+.
 .
-These programs must be installed on your system and accessible on your
-$PATH for \fBgrap2graph\fR to work.
+.PP
+The output image is clipped using
+.IR convert 's
+.B \-trim
+option to the smallest possible bounding box that contains all the black
+pixels.
 .
 .
 .\" ====================================================================
@@ -67,27 +88,41 @@ $PATH for \fBgrap2graph\fR to work.
 .TP
 .B \-unsafe
 Run
-.BR @address@hidden (@MAN1EXT@)
-and
-.BR groff (@MAN1EXT@)
-in the \[lq]unsafe\[rq] mode enabling the PIC macro
+.I groff
+in
+.I unsafe
+mode, enabling the
+.I PIC
+command
 .B sh
-to execute arbitrary commands.
+to execute arbitrary Unix shell commands.
+.
+The
+.I groff
+default is to forbid this.
 .
-The default is to forbid this.
 .
 .TP
-.BI \-format\  fmt
-Specify an output format; the default is PNG (Portable Network Graphics).
+.BI "\-format " output-format
+Write the image in
+.IR output-format ,
+which must be understood by
+.IR convert ;
+the default is PNG.
 .
-Any format that
-.BR convert (1)
-can emit is supported.
 .
+.TP
+.B \-\-help
+Display a brief usage message and exit.
 .
-.PP
-Command-line switches and arguments not listed above are passed to
-.BR convert (1).
+.
+.TP
+.B \-v
+.TQ
+.B \-\-version
+Display
+.IR grap2graph 's
+version string and exit.
 .
 .
 .\" ====================================================================
@@ -95,20 +130,19 @@ Command-line switches and arguments not listed above are 
passed to
 .\" ====================================================================
 .
 .TP
-.B GROFF_TMPDIR
-The directory in which temporary files will be created.
-.
-If this is not set
-.B grap2graph
-searches the environment variables
-.BR \%TMPDIR ,
-.BR TMP ,
-and
-.B TEMP
-(in that order).
+.B \%GROFF_TMPDIR
+.TQ
+.B \%TMPDIR
+.TQ
+.B \%TMP
+.TQ
+.B \%TEMP
+These environment variables are searched in the given order to determine
+the directory where temporary files will be created.
 .
-Otherwise, temporary files will be created in
-.BR /tmp .
+If none are set,
+.I /tmp
+is used.
 .
 .
 .\" ====================================================================
@@ -119,20 +153,22 @@ Otherwise, temporary files will be created in
 was written by
 .MT address@hidden:thyrsus.com
 Eric S.\& Raymond
-.ME .
+.ME ,
+based on a recipe for
+.BR pic2graph (@MAN1EXT@),
+by W.\& Richard Stevens.
 .
 .
-.na
 .\" ====================================================================
 .SH "SEE ALSO"
 .\" ====================================================================
 .
 .BR pic2graph (@MAN1EXT@),
 .BR eqn2graph (@MAN1EXT@),
+.BR grap (1),
 .BR @address@hidden (@MAN1EXT@),
 .BR groff (@MAN1EXT@),
-.BR gs (1),
-.BR convert (1).
+.BR convert (1)
 .
 .
 .\" Local Variables:
diff --git a/contrib/grap2graph/grap2graph.sh b/contrib/grap2graph/grap2graph.sh
index 58544e1..29df25b 100644
--- a/contrib/grap2graph/grap2graph.sh
+++ b/contrib/grap2graph/grap2graph.sh
@@ -7,7 +7,7 @@
 # In Unixland, the magic is in knowing what to string together...
 #
 # Take grap description on stdin, emit cropped bitmap on stdout.
-# The pic markup should *not* be wrapped in .G1/.G2, this script will do that.
+# The grap markup should *not* be wrapped in .G1/.G2, this script will do that.
 # A -U option on the command line enables gpic/groff "unsafe" mode.
 # A -format FOO option changes the image output format to any format
 # supported by convert(1).  All other options are passed to convert(1).
@@ -30,6 +30,7 @@
 #
 groff_opts=""
 convert_opts=""
+convert_trim_arg="-trim"
 format="png"
 
 while [ "$1" ]
@@ -54,22 +55,45 @@ done
 
 # create temporary directory
 tmp=
-for d in "$GROFF_TMPDIR" "$TMPDIR" "$TMP" "$TEMP" /tmp; do
-    test -z "$d" && continue
+for d in "$GROFF_TMPDIR" "$TMPDIR" "$TMP" "$TEMP" /tmp
+do
+    test -n "$d" && break
+done
+
+if ! test -d "$d"
+then
+    echo "$0: error: temporary directory \"$d\" does not exist or is" \
+        "not a directory" >&2
+    exit 1
+fi
 
-    tmp=`(umask 077 && mktemp -d -q "$d/grap2graph-XXXXXX") 2> /dev/null` \
-    && test -n "$tmp" && test -d "$tmp" \
-    && break
+if ! tmp=`(umask 077 && mktemp -d -q "$d/grap2graph-XXXXXX") 2> /dev/null`
+then
+    # mktemp failed--not installed or is a version that doesn't support those
+    # flags?  Fall back to older method which uses more predictable naming.
+    #
+    # $RANDOM is a Bashism.  The fallback of $PPID is not good 
pseudorandomness,
+    # but is supported by the stripped-down dash shell, for instance.
+    tmp="$d/grap2graph$$-${RANDOM:-$PPID}"
+    (umask 077 && mkdir "$tmp") 2> /dev/null
+fi
+
+if ! test -d "$tmp"
+then
+    echo "$0: error: cannot create temporary directory \"$tmp\"" >&2
+    exit 1
+fi
 
-    tmp=$d/grap2graph$$-$RANDOM
-    (umask 077 && mkdir $tmp) 2> /dev/null && break
-done;
-if test -z "$tmp"; then
-    echo "$0: cannot create temporary directory" >&2
-    { (exit 1); exit 1; }
+# See if the installed version of convert(1) is new enough to support the -trim
+# option.  Versions that didn't were described as "old" as early as 2008.
+is_convert_recent=`convert -help | grep -e -trim`
+if test -z "$is_convert_recent"
+then
+    echo "$0: warning: falling back to old '-crop 0x0' trim method" >&2
+    convert_trim_arg="-crop 0x0"
 fi
 
-trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' EXIT INT TERM
+trap 'exit_status=$?; rm -rf "$tmp" && exit $exit_status' EXIT INT TERM
 
 # Here goes:
 # 1. Add .G1/.G2.
@@ -77,7 +101,7 @@ trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' EXIT 
INT TERM
 # 3. Process through groff(1) with pic preprocessing to emit Postscript.
 # 4. Use convert(1) to crop the Postscript and turn it into a bitmap.
 (echo ".G1"; cat; echo ".G2") | grap | groff -p $groff_opts -Tps -P-pletter | \
-    convert -trim -crop 0x0 $convert_opts - $tmp/grap2graph.$format \
-    && cat $tmp/grap2graph.$format
+    convert -trim $convert_opts - "$tmp"/grap2graph.$format \
+    && cat "$tmp"/grap2graph.$format
 
 # End



reply via email to

[Prev in Thread] Current Thread [Next in Thread]