Mercurial > hg > octave-terminal
changeset 1583:5383d2d4cf9d
[project @ 1995-10-27 08:51:20 by jwe]
author | jwe |
---|---|
date | Fri, 27 Oct 1995 08:51:20 +0000 |
parents | d23a8704e306 |
children | 3ce1c706b142 |
files | src/file-io.cc |
diffstat | 1 files changed, 23 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -51,6 +51,7 @@ #include <readline/tilde.h> #include <DLList.h> +#include <SLStack.h> #include "dMatrix.h" @@ -79,6 +80,18 @@ // double linked list containing relevant information about open files static DLList <file_info> file_list; +// stack for next available file number +static SLStack <int> next_available_file_number; + +static int +get_next_avail_file_num (void) +{ + if (next_available_file_number.empty ()) + return file_list.length (); + else + return next_available_file_number.pop (); +} + void initialize_file_io (void) { @@ -147,8 +160,8 @@ { FILE *file_ptr = fopen (name, mode); if (file_ptr) - { - int file_number = file_list.length () + 1; + { + int file_number = get_next_avail_file_num (); file_info file (file_number, name, file_ptr, mode); file_list.append (file); @@ -223,6 +236,7 @@ } int success = fclose (file.fptr ()); + next_available_file_number.push (file.number ()); file_list.del (p); if (success == 0) @@ -493,7 +507,7 @@ return retval; } - int file_number = file_list.length () + 1; + int file_number = get_next_avail_file_num (); file_info file (file_number, name, file_ptr, mode); file_list.append (file); @@ -543,7 +557,7 @@ { file_info file = file_list (p); output_buf.form ("%7d%6s %s\n", file.number (), - file.mode ().data (), file.name ().data ()); + file.mode ().c_str (), file.name ().c_str ()); file_list.next (p); } @@ -751,9 +765,10 @@ { int success = fclose (file.fptr ()); if (success != 0) - error ("closing %s", file.name ().data ()); + error ("closing %s", file.name ().c_str ()); } + next_available_file_number.push (file.number ()); file_list.del (p); } else @@ -1946,7 +1961,7 @@ return retval; } - int number = file_list.length () + 1; + int number = get_next_avail_file_num (); file_info file (number, name, file_ptr, mode); file_list.append (file); @@ -1995,6 +2010,7 @@ } int success = pclose (file.fptr ()); + next_available_file_number.push (file.number ()); file_list.del (p); if (success == 0) @@ -2091,7 +2107,7 @@ return retval; } - new_stdin = file_list.length () + 1; + new_stdin = get_next_avail_file_num (); new_stdout = new_stdin + 1; file_info new_stdin_file_ptr (new_stdin, name, stdin_file, "w");