1 ## Copyright (C) 2002 Etienne Grossmann <etienne@isr.ist.utl.pt>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn{Function File} {@var{n} = } temp_name ( rootname, quick )
19 ## name = temp_name(rootname, quick=1) - Return a name that is not used
21 ## Returns a name, suitable for defining a new function, script or global
22 ## variable, of the form
26 ## Default rootname is "temp_name_"
28 ## "quick" is an optional parameter, which defaults to 1. If it is false,
29 ## temp_name() will find the smallest acceptable number for the name.
30 ## Otherwise, a hopefully quicker method is used.
34 function n = temp_name (rootname, quick)
36 persistent warned = false;
39 warning ("Octave:deprecated-function",
40 "temp_name has been deprecated, and will be removed in the future. Use `tmpnam' instead.");
43 ### Keep track of previously asked names
44 persistent cnt = struct ("dummy",0);
46 if nargin<1 || !length(rootname), rootname = "temp_name_" ; endif
48 if nargin<2, quick = 1; endif
51 if ! isfield (cnt, rootname)
61 n = sprintf ([rootname,"%i"], c);
65 n = sprintf ([rootname,"%i"], c);