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 << "LyX: lastfiles: too many files\n"
45 "\tdefault (=" << int(DEFAULTFILES) // int() only because of anon enum
47 num_files = DEFAULTFILES;
52 void LastFiles::readFile(string const & filename)
54 // we will not complain if we can't find filename nor will
55 // we issue a warning. Lgb.
56 LyXLex lex(0, 0); /* LyXLex should be changed
57 * to allow constructor with
61 lex.setFile(filename);
63 if (!lex.IsOK()) return;
69 while (lex.IsOK() && !error && i < num_files) {
71 case LyXLex::LEX_FEOF:
75 tmp = lex.GetString();
76 // Check if the file exist
78 if (!(fileInfo.newFile(tmp).exist() &&
79 fileInfo.isRegular()))
80 break; // the file does not exist
90 void LastFiles::writeFile(string const & filename) const
92 FilePtr fd(filename, FilePtr::write);
94 for (int i = 0; i < num_files; i++) {
95 if (!files[i].empty())
96 fprintf(fd, "\"%s\"\n", files[i].c_str());
99 lyxerr << "LyX: Warning: unable to save LastFiles: "
104 void LastFiles::newFile(string const & file)
107 // Find this file in list. If not in list, point to last entry
108 for(n = 0; n < (num_files - 1); n++)
109 if(files[n] == file) break;
111 for(int i = n; i >= 1; i--)
112 files[i] = files[i - 1];