diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/lintex/cxx |
Initial commit
Diffstat (limited to 'support/lintex/cxx')
-rw-r--r-- | support/lintex/cxx/Makefile | 41 | ||||
-rw-r--r-- | support/lintex/cxx/cleandir.cxx | 230 | ||||
-rw-r--r-- | support/lintex/cxx/cleandir.hh | 21 | ||||
-rw-r--r-- | support/lintex/cxx/cleanup.cxx | 98 | ||||
-rw-r--r-- | support/lintex/cxx/cleanup.hh | 23 | ||||
-rw-r--r-- | support/lintex/cxx/file.cxx | 70 | ||||
-rw-r--r-- | support/lintex/cxx/file.hh | 108 | ||||
-rw-r--r-- | support/lintex/cxx/ltx.cxx | 166 | ||||
-rw-r--r-- | support/lintex/cxx/ltx.hh | 41 |
9 files changed, 798 insertions, 0 deletions
diff --git a/support/lintex/cxx/Makefile b/support/lintex/cxx/Makefile new file mode 100644 index 0000000000..c53b349da6 --- /dev/null +++ b/support/lintex/cxx/Makefile @@ -0,0 +1,41 @@ +# Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +# Work: University of Padova - Department of Physics +# Via F. Marzolo, 8 - 35131 PADOVA - Italy +# Phone: +39 (049) 827-7216 FAX: +39 (049) 827-7102 +# EMail: loreti@pd.infn.it +# WWW: http://www.pd.infn.it/~loreti/mlo.html +# +# $Id: Makefile,v 1.9 2005/01/21 08:16:48 loreti Exp $ +# +###################################################### + +.PHONY: clean + +CXX = g++ +#CXXFLAGS = -std=c++98 -pedantic -W -Wall -g -DDEBUG +CXXFLAGS = -std=c++98 -pedantic -W -Wall -O2 + +#CXX = KCC +#CXXFLAGS = -O -DDEBUG +#CXXFLAGS = -O + +LDFLAGS = + +ltx: ltx.o cleandir.o cleanup.o file.o + $(CXX) $(LDFLAGS) -o $@ ltx.o cleandir.o cleanup.o file.o + +ltx.o: ltx.cxx ltx.hh cleandir.hh + $(CXX) $(CXXFLAGS) -o $@ -c ltx.cxx + +cleandir.o: cleandir.cxx cleandir.hh cleanup.hh + $(CXX) $(CXXFLAGS) -o $@ -c cleandir.cxx + +cleanup.o: cleanup.cxx cleanup.hh file.hh + $(CXX) $(CXXFLAGS) -o $@ -c cleanup.cxx + +file.o: file.cxx file.hh + $(CXX) $(CXXFLAGS) -o $@ -c file.cxx + +clean: + -rm *~ *.o ltx + -if [ -d ti_files ]; then rm ti_files/* && rmdir ti_files; fi diff --git a/support/lintex/cxx/cleandir.cxx b/support/lintex/cxx/cleandir.cxx new file mode 100644 index 0000000000..799f702c35 --- /dev/null +++ b/support/lintex/cxx/cleandir.cxx @@ -0,0 +1,230 @@ +// Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +// Work: University of Padova - Department of Physics +// Via F. Marzolo, 8 - 35131 PADOVA - Italy +// Phone: +39 (049) 827-7216 FAX: +39 (049) 827-7102 +// EMail: loreti@pd.infn.it +// WWW: http://www.pd.infn.it/~loreti/mlo.html +// +// ------------------------------------------------------------------- +// +// $Id: cleandir.cxx,v 1.11 2002/09/25 12:19:41 loreti Exp $ +// +// ------------------------------------------------------------------- + +#include <algorithm> +#include <iterator> +#include <vector> +#include <cstring> +#include "ltx.hh" // Includes: functional, iostream, string +#include "cleandir.hh" // Includes: string +#include "cleanup.hh" // Includes: string +#include "file.hh" // Includes: list, map, string, utility, ctime + +extern "C" { + #include <dirent.h> + #include <sys/stat.h> + #include <sys/types.h> +} + +using std::cerr; +using std::cout; +using std::strcmp; +using std::string; + +// Local variables + +namespace { + // In "re" are defined the extensions of the files relevant for + // LaTeX; ".tex" is missing, being handled separately. THIS ARRAY + // MUST BE SORTED IN ASCENDING ORDER. + + const char * re[] = { + ".aux", ".dvi", ".idx", ".ilg", ".ind", + ".lof", ".log", ".lot", ".pdf", ".ps", + ".toc" + }; + const size_t nRE = sizeof(re) / sizeof(re[0]); + std::vector<string> texExts(re, re + nRE); + + const string tex(".tex"); + const string dot("."); + + const size_t filename_max = 256; +} + +// Local functions (declarations) + +namespace { + void check_file(const string &, const time_t, currDir &); +} + +// Code + +void scan_dir( + const string & name +) { + // Scans the directory "name", building the related instantiation of + // the class "currDir" containing all the informations for the + // relevant files; then calls "clean_dir" to perform the actual + // cleanup. If the "-r" options has been specified, recurses over + // all the directories under the current one. + +#if defined(DEBUG) + static bool firstTime(true); + + if (firstTime) { + cout << "--------------------Relevant extensions (" + << nRE << ")\n"; + copy(texExts.begin(), texExts.end(), + std::ostream_iterator<string>(cout, " ")); + cout << std::endl; + firstTime = false; + } + + cout << "--------------------scan_dir called for \"" + << name << "\"\n"; +#endif // DEBUG + + DIR * pDir; + + if ((pDir = opendir( name.c_str() )) != 0) { + + string fullName(name); + if (*(fullName.rbegin()) != '/') fullName.append("/"); + + currDir thisDir(fullName); + std::list<string> subDirs; + struct dirent * pDe; + + // Reads every file: skips null inodes (already deleted + // files), and the two special files "." and ".." . + + while ((pDe = readdir(pDir)) != 0) { + if (pDe->d_ino == 0) continue; + +#if defined(DEBUG) + cout << "Next file: " << pDe->d_name << " - "; +#endif // DEBUG + + if (strcmp(pDe->d_name, ".") == 0) { +#if defined(DEBUG) + cout << "skipped\n"; +#endif // DEBUG + continue; + } + + if (strcmp(pDe->d_name, "..") == 0) { +#if defined(DEBUG) + cout << "skipped\n"; +#endif // DEBUG + continue; + } + + // Gets the file related informations with stat(2) (we need file + // type and modification time). If the call to "stat" fails, + // the file is not considered. + + char tName[filename_max]; + std::strcpy(tName, fullName.c_str()); + std::strcat(tName, pDe->d_name); + + struct stat sStat; + + if (stat(tName, &sStat) != 0) { +#if defined(DEBUG) + cout << "got error from stat()\n"; +#else + cerr << ltx::progname << ": error calling stat(" + << tName << ")\n"; +#endif // DEBUG + + } else { + if (S_ISDIR(sStat.st_mode) != 0) { +#if defined(DEBUG) + cout << "is a directory\n"; +#endif // DEBUG + + // If needed, push the subdirectory names in the dedicated + // list, for future recursion; plain files are handled by + // the local procedure check_file(). + + if (ltx::recurse) subDirs.push_back(tName); + + } else { + check_file(pDe->d_name, sStat.st_mtime, thisDir); + } + } + } + + // Looks if some cleanup has to be performed + + clean_files(thisDir); + + if (ltx::recurse) { + for_each(subDirs.begin(), subDirs.end(), std::ptr_fun(scan_dir)); + } + + closedir(pDir); + } else { + cerr << ltx::progname << ": \"" << name + << "\" could not be opened (or is not a directory)\n"; + } +} + +namespace { + void check_file( + const string & name, + const time_t mTime, + currDir & CDir + ) { + // - If the file "name" matches the trailing string identifying + // backup editor files, is removed; + // - if it matches a relevant extension, is inserted in the + // "currDir" instance. + + string::size_type where; + + if (ltx::lTrailEd > 0) { + if ((where = name.rfind(ltx::trailEd)) != string::npos) { + if ((where + ltx::lTrailEd) == name.size()) { + #if defined(DEBUG) + cout << "matches the default editor extension\n"; + #endif // DEBUG + nuke(CDir.getName(), name); + return; + } + } + } + + // Breaks the file name in "basename" and "extension"; and checks + // the latter against the known ones (".tex" files are handled + // separately). + + if ((where = name.find_last_of(dot)) != string::npos) { + string extension = name.substr(where); + string basename = name.substr(0, where); + fileFamily & fF = CDir.getFileFamily(basename); + + if (extension == tex) { + fF.addExtension(mTime, 0); + #if defined(DEBUG) + cout << "inserted\n"; + #endif // DEBUG + + } else if (binary_search(texExts.begin(), texExts.end(), extension)) { + fF.addExtension(mTime, &extension); + #if defined(DEBUG) + cout << "extension " << extension << " - inserted\n"; + } else { + cout << "extension not relevant\n"; + #endif // DEBUG + + } + + #if defined(DEBUG) + } else { + cout << "no extension\n"; + #endif // DEBUG + } + } +} diff --git a/support/lintex/cxx/cleandir.hh b/support/lintex/cxx/cleandir.hh new file mode 100644 index 0000000000..3c29d3a012 --- /dev/null +++ b/support/lintex/cxx/cleandir.hh @@ -0,0 +1,21 @@ +// Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +// Work: University of Padova - Department of Physics +// Via F. Marzolo, 8 - 35131 PADOVA - Italy +// Phone: +39 (049) 827-7216 FAX: +39 (049) 827-7102 +// EMail: loreti@pd.infn.it +// WWW: http://www.pd.infn.it/~loreti/mlo.html +// +// ------------------------------------------------------------------- +// +// $Id: cleandir.hh,v 1.1 2001/01/22 10:43:43 loreti Exp $ +// +// ------------------------------------------------------------------- + +#ifndef CLEANDIR_H_ +#define CLEANDIR_H_ + +#include <string> + +void scan_dir(const std::string &); + +#endif // CLEANDIR_H_ diff --git a/support/lintex/cxx/cleanup.cxx b/support/lintex/cxx/cleanup.cxx new file mode 100644 index 0000000000..f930490757 --- /dev/null +++ b/support/lintex/cxx/cleanup.cxx @@ -0,0 +1,98 @@ +// Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +// Work: University of Padova - Department of Physics +// Via F. Marzolo, 8 - 35131 PADOVA - Italy +// Phone: +39 (049) 827-7216 FAX: +39 (049) 827-7102 +// EMail: loreti@pd.infn.it +// WWW: http://www.pd.infn.it/~loreti/mlo.html +// +// ------------------------------------------------------------------- +// +// $Id: cleanup.cxx,v 1.8 2005/01/21 08:16:49 loreti Exp $ +// +// ------------------------------------------------------------------- + +#include <cstdio> +#include <cctype> +#include "ltx.hh" // Includes: functional, iostream, string +#include "file.hh" // Includes: list, map, string, utility, ctime +#include "cleanup.hh" // Includes: string + +using std::cin; +using std::cout; +using std::string; + +namespace { + const int answerLength(64); +} + +void clean_files( + const currDir & dir +) { + // Loops over all the file families stored in "dir", then loops over + // all the extensions in this file family; if a ".tex" file with a + // modification time former than the modification time of the target + // file exists, the file is removed. + + fileCollection::const_iterator iter, iterEnd = dir.end(); + + for (iter = dir.begin(); iter != iterEnd; iter++) { + + const fileFamily * pFF = iter->second; + std::list<extInfo>::const_iterator jter; + std::list<extInfo>::const_iterator jterEnd = pFF->end(); + + for (jter = pFF->begin(); jter != jterEnd; jter++) { + + string fullName = iter->first + jter->first; + + if (pFF->hasTex()) { + if (difftime(jter->second, pFF->texMtime()) > 0.0) { + + if (ltx::confirm) { + char answer[answerLength], c; + + do { + cout << "Remove " << dir.getName() + << fullName << " (y|n) ? "; + cin.get(answer, answerLength); + if (cin.gcount() < answerLength-1 ) { + cin.ignore(); + } + c = tolower(static_cast<unsigned char>(answer[0])); + } while (c != 'y' && c != 'n'); + if (c != 'y') continue; + } + nuke(dir.getName(), fullName); + + } else { + cout << dir.getName() << fullName + << " not removed; " << iter->first + << ".tex is newer\n"; + } + } else { + cout << dir.getName() << fullName + << " not removed; " << iter->first + << ".tex does not exist\n"; + } + } + } +} + +void nuke( + const string & dirName, + const string & fileName +) { + // Removes the file "fileName" from the directory "dirName". If the + // preprocessor symbol 'DEBUG' is defined, the file is not actually + // removed: but a message is printed on the standard output stream, + // informing that the Finger Of Death has been raised to him. + + string target = dirName + fileName; + +#if defined(DEBUG) + cout << "FOD: " << target << std::endl; +#else + remove(target.c_str()); + cout << target << " has been removed.\n"; +#endif // DEBUG +} diff --git a/support/lintex/cxx/cleanup.hh b/support/lintex/cxx/cleanup.hh new file mode 100644 index 0000000000..b692dd8f14 --- /dev/null +++ b/support/lintex/cxx/cleanup.hh @@ -0,0 +1,23 @@ +// Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +// Work: University of Padova - Department of Physics +// Via F. Marzolo, 8 - 35131 PADOVA - Italy +// Phone: +39 (049) 827-7216 FAX: +39 (049) 827-7102 +// EMail: loreti@pd.infn.it +// WWW: http://www.pd.infn.it/~loreti/mlo.html +// +// ------------------------------------------------------------------- +// +// $Id: cleanup.hh,v 1.2 2002/09/12 10:15:44 loreti Exp $ +// +// ------------------------------------------------------------------- + +#ifndef CLEANUP_H_ +#define CLEANUP_H_ + +#include <string> +#include "file.hh" + +void clean_files(const currDir &); +void nuke(const std::string &, const std::string &); + +#endif // CLEANUP_H_ diff --git a/support/lintex/cxx/file.cxx b/support/lintex/cxx/file.cxx new file mode 100644 index 0000000000..35c9362385 --- /dev/null +++ b/support/lintex/cxx/file.cxx @@ -0,0 +1,70 @@ +// Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +// Work: University of Padova - Department of Physics +// Via F. Marzolo, 8 - 35131 PADOVA - Italy +// Phone: +39 (049) 827-7216 FAX: +39 (049) 827-7102 +// EMail: loreti@pd.infn.it +// WWW: http://www.pd.infn.it/~loreti/mlo.html +// +// ------------------------------------------------------------------- +// +// $Id: file.cxx,v 1.7 2002/09/12 10:15:44 loreti Exp $ +// +// ------------------------------------------------------------------- + +#include <algorithm> +#include <functional> +#include <iostream> +#include "file.hh" // Includes: list, map, string, utility, ctime + +using std::string; + +// Methods for the class fileFamily + +void fileFamily::addExtension( + time_t mTime, + const string * pExtName +) { + // Insert the file informations in a fileFamily. "mTime" is the + // modification time, "pExtName" points to the file extension or is + // NULL for an extension of ".tex" . + + if (pExtName) { + _extInfo.push_back( std::make_pair(*pExtName, mTime) ); + } else { + _hasTex = true; + _texMtime = mTime; + } +} + +// Auxiliary function object for currDir objects + +struct releaseFileFamily + : public std::unary_function<fileCollectionElement, void> { + void operator() (fileCollectionElement & p) { + delete p.second; } +}; + +// Methods for the class currDir + +currDir::~currDir() +{ + for_each(_dirContent.begin(), _dirContent.end(), releaseFileFamily()); +} + +fileFamily & currDir::getFileFamily( + const string & base +) { + // Gets the file family related to the basename "base". If this is + // the first file found, a fileFamily instance is allocated with + // "operator new" (and will be later deleted in the currDir class + // destructor). + + fileFamily * retval = _dirContent[ base ]; + + if (retval == 0) { + retval = new fileFamily; + _dirContent[ base ] = retval; + } + + return *retval; +} diff --git a/support/lintex/cxx/file.hh b/support/lintex/cxx/file.hh new file mode 100644 index 0000000000..d395d74f2a --- /dev/null +++ b/support/lintex/cxx/file.hh @@ -0,0 +1,108 @@ +// Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +// Work: University of Padova - Department of Physics +// Via F. Marzolo, 8 - 35131 PADOVA - Italy +// Phone: +39 (049) 827-7216 FAX: +39 (049) 827-7102 +// EMail: loreti@pd.infn.it +// WWW: http://www.pd.infn.it/~loreti/mlo.html +// +// ------------------------------------------------------------------- +// +// $Id: file.hh,v 1.3 2002/09/12 10:15:44 loreti Exp $ +// +// ------------------------------------------------------------------- + +#ifndef FILE_H_ +#define FILE_H_ + +#include <list> +#include <map> +#include <string> +#include <utility> +#include <ctime> + +// Classes for the handling of directories and files. +// +// - The files are abstracted as a basename, an extension and a +// modification time: the basename being defined as all the file +// name characters up to (but not including) the last "."; and the +// extension as the remainder. A file may have an empty basename or +// an empty extension. +// +// - A "file family" is a set of files having all the same basename +// and different extensions. In this context, an extension of +// ".tex" is considered 'special' and is managed separately; the +// class "fileFamily" actually contains informations about the +// existence of a .tex member and its modification time, plus a list +// of all the related files with different extensions. +// +// - For the file families, methods are provided to test for the +// existence of a .tex; to get its modification time; to add a +// member to the family; and to retrieve the list of all the +// extensions found. + +typedef std::pair< std::string, time_t > extInfo; + +class fileFamily { +private: + bool _hasTex; + time_t _texMtime; + std::list<extInfo> _extInfo; + + // Prevents any use of the copy constructor and of the assignment + // operator + + fileFamily & operator = (const fileFamily & rhs); + fileFamily(const fileFamily & rhs); + +public: + fileFamily() : _hasTex(false), _texMtime(0) {} + ~fileFamily() {} + + bool hasTex() const { return _hasTex; } + time_t texMtime() const { return _texMtime; } + + void addExtension(time_t, const std::string *); + + // Const-iterators over all the found extensions + + std::list<extInfo>::const_iterator begin() const { + return _extInfo.begin(); } + std::list<extInfo>::const_iterator end() const { + return _extInfo.end(); } +}; + +// A directory is seen as a directory name plus a collection of file +// families; that collection is implemented as an STL map. Methods +// are provided to add a file, to retrieve the directory name, and to +// iterate over the file families. + +typedef std::pair< const std::string, fileFamily * > fileCollectionElement; +typedef std::map< const std::string, fileFamily * > fileCollection; + +class currDir { +private: + std::string _name; + fileCollection _dirContent; + + // Prevents any use of the copy constructor and of the assignment + // operator + + currDir & operator = (const currDir & rhs); + currDir(const currDir & rhs); + +public: + currDir(const std::string & dirName) : _name(dirName) { } + ~currDir(); + + const std::string & getName() const { return _name; } + fileFamily & getFileFamily(const std::string &); + + // Iterators over all the found file families + + fileCollection::const_iterator begin() const { + return _dirContent.begin(); } + fileCollection::const_iterator end() const { + return _dirContent.end(); }; +}; + +#endif // FILE_H_ diff --git a/support/lintex/cxx/ltx.cxx b/support/lintex/cxx/ltx.cxx new file mode 100644 index 0000000000..a82de99fdb --- /dev/null +++ b/support/lintex/cxx/ltx.cxx @@ -0,0 +1,166 @@ +// Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +// Work: University of Padova - Department of Physics +// Via F. Marzolo, 8 - 35131 PADOVA - Italy +// Phone: +39 (049) 827-7216 FAX: +39 (049) 827-7102 +// EMail: loreti@pd.infn.it +// WWW: http://www.pd.infn.it/~loreti/mlo.html +// +// ------------------------------------------------------------------- +// +// C++ version of the program "lintex", born as an exercise +// in programming. +// +// $Id: ltx.cxx,v 1.9 2006/09/11 12:25:41 loreti Exp $ +// +// ------------------------------------------------------------------- + +#include <algorithm> +#include <list> +#include <cstring> +#include "ltx.hh" // Includes: functional, iostream, string +#include "cleandir.hh" // Includes: string + +extern "C" { + #include <getopt.h> + #include <unistd.h> +} + +using std::cout; +using std::endl; +using std::string; + +// Global variables (definition) + +namespace ltx { + string progname; + string trailEd("~"); + string::size_type lTrailEd; + bool confirm(false); + bool recurse(false); +} + +using namespace ltx; + +// Local procedures + +namespace { + char *basename(char *); + void syntax(); +} + +int main( + int argc, + char *argv[] +) { + std::list<string> targets; + + // Gets the executable name + + progname = argv[0] = basename(argv[0]); + + // Decodes the command line options and arguments + + char shortOpts[] = "irb::"; + struct option longOpts[] = { + {"interactive", no_argument, 0, 'i'}, + {"recursive", no_argument, 0, 'r'}, + {"backup", optional_argument, 0, 'b'}, + { 0, 0, 0, 0} + }; + + int c; + while ((c = getopt_long(argc, argv, shortOpts, longOpts, 0)) != -1) { + switch (c) { + case 'i': + confirm = true; + break; + + case 'r': + recurse = true; + break; + + case 'b': + trailEd = optarg ? optarg : ""; + break; + + case 'h': + case '?': + syntax(); + return 0; + + default: + std::cerr << "Can't happen: " << __FILE__ << ' ' + << __LINE__ << endl; + return 0; + } + } + + while (optind < argc) targets.push_back( argv[optind++] ); + + // Computes the length of the extension identifying the backup + // files, and, if no target directories were explicitly given, + // scans the current one. + + lTrailEd = trailEd.size(); + + if (targets.empty()) targets.push_back("."); + +#if defined(DEBUG) + cout << "--------------------Argument analysis\n"; + cout << "Confirm = " << confirm << endl; + cout << "Recurse = " << recurse << endl; + cout << "Trailing editor extension = \"" << trailEd + << "\" (length " << lTrailEd << ")\n"; + cout << "Target directories:\n"; + + for_each(targets.begin(), targets.end(), printBefore(" ")); +#endif // DEBUG + + // Scans in turn all the wanted directories + + for_each(targets.begin(), targets.end(), std::ptr_fun(scan_dir)); + + return 0; +} + +namespace { + char *basename( + char *pc + ) { + // Strips the (eventual) path name from the full file name pointed + // to by "pc"; if no file name is given, returns an empty string. + + char *p = std::strrchr(pc, '/'); + if (p == 0) return pc; + return ++p; + } + + void syntax() + { + cout << + "\nUsage:\t " << progname << " [options] [dir [dir ... ]]\n"; + cout << + "Purpose: removes TeX auxiliary files and editor backup files from " + "the\n"; + cout + << "\t given directories (default: from the current directory). TeX\n"; + cout << + "\t auxiliary files are actually removed only if their modification\n"; + cout << + "\t time is more recent than the one of the related TeX source file.\n"; + cout << + "Options: -i | --interactive : asks before removing files;\n"; + cout << + "\t -r | --recursive : scans recursively the given directories;\n"; + cout << + "\t -b=ext | --backup=ext : \"ext\" is the trailing string " + "identifying\n"; + cout << + "\t\t\t\t editor backup files.\n"; + cout << + "Notes:\t \"ext\" defaults to \"~\"; -b \"\" avoids the unconditional " + "cleanup of\n"; + cout << + "\t any special file.\n" << endl; + } +} diff --git a/support/lintex/cxx/ltx.hh b/support/lintex/cxx/ltx.hh new file mode 100644 index 0000000000..ce41519d57 --- /dev/null +++ b/support/lintex/cxx/ltx.hh @@ -0,0 +1,41 @@ +// Author: Maurizio Loreti, aka MLO or (HAM) I3NOO +// Work: University of Padova - Department of Physics +// Via F. Marzolo, 8 - 35131 PADOVA - Italy +// Phone: +39 (049) 827-7216 FAX: +39 (049) 827-7102 +// EMail: loreti@pd.infn.it +// WWW: http://www.pd.infn.it/~loreti/mlo.html +// +// ------------------------------------------------------------------- +// +// $Id: ltx.hh,v 1.2 2002/09/12 10:15:44 loreti Exp $ +// +// ------------------------------------------------------------------- + +#include <functional> +#include <iostream> +#include <string> + +// Auxiliary function object used to print (on an output stream) a +// leading text followed by the argument string and an end-of-line. + +class printBefore : public std::unary_function< std::string, void > { +private: + const std::string & _leader; + std::ostream & _os; + +public: + printBefore(const std::string & b = "", std::ostream & o = std::cout) + : _leader(b), _os(o) {} + ~printBefore() {} + void operator() (const std::string & s) { _os << _leader << s << std::endl; } +}; + +// Global variables (declaration) + +namespace ltx { + extern std::string progname; + extern std::string trailEd; + extern std::string::size_type lTrailEd; + extern bool confirm; + extern bool recurse; +} |