coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
io.h
Go to the documentation of this file.
1 #ifndef IO_H
2 #define IO_H
3 #pragma once
4 /***************************************************************************
5  * Copyright (C) 2004, 2006 Symbian Software Ltd. *
6  * All rights reserved. *
7  * Copyright (C) 2007-2013 Mike Kinghan, imk@burroingroingjoing.com *
8  * All rights reserved. *
9  * *
10  * Contributed originally by Mike Kinghan, imk@burroingroingjoing.com *
11  * *
12  * Redistribution and use in source and binary forms, with or without *
13  * modification, are permitted provided that the following conditions *
14  * are met: *
15  * *
16  * Redistributions of source code must retain the above copyright *
17  * notice, this list of conditions and the following disclaimer. *
18  * *
19  * Redistributions in binary form must reproduce the above copyright *
20  * notice, this list of conditions and the following disclaimer in the *
21  * documentation and/or other materials provided with the distribution. *
22  * *
23  * Neither the name of Symbian Software Ltd. nor the names of its *
24  * contributors may be used to endorse or promote products derived from *
25  * this software without specific prior written permission. *
26  * *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
28  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
30  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
31  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED *
35  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,*
36  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF *
37  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
38  * DAMAGE. *
39  * *
40  **************************************************************************/
41 
42 #include "filesys.h"
43 #include <string>
44 #include <cassert>
45 
51 struct io {
53 
55  static char const * const _stdin_name_; // = "[stdin]"
56 
57 
65  static std::string read_filename();
66 
74  static FILE * open_file(std::string const & file, const char *mode);
75 
81  static void open(std::string const & fname);
82 
96  static void close(unsigned error);
97 
99  static void close_input();
100 
102  static void top();
103 
105  static std::string in_file_name() {
106  return _in_filename_;
107  }
108 
110  static std::ostream * output() {
111  return _output_;
112  }
113 
115  static std::istream * input() {
116  return _input_;
117  }
118 
124  static void set_spin_dir(char const *optarg);
125 
132  static void set_spin_prefix(char const *optarg);
133 
135  static std::string const & spin_dir() {
136  return _spin_dir_;
137  }
138 
140  static bool spin() {
141  return !_spin_dir_.empty();
142  }
143 
144 private:
145 
156  static void replace_infile();
157 
167  static void backup_infile(const char *filename);
168 
176  static void backup_infile();
177 
183  static void delete_infile();
184 
185 
187  static void open_outfile();
188 
195  static void open_output();
196 
200  static void make_spinfile();
201 
208  static void make_tempfile();
209 
216  static void make_backup_name(std::string const & filename);
217 
219  static std::string _in_filename_;
221  static std::ostream * _output_;
223  static std::istream * _input_;
225  static std::filebuf _infile_;
229  static std::string _out_filename_;
231  static std::string _bak_filename_;
233  static std::filebuf _outfile_;
235  static std::string _spin_dir_;
237  static std::string _spin_prefix_;
238 };
239 
240 #endif /* EOF*/
static FILE * open_file(std::string const &file, const char *mode)
Open a named file for reading or writing.
static char const *const _stdin_name_
Nominal filename for the standard input stream.
Definition: io.h:55
static void make_tempfile()
Create a temporary file to which output will be written.
Definition: io.cpp:112
Manages input and output file handling.
Definition: io.h:52
static void close_input()
Close the current source file.
static fs::permissions _in_out_permissions_
File permissions mask of input file, in case file is replaced.
Definition: io.h:227
static void open_output()
Open an output stream for the current input file.
Definition: io.cpp:165
static void top()
Reinitialize the module.
Definition: io.cpp:65
static void close(unsigned error)
Finalise the current pairing of source input and processed output, if any.
Definition: io.cpp:179
static void make_backup_name(std::string const &filename)
Generate a filename for backing up an input file.
Definition: io.cpp:136
static std::string in_file_name()
Get the name of the current source file.
Definition: io.h:105
static std::string const & spin_dir()
Get the name of operative spin directory.
Definition: io.h:135
static std::istream * _input_
The input stream.
Definition: io.h:223
static std::string read_filename()
Read the name of a source file from stdin.
Definition: io.cpp:78
static std::string _spin_prefix_
Path prefix assumed to match the spin directory.
Definition: io.h:237
static void set_spin_prefix(char const *optarg)
Set a path prefix (of input files) that will be assumed to match the name of the spin directory...
Definition: io.cpp:232
static std::ostream * _output_
The output stream.
Definition: io.h:221
static std::filebuf _outfile_
The output file.
Definition: io.h:233
static void make_spinfile()
Create an output file in the spin directory corresponding to an input file.
Definition: io.cpp:237
static std::string _out_filename_
Current output filename, if needed.
Definition: io.h:229
static void open_outfile()
Open the output file.
Definition: io.cpp:155
An error diagnostic.
static bool spin()
Say whether there is any spin directory.
Definition: io.h:140
static void delete_infile()
Delete the current input source file.
Definition: io.cpp:70
static std::string _spin_dir_
Name of directory in which to output a spin.
Definition: io.h:235
static std::ostream * output()
Get a pointer to the output stream.
Definition: io.h:110
static void set_spin_dir(char const *optarg)
Set the directory in which to output a spin.
Definition: io.cpp:227
static std::string _in_filename_
The name of the current source file.
Definition: io.h:219
static void replace_infile()
Replace the current input source file with the temporary output file.
Definition: io.cpp:123
static void backup_infile()
Backup the current input source file.
Definition: io.cpp:144
static void open(std::string const &fname)
Open an input file and the appropriate output file.
Definition: io.cpp:202
char * optarg
Argument to an option parsed by getopt_long()
Definition: get_options.cpp:49
static std::filebuf _infile_
The input file.
Definition: io.h:225
static std::string _bak_filename_
Backup filename, if needed.
Definition: io.h:231
static std::istream * input()
Get a pointer to the input stream.
Definition: io.h:115
int permissions
Type of file permissions mask.
Definition: filesys.h:147