1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
7 * Copyright (C) 1995-1998 The LyX Team.
9 *======================================================*/
15 #pragma implementation
18 //#include "definitions.h"
21 #include "lastfiles.h"
22 #include "filetools.h"
25 // $Id: lastfiles.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $
27 #if !defined(lint) && !defined(WITH_WARNINGS)
28 static char vcid[] = "$Id: lastfiles.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $";
31 LastFiles::LastFiles(LString const & filename, bool st, char num)
34 setNumberOfFiles(num);
35 files = new LString[num_files];
40 LastFiles::~LastFiles()
46 void LastFiles::setNumberOfFiles(char no)
48 if (1 <= no && no <= ABSOLUTEMAXLASTFILES)
51 lyxerr.print(LString("LyX: lastfiles: too many files\n"
52 "\tdefault (=") + int(DEFAULTFILES) + ") used.");
53 num_files = DEFAULTFILES;
58 void LastFiles::readFile(LString const & filename)
60 // we will not complain if we can't find filename nor will
61 // we issue a warning. Lgb.
62 LyXLex lex(NULL, 0); /* LyXLex should be changed
63 * to allow constructor with
67 lex.setFile(filename);
69 if (!lex.IsOK()) return;
75 while (lex.IsOK() && !error && i < num_files) {
77 case LyXLex::LEX_FEOF:
81 tmp = lex.GetString();
82 // Check if the file exist
84 if (!(fileInfo.newFile(tmp).exist() &&
85 fileInfo.isRegular()))
86 break; // the file does not exist
96 void LastFiles::writeFile(LString const & filename) const
98 FilePtr fd(filename, FilePtr::write);
100 for (int i = 0; i < num_files; i++) {
101 if (!files[i].empty())
102 fprintf(fd, "\"%s\"\n", files[i].c_str());
105 lyxerr.print("LyX: Warning: unable to save LastFiles: "
110 void LastFiles::newFile(LString const & file)
113 // Find this file in list. If not in list, point to last entry
114 for(n = 0; n < (num_files - 1); n++)
115 if(files[n] == file) break;
117 for(int i = n; i >= 1; i--)
118 files[i] = files[i - 1];