# HG changeset patch # User jwe # Date 846991564 0 # Node ID d07a5d0b57e2ba3fee06663b9cc5bb0d1ac3a494 # Parent 5be3f6f5986aa9d2f17b3f413dc72aacc6da9661 [project @ 1996-11-03 03:25:18 by jwe] diff --git a/NEWS b/NEWS --- a/NEWS +++ b/NEWS @@ -190,13 +190,13 @@ * New audio functions from Andreas Weingessel . - lin2mu -- linear to mu-law encoding - loadaudio -- load an audio file to a vector - mu2lin -- mu-law to linear encoding - playaudio -- play an audio file - record -- record sound and store in vector - saveaudio -- save a vector as an audio file - setaudio -- executes mixer shell command + lin2mu -- linear to mu-law encoding + loadaudio -- load an audio file to a vector + mu2lin -- mu-law to linear encoding + playaudio -- play an audio file + record -- record sound and store in vector + saveaudio -- save a vector as an audio file + setaudio -- executes mixer shell command * New plotting functions from Vinayak Dutt. Ones dealing with multiple plots on one page require features from gnuplot 3.6beta @@ -247,8 +247,8 @@ These functions return new strings. - tolower -- convert to lower case - toupper -- convert to upper case + tolower -- convert to lower case + toupper -- convert to upper case * New function, fgetl. Both fgetl and fgets accept an optional second argument that specifies a maximum number of characters to @@ -278,21 +278,21 @@ * New io/subprocess functions: - fputs -- write a string to a file with no formatting - popen2 -- start a subprocess with 2-way communication - mkfifo -- create a FIFO special file - popen -- open a pipe to a subprocess - pclose -- close a pipe from a subprocess - waitpid -- check the status of or wait for subprocesses + fputs -- write a string to a file with no formatting + popen2 -- start a subprocess with 2-way communication + mkfifo -- create a FIFO special file + popen -- open a pipe to a subprocess + pclose -- close a pipe from a subprocess + waitpid -- check the status of or wait for subprocesses * New time functions: - asctime -- format time structure according to local format - ctime -- equivalent to `asctime (localtime (TMSTRUCT))' - gmtime -- return time structure corresponding to UTC - localtime -- return time structure corresponding to local time zone - strftime -- print given time structure using specified format - time -- return current time + asctime -- format time structure according to local format + ctime -- equivalent to `asctime (localtime (TMSTRUCT))' + gmtime -- return time structure corresponding to UTC + localtime -- return time structure corresponding to local time zone + strftime -- print given time structure using specified format + time -- return current time The `clock' and `date' functions are now implemented in M-files using these basic functions. @@ -310,11 +310,12 @@ * Other new functions: - atexit -- register functions to be called when Octave exits - putenv -- define an environment variable - meshgrid -- compatible with Matlab's meshgrid function - tilde_expand -- perform tilde expansion on string - completion_matches -- perform command completion on string + tmpnam -- replaces octave_tmp_file_name + atexit -- register functions to be called when Octave exits + putenv -- define an environment variable + meshgrid -- compatible with Matlab's meshgrid function + tilde_expand -- perform tilde expansion on string + completion_matches -- perform command completion on string * The New function octave_config_info returns a structure containing information about how Octave was configured and compiled. diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,13 @@ +Sat Nov 2 21:06:29 1996 John W. Eaton + + * image/image.m: Use tmpnam() instead of home-brew scheme. + + * audio/record.m, audio/playaudio.m: Use tmpnam() instead of + octave_tmp_file_name(). Use unwind_protect to ensure tmp file is + deleted. + * miscellaneous/bug_report.m: Likewise. Also use unlink() instead + of a system() command to delete the tmp file. + Wed Oct 30 17:19:45 1996 John W. Eaton * Version 1.90. diff --git a/scripts/audio/playaudio.m b/scripts/audio/playaudio.m --- a/scripts/audio/playaudio.m +++ b/scripts/audio/playaudio.m @@ -37,8 +37,6 @@ function playaudio (name, ext) - file = octave_tmp_file_name (); - usage_msg = "playaudio (name [, ext]) or playaudio (X)"; if (nargin == 1 && is_vector (name) && ! isstr (name)) @@ -53,11 +51,15 @@ endif endif X = name + 127; - num = fopen (file, "w"); - c = fwrite (num, X, "uchar"); - fclose (num); - system (sprintf ("cat %s > /dev/dsp", file)); - unlink (file); + unwind_protect + file = tmpnam (); + num = fopen (file, "w"); + c = fwrite (num, X, "uchar"); + fclose (num); + system (sprintf ("cat %s > /dev/dsp", file)); + unwind_protect_cleanup + unlink (file); + end_unwind_protect elseif (nargin >= 1 && isstr (name)) ## play a file if (nargin == 1) diff --git a/scripts/audio/record.m b/scripts/audio/record.m --- a/scripts/audio/record.m +++ b/scripts/audio/record.m @@ -36,22 +36,28 @@ usage ("X = record (sec [, sampling_rate])"); endif - file = octave_tmp_file_name (); + unwind_protect + + file = tmpnam (); - input ("Please hit ENTER and speak afterwards!\n", 1); + input ("Please hit ENTER and speak afterwards!\n", 1); - cmd = sprintf ("dd if=/dev/dsp of=%s bs=%d count=%d", - file, sampling_rate, sec) + cmd = sprintf ("dd if=/dev/dsp of=%s bs=%d count=%d", + file, sampling_rate, sec) + + system (cmd); - system (cmd); + num = fopen (file, "r"); - num = fopen (file, "r"); + [Y, c] = fread (num, sampling_rate * sec, "uchar"); + + fclose (num); - [Y, c] = fread (num, sampling_rate * sec, "uchar"); + unwind_protect_cleanup - fclose (num); + unlink (file); - unlink (file); + end_unwind_protect X = Y - 127; diff --git a/scripts/image/image.m b/scripts/image/image.m --- a/scripts/image/image.m +++ b/scripts/image/image.m @@ -43,21 +43,23 @@ usage ("image (matrix, [zoom])"); endif - ## XXX FIXME XXX -- we should use octave_tmp_file_name. - - rnd_str = num2str (fix (rand * 10000)); - ppm_name = ["image.", rnd_str, ".ppm" ]; + ppm_name = tmpnam (); saveimage (ppm_name, x, "ppm"); ## Start the viewer. Try xv, then xloadimage. xv = sprintf ("xv -expand %f %s", zoom, ppm_name); + xloadimage = sprintf ("xloadimage -zoom %f %s", zoom*100, ppm_name); + rm = sprintf ("rm -f %s", ppm_name); - command = sprintf ("( %s || %s && %s ) > /dev/null 2>&1 &", ... - xv, xloadimage, rm); + ## Need to let the shell clean up the tmp file because we are putting + ## the viewer in the background. + + command = sprintf ("( %s || %s && %s ) > /dev/null 2>&1 &", + xv, xloadimage, rm); system (command); diff --git a/scripts/miscellaneous/bug_report.m b/scripts/miscellaneous/bug_report.m --- a/scripts/miscellaneous/bug_report.m +++ b/scripts/miscellaneous/bug_report.m @@ -37,31 +37,34 @@ subject = ""; subject = input ("Subject: ", "s"); - ## XXX FIXME XXX -- really need a better system command, one that will - ## automatically send output from the command to stdout... + unwind_protect - prefs = octave_tmp_file_name (); + prefs = tmpnam (); - if (! isempty (prefs)) - fopen (prefs, "w"); - dump_prefs (prefs); - fclose (prefs); - endif + if (! isempty (prefs)) + fopen (prefs, "w"); + dump_prefs (prefs); + fclose (prefs); + endif - cmd = "octave-bug"; + cmd = "octave-bug"; - if (length (subject) > 0) - cmd = sprintf ("%s -s \"%s\"", cmd, subject); - endif + if (length (subject) > 0) + cmd = sprintf ("%s -s \"%s\"", cmd, subject); + endif + + if (! isempty (prefs)) + cmd = sprintf ("%s %s", cmd, prefs); + endif - if (! isempty (prefs)) - cmd = sprintf ("%s %s", cmd, prefs); - endif + system (cmd); + + unwind_protect_cleanup - system (cmd); + if (! isempty (prefs)) + unlink (prefs); + endif - if (! isempty (prefs)) - system (sprintf ("rm -f %s", prefs)); - endif + end_unwind_protect endfunction diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,7 @@ Sat Nov 2 20:44:55 1996 John W. Eaton + * file-io.cc (Ftmpnam): Rename from Foctave_temp_file_name. + * Makefile.in (DLD_SRC): Move time.cc and getrusage.cc here from SOURCES. Add getpwent.cc. diff --git a/src/file-io.cc b/src/file-io.cc --- a/src/file-io.cc +++ b/src/file-io.cc @@ -1232,8 +1232,8 @@ return retval; } -DEFUN (octave_tmp_file_name, args, , - "octave_tmp_file_name ()\n\ +DEFUN (tmpnam, args, , + "tmpnam ()\n\ Return unique temporary file name.") { octave_value retval; @@ -1241,11 +1241,13 @@ if (args.length () == 0) retval = oct_tempnam (); else - print_usage ("octave_tmp_file_name"); + print_usage ("tmpnam"); return retval; } +DEFALIAS (octave_tmp_file_name, tmpnam); + static int convert (int x, int ibase, int obase) {