1 diff --git a/converter/other/anytopnm b/converter/other/anytopnm
2 index acf8813..335312a 100755
3 --- a/converter/other/anytopnm
4 +++ b/converter/other/anytopnm
5 @@ -511,10 +511,7 @@ else
9 -tempdir="${TMPDIR-/tmp}/anytopnm.$$"
10 -mkdir -m 0700 $tempdir || \
11 - { echo "Could not create temporary file. Exiting."; exit 1;}
12 -trap 'rm -rf $tempdir' 0
13 +tempdir=$(mktemp -d -t anytopnm.XXXXXXXXXX) || exit 1
16 # Find the filename extension for last-ditch efforts later
17 @@ -537,12 +534,17 @@ typeDescription=`file "$file" | cut -d: -f2- | cut -c2-`
18 determineType "$file" "$mimeType" "$typeDescription" "$fileExtension"
20 if [ "$filetype" = "unknown" ]; then
21 - echo "$progname: unknown file type. " \
22 - "'file' says mime type is '$mimeType', " 1>&2
23 - echo "type description is '$typeDescription'" 1>&2
24 + if [ -d "$tempdir" ] ; then
31 convertIt $file $filetype
33 +if [ -d "$tempdir" ] ; then
38 diff --git a/editor/pamstretch-gen b/editor/pamstretch-gen
39 index ba0e818..250fca0 100755
40 --- a/editor/pamstretch-gen
41 +++ b/editor/pamstretch-gen
42 @@ -31,9 +31,7 @@ if [ "$1" = "" ]; then
46 -tempdir="${TMPDIR-/tmp}/pamstretch-gen.$$"
47 -mkdir -m 0700 $tempdir || \
48 - { echo "Could not create temporary file. Exiting."; exit 1;}
49 +tempfile=$(mktemp /tmp/pnmig.XXXXXXXXXX) || exit 1
50 trap 'rm -rf $tempdir' 0 1 3 15
52 tempfile=$tempdir/pnmig
53 diff --git a/editor/pnmmargin b/editor/pnmmargin
54 index 0f57d1d..e0d3625 100755
55 --- a/editor/pnmmargin
56 +++ b/editor/pnmmargin
58 # documentation. This software is provided "as is" without express or
61 -tempdir="${TMPDIR-/tmp}/pnmmargin.$$"
62 -mkdir -m 0700 $tempdir || \
63 - { echo "Could not create temporary file. Exiting." 1>&2; exit 1;}
64 -trap 'rm -rf $tempdir' 0 1 3 15
66 +tempdir=$(mktemp -d -t ppmmargin.XXXXXXX) || exit 1
70 @@ -90,6 +86,7 @@ else
72 pnmpad $plainopt $color \
73 -left=$size -right=$size -top=$size -bottom=$size $tmp1
78 @@ -103,4 +100,4 @@ else
79 pnmcat -tb $plainopt $tmp3 $tmp4 $tmp3
84 diff --git a/editor/ppmfade b/editor/ppmfade
85 index 027fc79..8eb094f 100755
88 @@ -40,6 +40,7 @@ exec perl -w -x -S -- "$0" "$@"
90 ##############################################################################
92 +use File::Temp "tempdir";
96 @@ -137,20 +138,26 @@ if ($first_file ne "undefined") {
98 print("Frames are " . $width . "W x " . $height . "H\n");
101 +# We create a tmp-directory right here
103 +my $tmpdir = tempdir("ppmfade.XXXXXX", CLEANUP => 1);
106 if ($first_file eq "undefined") {
107 print "Fading from black to ";
108 - system("ppmmake \\#000 $width $height >junk1$$.ppm");
109 + system("ppmmake \\#000 $width $height >$tmpdir/junk1$$.ppm");
111 print "Fading from $first_file to ";
112 - system("cp", $first_file, "junk1$$.ppm");
113 + system("cp", $first_file, "$tmpdir/junk1$$.ppm");
116 if ($last_file eq "undefined") {
118 - system("ppmmake \\#000 $width $height >junk2$$.ppm");
119 + system("ppmmake \\#000 $width $height >$tmpdir/junk2$$.ppm");
121 print "$last_file\n";
122 - system("cp", $last_file, "junk2$$.ppm");
123 + system("cp", $last_file, "$tmpdir/junk2$$.ppm");
127 @@ -158,14 +165,14 @@ if ($last_file eq "undefined") {
130 # Here's what our temporary files are:
131 -# junk1$$.ppm: The original (fade-from) image
132 -# junk2$$.ppm: The target (fade-from) image
133 -# junk3$$.ppm: The frame of the fade for the current iteration of the
135 -# junk1a$$.ppm: If the fade involves a ppmmix sequence from one intermediate
136 -# image to another, this is the first frame of that
138 -# junk2a$$.ppm: This is the last frame of the above-mentioned ppmmix sequence
139 +# $tmpdir/junk1$$.ppm: The original (fade-from) image
140 +# $tmpdir/junk2$$.ppm: The target (fade-from) image
141 +# $tmpdir/junk3$$.ppm: The frame of the fade for the current iteration of the
143 +# $tmpdir/junk1a$$.ppm: If the fade involves a ppmmix sequence from one intermediate
144 +# image to another, this is the first frame of that
146 +# $tmpdir/junk2a$$.ppm: This is the last frame of the above-mentioned ppmmix sequence
148 my $i; # Frame number
149 for ($i = 1; $i <= $nframes; $i++) {
150 @@ -173,147 +180,147 @@ for ($i = 1; $i <= $nframes; $i++) {
151 if ($mode eq $SPREAD) {
153 my $n = $spline20[$i] * 100;
154 - system("ppmspread $n junk1$$.ppm >junk3$$.ppm");
155 + system("ppmspread $n $tmpdir/junk1$$.ppm >$tmpdir/junk3$$.ppm");
158 $n = $spline20[$i] * 100;
159 - system("ppmspread $n junk1$$.ppm >junk1a$$.ppm");
160 + system("ppmspread $n $tmpdir/junk1$$.ppm >$tmpdir/junk1a$$.ppm");
161 $n = (1-$spline20[$i-10]) * 100;
162 - system("ppmspread $n junk2$$.ppm >junk2a$$.ppm");
163 + system("ppmspread $n $tmpdir/junk2$$.ppm >$tmpdir/junk2a$$.ppm");
164 $n = $spline10[$i-10];
165 - system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm");
166 + system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$tmpdir/junk3$$.ppm");
168 my $n = (1-$spline20[$i-10])*100;
169 - system("ppmspread $n junk2$$.ppm >junk3$$.ppm");
170 + system("ppmspread $n $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
172 } elsif ($mode eq $SHIFT) {
174 my $n = $spline20[$i] * 100;
175 - system("ppmshift $n junk1$$.ppm >junk3$$.ppm");
176 + system("ppmshift $n $tmpdir/junk1$$.ppm >$tmpdir/junk3$$.ppm");
179 $n = $spline20[$i] * 100;
180 - system("ppmshift $n junk1$$.ppm >junk1a$$.ppm");
181 + system("ppmshift $n $tmpdir/junk1$$.ppm >$tmpdir/junk1a$$.ppm");
182 $n = (1-$spline20[$i-10])*100;
183 - system("ppmshift $n junk2$$.ppm >junk2a$$.ppm");
184 + system("ppmshift $n $tmpdir/junk2$$.ppm >$tmpdir/junk2a$$.ppm");
185 $n = $spline10[$i-10];
186 - system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm");
187 + system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$tmpdir/junk3$$.ppm");
189 my $n = (1-$spline20[$i-10]) * 100;
190 - system("ppmshift $n junk2$$.ppm >junk3$$.ppm");
191 + system("ppmshift $n $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
193 } elsif ($mode eq $RELIEF) {
195 - system("ppmrelief junk1$$.ppm >junk1r$$.ppm");
196 + system("ppmrelief $tmpdir/junk1$$.ppm >$tmpdir/junk1r$$.ppm");
199 my $n = $spline10[$i];
200 - system("ppmmix $n junk1$$.ppm junk1r$$.ppm >junk3$$.ppm");
201 + system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1r$$.ppm >$tmpdir/junk3$$.ppm");
203 my $n = $spline10[$i-10];
204 - system("ppmmix $n junk1r$$.ppm junk2r$$.ppm >junk3$$.ppm");
205 + system("ppmmix $n $tmpdir/junk1r$$.ppm $tmpdir/junk2r$$.ppm >$tmpdir/junk3$$.ppm");
207 my $n = $spline10[$i-20];
208 - system("ppmmix $n junk2r$$.ppm junk2$$.ppm >junk3$$.ppm");
209 + system("ppmmix $n $tmpdir/junk2r$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
212 - system("ppmrelief junk2$$.ppm >junk2r$$.ppm");
213 + system("ppmrelief $tmpdir/junk2$$.ppm >$tmpdir/junk2r$$.ppm");
215 } elsif ($mode eq $OIL) {
217 - system("ppmtopgm junk1$$.ppm | pgmoil >junko$$.ppm");
218 - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
220 + system("ppmtopgm $tmpdir/junk1$$.ppm | pgmoil >$tmpdir/junko$$.ppm");
221 + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
222 + ">$tmpdir/junk1o$$.ppm");
225 my $n = $spline10[$i];
226 - system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm");
227 + system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tmpdir/junk3$$.ppm");
229 my $n = $spline10[$i-10];
230 - system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm");
231 + system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$tmpdir/junk3$$.ppm");
233 my $n = $spline10[$i-20];
234 - system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm");
235 + system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
238 - system("ppmtopgm junk2$$.ppm | pgmoil >junko$$.ppm");
239 - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
241 + system("ppmtopgm $tmpdir/junk2$$.ppm | pgmoil >$tmpdir/junko$$.ppm");
242 + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
243 + ">$tmpdir/junk2o$$.ppm");
245 } elsif ($mode eq $EDGE) {
247 - system("ppmtopgm junk1$$.ppm | pgmedge >junko$$.ppm");
248 - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
250 + system("ppmtopgm $tmpdir/junk1$$.ppm | pgmedge >$tmpdir/junko$$.ppm");
251 + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
252 + ">$tmpdir/junk1o$$.ppm");
255 my $n = $spline10[$i];
256 - system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm");
257 + system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tmpdir/junk3$$.ppm");
259 my $n = $spline10[$i-10];
260 - system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm");
261 + system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$tmpdir/junk3$$.ppm");
263 my $n = $spline10[$i-20];
264 - system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm");
265 + system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
268 - system("ppmtopgm junk2$$.ppm | pgmedge >junko$$.ppm");
269 - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
271 + system("ppmtopgm $tmpdir/junk2$$.ppm | pgmedge >$tmpdir/junko$$.ppm");
272 + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
273 + ">$tmpdir/junk2o$$.ppm");
275 } elsif ($mode eq $BENTLEY) {
277 - system("ppmtopgm junk1$$.ppm | pgmbentley >junko$$.ppm");
278 - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
280 + system("ppmtopgm $tmpdir/junk1$$.ppm | pgmbentley >$tmpdir/junko$$.ppm");
281 + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
282 + ">$tmpdir/junk1o$$.ppm");
285 my $n = $spline10[$i];
286 - system("ppmmix $n junk1$$.ppm junk1o$$.ppm >junk3$$.ppm");
287 + system("ppmmix $n $tmpdir/junk1$$.ppm $tmpdir/junk1o$$.ppm >$tmpdir/junk3$$.ppm");
289 my $n = $spline10[$i-10];
290 - system("ppmmix $n junk1o$$.ppm junk2o$$.ppm >junk3$$.ppm");
291 + system("ppmmix $n $tmpdir/junk1o$$.ppm $tmpdir/junk2o$$.ppm >$tmpdir/junk3$$.ppm");
293 my $n = $spline10[$i-20];
294 - system("ppmmix $n junk2o$$.ppm junk2$$.ppm >junk3$$.ppm");
295 + system("ppmmix $n $tmpdir/junk2o$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
298 - system("ppmtopgm junk2$$.ppm | pgmbentley >junko$$.ppm");
299 - system("rgb3toppm junko$$.ppm junko$$.ppm junko$$.ppm " .
301 + system("ppmtopgm $tmpdir/junk2$$.ppm | pgmbentley >$tmpdir/junko$$.ppm");
302 + system("rgb3toppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm $tmpdir/junko$$.ppm " .
303 + ">$tmpdir/junk2o$$.ppm");
305 } elsif ($mode eq $BLOCK) {
307 my $n = 1 - 1.9*$spline20[$i];
308 - system("pamscale $n junk1$$.ppm | " .
309 - "pamscale -width $width -height $height >junk3$$.ppm");
310 + system("pamscale $n $tmpdir/junk1$$.ppm | " .
311 + "pamscale -width $width -height $height >$tmpdir/junk3$$.ppm");
313 my $n = $spline10[$i-10];
314 - system("ppmmix $n junk1a$$.ppm junk2a$$.ppm >junk3$$.ppm");
315 + system("ppmmix $n $tmpdir/junk1a$$.ppm $tmpdir/junk2a$$.ppm >$tmpdir/junk3$$.ppm");
317 my $n = 1 - 1.9*$spline20[31-$i];
318 - system("pamscale $n junk2$$.ppm | " .
319 - "pamscale -width $width -height $height >junk3$$.ppm");
320 + system("pamscale $n $tmpdir/junk2$$.ppm | " .
321 + "pamscale -width $width -height $height >$tmpdir/junk3$$.ppm");
324 - system("cp", "junk3$$.ppm", "junk1a$$.ppm");
325 - system("pamscale $n junk2$$.ppm | " .
326 - "pamscale -width $width -height $height >junk2a$$.ppm");
327 + system("cp", "$tmpdir/junk3$$.ppm", "$tmpdir/junk1a$$.ppm");
328 + system("pamscale $n $tmpdir/junk2$$.ppm | " .
329 + "pamscale -width $width -height $height >$tmpdir/junk2a$$.ppm");
331 } elsif ($mode eq $MIX) {
332 my $fade_factor = sqrt(1/($nframes-$i+1));
333 - system("ppmmix $fade_factor junk1$$.ppm junk2$$.ppm >junk3$$.ppm");
334 + system("ppmmix $fade_factor $tmpdir/junk1$$.ppm $tmpdir/junk2$$.ppm >$tmpdir/junk3$$.ppm");
336 print("Internal error: impossible mode value '$mode'\n");
339 my $outfile = sprintf("%s.%04d.ppm", $base_name, $i);
340 - system("cp", "junk3$$.ppm", $outfile);
341 + system("cp", "$tmpdir/junk3$$.ppm", $outfile);
347 -system("rm junk*$$.ppm");
348 +system("rm $tmpdir/junk*$$.ppm");
351 diff --git a/editor/ppmshadow b/editor/ppmshadow
352 index 62cdf8b..72e1b22 100755
353 --- a/editor/ppmshadow
354 +++ b/editor/ppmshadow
355 @@ -97,9 +97,10 @@ sub makeConvolutionKernel($$) {
358 my $tmpdir = $ENV{TMPDIR} || "/tmp";
359 -my $ourtmp = "$tmpdir/ppmshadow$$";
360 -mkdir($ourtmp, 0777) or
361 - die("Unable to create directory for temporary files '$ourtmp");
362 +my $ourtmp; chomp($ourtmp = `mktemp -d -t PPMshadow.XXXXXX`);
364 + die "Can't create directory for temporary files";
367 # Process command line options