coan  6.0.1
A C/C++ Configuration Analyzer
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
io Struct Reference

Manages input and output file handling. More...

#include <io.h>

Static Public Member Functions

static std::string read_filename ()
 Read the name of a source file from stdin. More...
 
static FILE * open_file (std::string const &file, const char *mode)
 Open a named file for reading or writing. More...
 
static void open (std::string const &fname)
 Open an input file and the appropriate output file. More...
 
static void close (unsigned error)
 Finalise the current pairing of source input and processed output, if any. More...
 
static void close_input ()
 Close the current source file.
 
static void top ()
 Reinitialize the module.
 
static std::string in_file_name ()
 Get the name of the current source file.
 
static std::ostream * output ()
 Get a pointer to the output stream.
 
static std::istream * input ()
 Get a pointer to the input stream.
 
static void set_spin_dir (char const *optarg)
 Set the directory in which to output a spin. More...
 
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. More...
 
static std::string const & spin_dir ()
 Get the name of operative spin directory.
 
static bool spin ()
 Say whether there is any spin directory.
 

Static Public Attributes

static char const *const _stdin_name_ = "[stdin]"
 Nominal filename for the standard input stream.
 

Static Private Member Functions

static void replace_infile ()
 Replace the current input source file with the temporary output file. More...
 
static void backup_infile (const char *filename)
 Generate a backup name for the current input source file. More...
 
static void backup_infile ()
 Backup the current input source file. More...
 
static void delete_infile ()
 Delete the current input source file. More...
 
static void open_outfile ()
 Open the output file.
 
static void open_output ()
 Open an output stream for the current input file. More...
 
static void make_spinfile ()
 Create an output file in the spin directory corresponding to an input file.
 
static void make_tempfile ()
 Create a temporary file to which output will be written. More...
 
static void make_backup_name (std::string const &filename)
 Generate a filename for backing up an input file. More...
 

Static Private Attributes

static std::string _in_filename_
 The name of the current source file.
 
static std::ostream * _output_
 The output stream.
 
static std::istream * _input_
 The input stream.
 
static std::filebuf _infile_
 The input file.
 
static fs::permissions _in_out_permissions_
 File permissions mask of input file, in case file is replaced.
 
static std::string _out_filename_
 Current output filename, if needed.
 
static std::string _bak_filename_
 Backup filename, if needed.
 
static std::filebuf _outfile_
 The output file.
 
static std::string _spin_dir_
 Name of directory in which to output a spin.
 
static std::string _spin_prefix_
 Path prefix assumed to match the spin directory.
 

Detailed Description

Manages input and output file handling.

Definition at line 52 of file io.h.

Member Function Documentation

static void io::backup_infile ( const char *  filename)
staticprivate

Generate a backup name for the current input source file.

Generate a backup name for the current input source file, when the --replace and --backup option are in force.

The backup filename is saved in static storage.

Parameters
filenameThe name of the source file to be backed up.
void io::backup_infile ( )
staticprivate

Backup the current input source file.

Backup the current input source file when the --backup option is in force.

The current source file is renamed with a generated backup filename.

Definition at line 144 of file io.cpp.

void io::close ( unsigned  error)
static

Finalise the current pairing of source input and processed output, if any.

Parameters
error0 if no errors were raised in processing the input file that is to be closed, else the reason code of the error that aborted processing.

If a file is associated with either of these streams, it is closed. The output file replaces the input file, if error == 0 and the --replace option is in force, and is also backed up beforehand, if the --backup option is in force. If the function is called before any input has been opened it is a no-op

Definition at line 179 of file io.cpp.

void io::delete_infile ( )
staticprivate

Delete the current input source file.

Delete the current input source file, preparatory to replacing it with the corresponding output file.

Definition at line 70 of file io.cpp.

void io::make_backup_name ( std::string const &  filename)
staticprivate

Generate a filename for backing up an input file.

Generate a filename for backing up an input file when --replace and --backup are in effect.

Parameters
filenameThe name of the input file to be backed up.

Definition at line 136 of file io.cpp.

void io::make_tempfile ( )
staticprivate

Create a temporary file to which output will be written.

Create a temporary file to which output will be written preparatory to replacing the input file with this output when --replace is in effect.

Definition at line 112 of file io.cpp.

void io::open ( std::string const &  fname)
static

Open an input file and the appropriate output file.

Parameters
fnameThe name of the input file to open. An empty string, "", denotes the standard input

Definition at line 202 of file io.cpp.

static FILE* io::open_file ( std::string const &  file,
const char *  mode 
)
static

Open a named file for reading or writing.

Parameters
fileThe name of the file to be opened
modeThe read or write mode in which to open the file, "r" or "w".
Returns
Handle to opened file on success, else nullptr.
void io::open_output ( )
staticprivate

Open an output stream for the current input file.

The output stream is cout unless input source files are to be replaced with output. Otherwise the output stream is opened on a temporary output file.

Definition at line 165 of file io.cpp.

string io::read_filename ( )
static

Read the name of a source file from stdin.

Filenames may contain spaces if quoted.

Returns
A pointer to the source filename in static storage, if a valid filename is read; nullptr if no filename is read.

Definition at line 78 of file io.cpp.

void io::replace_infile ( )
staticprivate

Replace the current input source file with the temporary output file.

Replace the current input source file with the temporary output file, when the --replace option is in force.

The input source file has either been deleted or renamed to a backup when this function is called, depending on whether the --backup option is in force.

Definition at line 123 of file io.cpp.

void io::set_spin_dir ( char const *  optarg)
static

Set the directory in which to output a spin.

Parameters
optargThe commandline option specifing the spin directory name. The function stores the absolute path of the spin directory.

Definition at line 227 of file io.cpp.

void io::set_spin_prefix ( char const *  optarg)
static

Set a path prefix (of input files) that will be assumed to match the name of the spin directory.

Parameters
optargThe commandline option specifing the spin prefix.

The function stores the absolute path of the spin prefix.

Definition at line 232 of file io.cpp.


The documentation for this struct was generated from the following files: