"Fossies" - the Fresh Open Source Software Archive 
Member "pfstools-2.2.0/src/octave/pfsclose.cpp" (12 Aug 2021, 2340 Bytes) of package /linux/privat/pfstools-2.2.0.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /**
2 * @brief Close pfs stream
3 *
4 * This file is a part of PFSTOOLS package.
5 * ----------------------------------------------------------------------
6 * Copyright (C) 2003,2004 Rafal Mantiuk and Grzegorz Krawczyk
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * ----------------------------------------------------------------------
22 *
23 * @author Rafal Mantiuk, <mantiuk@mpi-sb.mpg.de>
24 *
25 * $Id: pfsclose.cpp,v 1.1 2005/06/15 13:36:54 rafm Exp $
26 */
27
28 #include <octave/oct.h>
29 #include <octave/oct-stream.h>
30 #include <octave/ov-struct.h>
31
32 //#include "../../config.h" // conflicts with config.h from octave distribution
33
34 #include <string>
35 #include <pfs.h>
36
37 #if OCTAVE_MAJOR_VERSION < 4 || (OCTAVE_MAJOR_VERSION == 4 && OCTAVE_MINOR_VERSION < 4)
38 #define isstruct is_map
39 #endif
40
41 #define SCRIPT_NAME "pfsclose"
42
43 static const char *helpString =
44 #include "pfsclose_help.h"
45
46 DEFUN_DLD( pfsclose, args, , helpString )
47 {
48 octave_value_list retval;
49
50 int nargin = args.length();
51
52 // Get arguments and check if they are legal
53
54 if( nargin != 1 || !args(0).isstruct() )
55 {
56 error( SCRIPT_NAME ": Improper usage!");
57 return retval;
58 }
59
60 octave_map pfsStream = args(0).map_value();
61
62 octave_scalar_map::const_iterator itFH = pfsStream.seek( "FH" );
63 if( itFH == pfsStream.end() ||
64 !pfsStream.contents( itFH )(0).is_real_scalar() )
65 {
66 error( SCRIPT_NAME ": FH field missing in the structure or it has wrong type");
67 return retval;
68 }
69 FILE *fh = (FILE*)((long)(pfsStream.contents( itFH )(0).double_value()));
70
71 // close file if not stdin or stdout
72
73 if( fh != stdin && fh != stdout )
74 fclose( fh );
75
76 return retval;
77 }