# HG changeset patch # User jwe # Date 777703263 0 # Node ID cf16ec9a242817e6976041d9eb2dfb003d494e99 # Parent 95c7e27b2df7f2f153486a0a1a869eaddf66980c [project @ 1994-08-24 04:38:14 by jwe] diff --git a/src/Makefile.in b/src/Makefile.in --- a/src/Makefile.in +++ b/src/Makefile.in @@ -37,7 +37,7 @@ @echo making $@ from $< @$(CXXCPP) -c $(CPPFLAGS) $(XALL_CXXFLAGS) -DMAKE_BUILTINS $< \ | $(srcdir)/mkdefs > $@.tmp - @if test "`wc $@.tmp | awk '{print $3}'`" -ne 0 ; then \ + @if test `wc $@.tmp | sed 's%[^0-9]*\([0-9]*\).*%\1%'` -ne 0 ; then \ mv $@.tmp $@ ; \ else \ echo "error: $@ is empty!" 1>&2 ; \ @@ -157,7 +157,7 @@ etags $(SOURCES) clean: - rm -f *.a *.o *.def builtins.cc + rm -f *.a *.o builtins.cc .PHONY: clean mostlyclean: @@ -165,24 +165,24 @@ .PHONY: mostlyclean distclean: clean - rm -f Makefile octave .fname *.d + rm -f Makefile octave .fname *.d *.def .PHONY: distclean realclean: distclean rm -f tags TAGS y.tab.c y.tab.h y.output yy.lex.c \ - lex.cc parse.cc defaults.h *.d + lex.cc parse.cc defaults.h *.d *.def .PHONY: realclean local-dist: parse.cc lex.cc ln $(DISTFILES) ../`cat ../.fname`/src - rm -f parse.cc lex.cc y.tab.h y.output yy.lex.c \ - lex.cc parse.cc defaults.h + rm -f parse.cc lex.cc y.tab.h y.output yy.lex.c + rm -f lex.cc parse.cc defaults.h *.d *.def .PHONY: local-dist dist: parse.cc lex.cc ln $(DISTFILES) ../`cat ../.fname`/src - rm -f parse.cc lex.cc y.tab.h y.output yy.lex.c \ - lex.cc parse.cc defaults.h + rm -f parse.cc lex.cc y.tab.h y.output yy.lex.c + rm -f lex.cc parse.cc defaults.h *.d *.def .PHONY: dist # Special rules -- these files need special things to be defined. diff --git a/src/utils.cc b/src/utils.cc --- a/src/utils.cc +++ b/src/utils.cc @@ -34,6 +34,12 @@ make_absolute get_working_directory change_to_directory gethostname +The 2 functions listed below were adapted from a similar functions +from GCC, the GNU C compiler, copyright (C) 1987, 1989, 1992, 1993, +1994 Free Software Foundation, Inc. + + choose_temp_base_try octave_tmp_file_name + */ #ifdef HAVE_CONFIG_H @@ -199,6 +205,80 @@ } #endif +// Compute a string to use as the base of all temporary file names. + +static char * +choose_temp_base_try (char *try_me, char *base) +{ + char *retval; + + if (base) + retval = base; + else if (! try_me) + retval = 0; + else if (access (try_me, R_OK | W_OK) != 0) + retval = 0; + else + retval = try_me; + + return retval; +} + +// Get a temporary file name. The prefix comes from the envvar +// TMPDIR, or TMP, or TEMP if defined; otherwise, from the P_tmpdir +// macro if that is defined; otherwise, it is /usr/tmp or /tmp, or ./. +// +// If nothing works, panic. + +char * +octave_tmp_file_name (void) +{ +#if defined (HAVE_MKTEMP) + static char *temp_file_name = 0; + + char *base = 0; + int len; + + base = choose_temp_base_try (getenv ("TMPDIR"), base); + base = choose_temp_base_try (getenv ("TMP"), base); + base = choose_temp_base_try (getenv ("TEMP"), base); + +#ifdef P_tmpdir + base = choose_temp_base_try (P_tmpdir, base); +#endif + + base = choose_temp_base_try ("/usr/tmp", base); + base = choose_temp_base_try ("/tmp", base); + +// If all else fails, use the current directory! + + if (base == (char *)0) + base = "./"; + + len = strlen (base); + + delete [] temp_file_name; + + temp_file_name = new char [len + sizeof("/oct-XXXXXX") + 1]; + + strcpy (temp_file_name, base); + + if (len > 0 && temp_file_name[len-1] != '/') + temp_file_name[len++] = '/'; + + strcpy (temp_file_name + len, "oct-XXXXXX"); + + mktemp (temp_file_name); + + if (! strlen (temp_file_name)) + panic ("unable to find directory for temporary files!"); + + return temp_file_name; +#else + return tmpnam (0); +#endif +} + char ** pathstring_to_vector (char *pathstring) {