1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
13 #include "lastfiles.h"
16 #include "support/FileInfo.h"
29 using std::ostream_iterator;
32 LastFiles::LastFiles(string const & filename, bool st, unsigned int num)
35 setNumberOfFiles(num);
40 void LastFiles::setNumberOfFiles(unsigned int no)
42 if (0 < no && no <= ABSOLUTEMAXLASTFILES)
45 lyxerr << "LyX: lastfiles: too many files\n"
46 "\tdefault (=" << int(DEFAULTFILES)
48 num_files = DEFAULTFILES;
53 void LastFiles::readFile(string const & filename)
55 // we will not complain if we can't find filename nor will
56 // we issue a warning. (Lgb)
57 ifstream ifs(filename.c_str());
61 while (getline(ifs, tmp) && files.size() < num_files) {
63 if (!(fileInfo.newFile(tmp).exist() &&
64 fileInfo.isRegular()))
72 void LastFiles::writeFile(string const & filename) const
74 ofstream ofs(filename.c_str());
76 copy(files.begin(), files.end(),
77 ostream_iterator<string>(ofs, "\n"));
79 lyxerr << "LyX: Warning: unable to save LastFiles: "
84 void LastFiles::newFile(string const & file)
86 // If file already exist, delete it and reinsert at front.
87 Files::iterator it = find(files.begin(), files.end(), file);
88 if (it != files.end())
90 files.push_front(file);
91 if (files.size() > num_files)
96 string const LastFiles::operator[](unsigned int i) const