1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-10-02 16:21:10 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
|
|
|
*
|
|
|
|
* ======================================================*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "lyxlex.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/FileInfo.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lastfiles.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "error.h"
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
LastFiles::LastFiles(string const & filename, bool st, char num)
|
1999-09-27 18:44:28 +00:00
|
|
|
: dostat(st)
|
|
|
|
{
|
|
|
|
setNumberOfFiles(num);
|
1999-10-02 16:21:10 +00:00
|
|
|
files = new string[num_files];
|
1999-09-27 18:44:28 +00:00
|
|
|
readFile(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LastFiles::~LastFiles()
|
|
|
|
{
|
|
|
|
delete[] files;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LastFiles::setNumberOfFiles(char no)
|
|
|
|
{
|
|
|
|
if (1 <= no && no <= ABSOLUTEMAXLASTFILES)
|
|
|
|
num_files = no;
|
|
|
|
else {
|
1999-10-02 16:21:10 +00:00
|
|
|
lyxerr.print(string("LyX: lastfiles: too many files\n"
|
|
|
|
"\tdefault (=") + tostr(DEFAULTFILES) + ") used.");
|
1999-09-27 18:44:28 +00:00
|
|
|
num_files = DEFAULTFILES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void LastFiles::readFile(string const & filename)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// we will not complain if we can't find filename nor will
|
|
|
|
// we issue a warning. Lgb.
|
1999-10-02 16:21:10 +00:00
|
|
|
LyXLex lex(0, 0); /* LyXLex should be changed
|
1999-09-27 18:44:28 +00:00
|
|
|
* to allow constructor with
|
|
|
|
* no parameters. */
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
lex.setFile(filename);
|
|
|
|
|
|
|
|
if (!lex.IsOK()) return;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp;
|
1999-09-27 18:44:28 +00:00
|
|
|
FileInfo fileInfo;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (lex.IsOK() && !error && i < num_files) {
|
|
|
|
switch(lex.lex()) {
|
|
|
|
case LyXLex::LEX_FEOF:
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tmp = lex.GetString();
|
|
|
|
// Check if the file exist
|
|
|
|
if (dostat) {
|
|
|
|
if (!(fileInfo.newFile(tmp).exist() &&
|
|
|
|
fileInfo.isRegular()))
|
|
|
|
break; // the file does not exist
|
|
|
|
}
|
|
|
|
files[i] = tmp;
|
|
|
|
i++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void LastFiles::writeFile(string const & filename) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
FilePtr fd(filename, FilePtr::write);
|
|
|
|
if (fd()) {
|
|
|
|
for (int i = 0; i < num_files; i++) {
|
|
|
|
if (!files[i].empty())
|
|
|
|
fprintf(fd, "\"%s\"\n", files[i].c_str());
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
lyxerr.print("LyX: Warning: unable to save LastFiles: "
|
|
|
|
+ filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void LastFiles::newFile(string const & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
// Find this file in list. If not in list, point to last entry
|
|
|
|
for(n = 0; n < (num_files - 1); n++)
|
|
|
|
if(files[n] == file) break;
|
|
|
|
|
|
|
|
for(int i = n; i >= 1; i--)
|
|
|
|
files[i] = files[i - 1];
|
|
|
|
files[0] = file;
|
|
|
|
}
|