diff options
author | wlemb <wlemb> | 2003-10-28 07:46:21 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2003-10-28 07:46:21 +0000 |
commit | 6f5e764aa363f94048dadabcde94956e507edd87 (patch) | |
tree | 8a7e544e9a46558caeb33484cf61ea12fac7c675 /contrib/grap2graph | |
parent | 1b6b1ae675b4df397807631699464f3fa77a9727 (diff) | |
download | groff-6f5e764aa363f94048dadabcde94956e507edd87.tar.gz |
* contrib/eqn2graph/eqn2graph.sh, contrib/grap2graph/grap2graph.sh,
contrib/pic2graph/pic2graph.sh: Implement secure management of
temporary files.
Pass `-P-pletter' to groff to avoid data outside of the converted
area -- some versions of `convert' (for example 5.3.8) don't check
the bounding box of the image but always use a fixed image size
(letter paper format).
* contrib/eqn2graph/eqn2graph.man, contrib/grap2graph/grap2graph.man,
contrib/pic2graph/pic2graph.man: Updated.
* src/roff/groff/groff.man: Document $TMP and $TEMP.
Diffstat (limited to 'contrib/grap2graph')
-rw-r--r-- | contrib/grap2graph/grap2graph.man | 18 | ||||
-rw-r--r-- | contrib/grap2graph/grap2graph.sh | 29 |
2 files changed, 40 insertions, 7 deletions
diff --git a/contrib/grap2graph/grap2graph.man b/contrib/grap2graph/grap2graph.man index cf259321..0c6d4568 100644 --- a/contrib/grap2graph/grap2graph.man +++ b/contrib/grap2graph/grap2graph.man @@ -1,4 +1,4 @@ -.\" $Id: grap2graph.man,v 1.2 2003/07/02 18:48:25 wlemb Exp $ +.\" $Id: grap2graph.man,v 1.3 2003/10/28 07:46:23 wlemb Exp $ .\" This documentation is released to the public domain. . . @@ -72,6 +72,22 @@ Command-line switches and arguments not listed above are passed to .BR convert (1). . . +.SH ENVIRONMENT +.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). +Otherwise, temporary files will be created in +.BR /tmp . +. +. .SH "SEE ALSO" .BR pic2graph (@MAN1EXT@), .BR eqn2graph (@MAN1EXT@), diff --git a/contrib/grap2graph/grap2graph.sh b/contrib/grap2graph/grap2graph.sh index 75bb881e..7737f1ef 100644 --- a/contrib/grap2graph/grap2graph.sh +++ b/contrib/grap2graph/grap2graph.sh @@ -28,7 +28,7 @@ # # Thus, we pass -U to groff(1), and everything else to convert(1). # -# $Id: grap2graph.sh,v 1.1 2003/07/02 15:35:01 wlemb Exp $ +# $Id: grap2graph.sh,v 1.2 2003/10/28 07:46:23 wlemb Exp $ # groff_opts="" convert_opts="" @@ -54,15 +54,32 @@ do shift done +# create temporary directory +tmp= +for d in "$GROFF_TMPDIR" "$TMPDIR" "$TMP" "$TEMP" /tmp; do + test -z "$d" && continue + + tmp=`(umask 077 && mktemp -d -q "$d/grap2graph-XXXXXX") 2> /dev/null` \ + && test -n "$tmp" && test -d "$tmp" \ + && break + + 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; } +fi + +trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0 2 15 + # Here goes: # 1. Add .G1/.G2. # 2. Process through grap(1) to emit pic markup. # 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. -tmp=/usr/tmp/grap2graph-$$ -trap "rm ${tmp}.*" 0 2 15 -(echo ".G1"; cat; echo ".G2") | grap | groff -p $groff_opts -Tps | \ - convert -crop 0x0 $convert_opts - ${tmp}.${format} \ - && cat ${tmp}.${format} +(echo ".G1"; cat; echo ".G2") | grap | groff -p $groff_opts -Tps -P-pletter | \ + convert -crop 0x0 $convert_opts - $tmp/grap2graph.$format \ + && cat $tmp/grap2graph.$format # End |