add an option to close all files

This commit is contained in:
Jim Saxton 2017-07-07 13:37:44 -07:00
parent 8bf19814bc
commit 20854fc3b0
2 changed files with 23 additions and 3 deletions

View File

@ -762,12 +762,24 @@ void myclose(void) /* close the specified stream */
#endif #endif
s=(int)pop(stNUMBER)->value; s=(int)pop(stNUMBER)->value;
if (s == -2){
for(s=1;s<FOPEN_MAX-4;s++) {
if (stream_modes[s]!=smCLOSED) {
streams[s]=NULL;
stream_modes[s]=smCLOSED;
}
}
return;
}
if (abs(s)==STDIO_STREAM || badstream(s,0)) return; if (abs(s)==STDIO_STREAM || badstream(s,0)) return;
if (stream_modes[s]==smCLOSED) { if (stream_modes[s]==smCLOSED) {
sprintf(string,"stream %d already closed",s); sprintf(string,"stream %d already closed",s);
error(WARNING,string); error(WARNING,string);
return; return;
} }
if (s==lprstream) { if (s==lprstream) {
#ifdef UNIX #ifdef UNIX
pclose(lineprinter); pclose(lineprinter);

View File

@ -3211,18 +3211,26 @@ close -- close a file, which has been opened before
Synopsis: Synopsis:
close filenum close filenum
close # filenum close # filenum
close -2
close #-2
Description: Description:
The close-command closes an open file. You should issue this command as soon as you are done with reading from or writing to a file. The close-command closes an open file. You should issue this command as soon as you are done with reading from or writing to a file.
close -2 closes all open files.
Example: Example:
all = -2
open "my.data" for reading as 1 open "my.data" for reading as 1
input #1 a input #1 a
print a print a
close 1 close all
Explanation: Explanation:
This program opens the file "my.data", reads a number from it, prints this number and closes the file again. This program opens the file "my.data", reads a number from it, prints this number and then closes all files.
Related: open Related: open