1 /*
2     Gri - A language for scientific graphics programming
3     Copyright (C) 2008 Daniel Kelley
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #include <stdio.h>
21 #include <string.h>
22 #include "extern.hh"
23 #include "private.hh"
24 #include "DataFile.hh"
25 
26 bool
closeCmd()27 closeCmd()
28 {
29 	if (((unsigned) superuser()) & FLAG_AUT1)printf("\nDEBUG: %s:%d closing a datafile.   Before doing that, datafile stack_len= %d\n",__FILE__,__LINE__,int(_dataFILE.size()));
30 
31 
32 	if ((_dataFILE.back()).get_type() == DataFile::from_cmdfile) {
33 		err("`close' ignored: no data file open");
34 		return false;
35 	}
36 	int file = _dataFILE.size() - 1;
37 	std::string fname;
38 	switch (_nword) {
39 	case 1:
40 		break;
41 	case 2:
42 		fname.assign(_word[1]);
43 		un_double_quote(fname);
44 		file = data_file_index(fname.c_str());
45 		if (file < 0) {
46 			extern char     _grTempString[];
47 			sprintf(_grTempString, "`close' cannot close `%s' since it is not open", _word[1]);
48 			err(_grTempString);
49 			return false;
50 		}
51 		break;
52 	default:
53 		demonstrate_command_usage();
54 		NUMBER_WORDS_ERROR;
55 		return false;
56 	}
57 	pop_data_file(file);
58 	clear_eof_flag_on_data_file();
59 	return true;
60 }
61