1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team.
9 * ======================================================*/
15 #pragma implementation
19 #include "support/FileInfo.h"
20 #include "lastfiles.h"
21 #include "support/filetools.h"
24 LastFiles::LastFiles(string const & filename, bool st, char num)
27 setNumberOfFiles(num);
28 files = new string[num_files];
33 LastFiles::~LastFiles()
39 void LastFiles::setNumberOfFiles(char no)
41 if (1 <= no && no <= ABSOLUTEMAXLASTFILES)
44 lyxerr.print(string("LyX: lastfiles: too many files\n"
45 "\tdefault (=") + tostr(DEFAULTFILES) + ") used.");
46 num_files = DEFAULTFILES;
51 void LastFiles::readFile(string const & filename)
53 // we will not complain if we can't find filename nor will
54 // we issue a warning. Lgb.
55 LyXLex lex(0, 0); /* LyXLex should be changed
56 * to allow constructor with
60 lex.setFile(filename);
62 if (!lex.IsOK()) return;
68 while (lex.IsOK() && !error && i < num_files) {
70 case LyXLex::LEX_FEOF:
74 tmp = lex.GetString();
75 // Check if the file exist
77 if (!(fileInfo.newFile(tmp).exist() &&
78 fileInfo.isRegular()))
79 break; // the file does not exist
89 void LastFiles::writeFile(string const & filename) const
91 FilePtr fd(filename, FilePtr::write);
93 for (int i = 0; i < num_files; i++) {
94 if (!files[i].empty())
95 fprintf(fd, "\"%s\"\n", files[i].c_str());
98 lyxerr.print("LyX: Warning: unable to save LastFiles: "
103 void LastFiles::newFile(string const & file)
106 // Find this file in list. If not in list, point to last entry
107 for(n = 0; n < (num_files - 1); n++)
108 if(files[n] == file) break;
110 for(int i = n; i >= 1; i--)
111 files[i] = files[i - 1];