67 _in_filename_.resize(0);
72 if (
remove(_in_filename_.c_str())) {
74 "Cannot remove file \"" << _in_filename_ <<
'\"' <<
emit();
85 for ( ; ch != EOF && isspace(ch); ch = getchar()) {};
91 for (ch = getchar() ; ch != EOF && ch !=
'\"'; ch = getchar()) {
92 if (isspace(ch) && ch !=
' ') {
94 "Illegal whitespace in _input_ filename: \""
95 << filename <<
"..." <<
emit();
101 "A quoted _input_ filename is unterminated: \""
102 << filename <<
"..." <<
emit();
105 for ( ; ch != EOF && !isspace(ch); ch = getchar()) {
118 if (_out_filename_.empty()) {
125 if (rename(_out_filename_.c_str(),_in_filename_.c_str())) {
127 "Cannot rename file \"" << _out_filename_ <<
"\" as \""
128 << _in_filename_ <<
'\"' <<
emit();
129 }
else if (_in_out_permissions_ != -1) {
130 _in_out_permissions_ =
132 assert(_in_out_permissions_ != -1);
138 _bak_filename_ = filename;
146 make_backup_name(_in_filename_);
147 if (rename(_in_filename_.c_str(),
148 _bak_filename_.c_str())) {
150 "Cannot rename file \"" << _in_filename_ <<
"\" as \""
151 << _bak_filename_ <<
'\"' <<
emit();
157 _outfile_.open(_out_filename_.c_str(),ios_base::out);
158 if (!_outfile_.is_open()) {
160 _out_filename_ <<
" for writing" <<
emit();
162 _output_ =
new ostream(&_outfile_);
175 _output_ =
new ostream(cout.rdbuf());
181 delete _input_, _input_ =
nullptr;
182 delete _output_, _output_ =
nullptr;
204 _in_filename_ = fname;
206 if (fname != _stdin_name_) {
207 _in_out_permissions_ =
209 _infile_.open(fname.c_str(),ios_base::in);
210 if (!_infile_.is_open()) {
212 _in_filename_ <<
" for reading" <<
emit();
214 _input_ =
new istream(&_infile_);
215 assert(_input_->good());
217 _input_ =
new istream(cin.rdbuf());
239 path_t spin_filename(_spin_dir_);
240 path_t in_filename(_in_filename_);
242 if (_spin_prefix_.empty()) {
243 spin_filename += in_filename.
segment(1);
245 static path_t prefix(_spin_prefix_);
248 size_t parts = spin_filename.
elements();
249 string dir = spin_filename.
segment(0,parts - 1);
251 _out_filename_ = spin_filename.
str();
abend_msg< 11 > abend_no_tempfile
Report cannot create a temporary file.
abend_msg< 8 > abend_illegal_filename
Report invalid filename input.
static char const *const _stdin_name_
Nominal filename for the standard input stream.
abend_msg< 3 > abend_eof_in_filename
Report end of input encountered while reading a quoted filename. a closing quotation was not found...
static void make_tempfile()
Create a temporary file to which output will be written.
permissions get_permissions(std::string const &filename)
void make_dir(std::string const &abs_path, bool recursive=true)
Create a directory given an absolute path name.
static fs::permissions _in_out_permissions_
File permissions mask of input file, in case file is replaced.
static void open_output()
Open an output stream for the current input file.
std::string segment(size_t start=0, size_t len=std::string::npos) const
Get a sub-sequence of the path's elements as a string.
static void top()
Reinitialize the module.
abend_msg< 1 > abend_cant_open_output
Report cannot open an output file.
bool is_absolute(std::string pathname)
Say whether a filename is absolute or relative.
std::string const & str() const
Get the path as a string.
static int exitcode()
Convert the internal exit status to an exit code for exit().
static void close(unsigned error)
Finalise the current pairing of source input and processed output, if any.
void pop_back()
Remove the last element of the path, if any.
static void make_backup_name(std::string const &filename)
Generate a filename for backing up an input file.
static std::istream * _input_
The input stream.
static std::string read_filename()
Read the name of a source file from stdin.
static std::string _spin_prefix_
Path prefix assumed to match the spin directory.
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...
static bool list_once_per_file()
Do we report the listed items just once per input file?
static std::ostream * _output_
The output stream.
static std::filebuf _outfile_
The output file.
static void top()
Reinitialize the class static state.
The tag class is inserted in a diagnostic_base to tell it to emit itself.
abend_msg< 2 > abend_cant_open_input
Report cannot open an input file.
static void make_spinfile()
Create an output file in the spin directory corresponding to an input file.
static std::string _out_filename_
Current output filename, if needed.
static void per_file_init()
Delete all transient symbols from the symbol table.
static void open_outfile()
Open the output file.
size_t elements() const
Get the number of elements in the path
static bool keep_going()
Shall we continue to process input files after errors?
void push_back(std::string const &str)
Append a string to the path.
static void delete_infile()
Delete the current input source file.
static bool replace()
Do we replace input files with output files?
static std::string _spin_dir_
Name of directory in which to output a spin.
int set_permissions(std::string const &filename, permissions p)
static void set_spin_dir(char const *optarg)
Set the directory in which to output a spin.
static void erase_all()
Forget all directives table used by the operative command.
std::string abs_path(std::string const &filename)
Get the absolute pathname for a filename.
static std::string const & backup_suffix()
Get the file backup name suffix.
std::string real_path(std::string const &relname)
Get the absolute real pathname of a file or directory name.
static std::string _in_filename_
The name of the current source file.
static void replace_infile()
Replace the current input source file with the temporary output file.
obj_type_t obj_type(std::string const &name)
Get the type of the object putatively designated by a filename.
static void backup_infile()
Backup the current input source file.
std::string tempname(std::string const &format)
Create a tempory filename from a template.
static void open(std::string const &fname)
Open an input file and the appropriate output file.
abend_msg< 9 > abend_cant_delete_file
Report failure to delete a file.
char * optarg
Argument to an option parsed by getopt_long()
abend_msg< 10 > abend_cant_rename_file
Report failure to rename a file.
static std::filebuf _infile_
The input file.
static std::string _bak_filename_
Backup filename, if needed.
int permissions
Type of file permissions mask.