merge in the class Path changes

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@196 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 1999-10-13 17:32:46 +00:00
parent 0b2b65ee42
commit 535dd32c4c
20 changed files with 136 additions and 216 deletions

View File

@ -1,5 +1,17 @@
1999-10-13 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/LaTeXLog.C (ShowLatexLog): reordered som statements so that
Path would fit in more nicely.
* all files that used to use pathstack: uses now Path instead.
This change was a lot easier than expected.
* src/support/path.h: new file
* src/support/Makefile.am (libsupport_a_SOURCES): added path.h
* src/Makefile.am (lyx_SOURCES): removed pathstack.[Ch]
* src/support/lyxstring.C (getline): Default arg was given for
para 3. removed.

View File

@ -72,11 +72,11 @@ src/menus.C
src/minibuffer.C
src/minibuffer.h
src/paragraph.C
src/pathstack.C
src/print_form.C
src/sp_form.C
src/spellchecker.C
src/support/filetools.C
src/support/lyxlib.h
src/support/path.h
src/text.C
src/text2.C

View File

@ -27,7 +27,7 @@
#include "debug.h"
#include "support/syscall.h"
#include "support/syscontr.h"
#include "pathstack.h"
#include "support/path.h"
#include "gettext.h"
/*

View File

@ -28,7 +28,7 @@
#include "support/lyxlib.h"
#include "support/syscall.h"
#include "support/syscontr.h"
#include "pathstack.h"
#include "support/path.h"
#include "bufferlist.h"
#include "minibuffer.h"
#include "gettext.h"
@ -682,7 +682,7 @@ void LaTeX::deplog(DepTable & head)
// found in the same dir
// as the .lyx file and
// should be inserted.
PathPush(path);
Path p(path);
if (FileInfo(foundfile).exist()) {
lyxerr << "LyX Strange: this should actually never"
" happen anymore, this it should be"
@ -691,10 +691,8 @@ void LaTeX::deplog(DepTable & head)
lyxerr[Debug::LATEX] << "Same Directory file: "
<< foundfile << endl;
head.insert(foundfile);
PathPop();
continue;
}
PathPop();
lyxerr[Debug::LATEX]
<< "Not a file or we are unable to find it."

View File

@ -8,7 +8,7 @@
#include "LString.h"
#include "support/FileInfo.h"
#include "support/filetools.h"
#include "pathstack.h"
#include "support/path.h"
#include "lyxrc.h"
#include "BufferView.h"
#include "gettext.h"
@ -18,37 +18,39 @@ extern BufferView *current_view;
void ShowLatexLog()
{
string filename, fname, bname, path;
bool use_build = false;
string filename, fname, bname, path;
bool use_build = false;
filename = current_view->currentBuffer()->getFileName();
if (!filename.empty()) {
fname = SpaceLess(ChangeExtension(filename, ".log", true));
bname = SpaceLess(ChangeExtension(filename, lyxrc->literate_extension + ".out", true));
path = OnlyPath(filename);
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
path = current_view->currentBuffer()->tmppath;
filename = current_view->currentBuffer()->getFileName();
if (!filename.empty()) {
fname = SpaceLess(ChangeExtension(filename, ".log", true));
bname = SpaceLess(ChangeExtension(filename,
lyxrc->literate_extension + ".out", true));
path = OnlyPath(filename);
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
path = current_view->currentBuffer()->tmppath;
}
FileInfo f_fi(path + fname), b_fi(path + bname);
if (b_fi.exist())
if (!f_fi.exist()
|| f_fi.getModificationTime() < b_fi.getModificationTime())
use_build = true; // If no Latex log or Build log is newer, show Build log
Path p(path); // path to LaTeX file
if (!fl_load_browser(fd_latex_log->browser_latexlog,
use_build ? bname.c_str() : fname.c_str()))
fl_add_browser_line(fd_latex_log->browser_latexlog,
_("Unable to show log file!"));
} else {
fl_add_browser_line(fd_latex_log->browser_latexlog,
_("NO LATEX LOG FILE!"));
}
if (fd_latex_log->LaTeXLog->visible) {
fl_raise_form(fd_latex_log->LaTeXLog);
} else {
fl_show_form(fd_latex_log->LaTeXLog,
FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
use_build ? _("Build Program Log") : _("LaTeX Log"));
}
FileInfo f_fi(path + fname), b_fi(path + bname);
if (b_fi.exist())
if ( ! f_fi.exist()
|| f_fi.getModificationTime() < b_fi.getModificationTime())
use_build = true; // If no Latex log or Build log is newer, show Build log
PathPush(path); // path to LaTeX file
}
if (!fl_load_browser(fd_latex_log->browser_latexlog,
(use_build)?bname.c_str():fname.c_str()))
fl_add_browser_line(fd_latex_log->browser_latexlog, _("NO LATEX LOG FILE!"));
if (fd_latex_log->LaTeXLog->visible) {
fl_raise_form(fd_latex_log->LaTeXLog);
}
else {
fl_show_form(fd_latex_log->LaTeXLog,
FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
(use_build)?_("Build Program Log"):_("LaTeX Log"));
}
if (!filename.empty())
PathPop();
}
void LatexLogClose(FL_OBJECT *, long)

View File

@ -26,7 +26,7 @@
#include "support/lyxlib.h"
#include "support/syscall.h"
#include "support/syscontr.h"
#include "pathstack.h"
#include "support/path.h"
#include "bufferlist.h"
#include "minibuffer.h"
#include "gettext.h"

View File

@ -6,7 +6,7 @@
#include "lyxrc.h"
#include "LString.h"
#include "support/filetools.h"
#include "pathstack.h"
#include "support/path.h"
#include "buffer.h"
#include "lyx_gui_misc.h"
#include "support/syscall.h"
@ -82,7 +82,7 @@ void SendtoApplyCB(FL_OBJECT *, long)
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
path = buffer->tmppath;
}
PathPush(path);
Path p(path);
// save the .lyx file in tmp_dir if this filetype is requested
if (fl_get_button(fd_form_sendto->radio_ftype_lyx))
buffer->writeFile(fname,true);
@ -94,7 +94,6 @@ void SendtoApplyCB(FL_OBJECT *, long)
if (fl_get_button(fd_form_sendto->radio_ftype_ascii))
buffer->writeFileAscii(fname, lyxrc->ascii_linelen);
Systemcalls one(Systemcalls::System, command);
PathPop();
}
void SendtoCancelCB(FL_OBJECT *, long)

View File

@ -140,8 +140,6 @@ lyx_SOURCES = \
os2_defines.h \
os2_errortable.h \
paragraph.C \
pathstack.C \
pathstack.h \
print_form.C \
print_form.h \
screen.C \

View File

@ -63,7 +63,7 @@
#include "insets/insetspecialchar.h"
#include "insets/figinset.h"
#include "support/filetools.h"
#include "pathstack.h"
#include "support/path.h"
#include "LaTeX.h"
#include "Literate.h"
#include "Chktex.h"
@ -3132,7 +3132,7 @@ int Buffer::runLaTeX()
path = tmppath;
}
PathPush(path); // path to LaTeX file
Path p(path); // path to LaTeX file
users->getOwner()->getMiniBuffer()->Set(_("Running LaTeX..."));
// Remove all error insets
@ -3179,7 +3179,6 @@ int Buffer::runLaTeX()
users->updateScrollbar();
}
AllowInput();
PathPop(); // path to LaTeX file
return latex.getNumErrors();
}
@ -3203,7 +3202,7 @@ int Buffer::runLiterate()
path = tmppath;
}
PathPush(path); // path to Literate file
Path p(path); // path to Literate file
users->getOwner()->getMiniBuffer()->Set(_("Running Literate..."));
// Remove all error insets
@ -3248,7 +3247,6 @@ int Buffer::runLiterate()
users->updateScrollbar();
}
AllowInput();
PathPop(); // path to LaTeX file
return literate.getNumErrors();
}
@ -3272,7 +3270,7 @@ int Buffer::buildProgram()
path = tmppath;
}
PathPush(path); // path to Literate file
Path p(path); // path to Literate file
users->getOwner()->getMiniBuffer()->Set(_("Building Program..."));
// Remove all error insets
@ -3316,7 +3314,6 @@ int Buffer::buildProgram()
users->updateScrollbar();
}
AllowInput();
PathPop(); // path to LaTeX file
return literate.getNumErrors();
}
@ -3340,7 +3337,7 @@ int Buffer::runChktex()
path = tmppath;
}
PathPush(path); // path to LaTeX file
Path p(path); // path to LaTeX file
users->getOwner()->getMiniBuffer()->Set(_("Running chktex..."));
// Remove all error insets
@ -3372,7 +3369,6 @@ int Buffer::runChktex()
users->updateScrollbar();
}
AllowInput();
PathPop(); // path to LaTeX file
return res;
}

View File

@ -42,7 +42,7 @@
#include "combox.h"
#include "bufferlist.h"
#include "support/filetools.h"
#include "pathstack.h"
#include "support/path.h"
#include "filedlg.h"
#include "lyx_gui_misc.h"
#include "LyXView.h" // only because of form_main
@ -549,9 +549,8 @@ int MakeDVIOutput(Buffer *buffer)
path = buffer->tmppath;
}
if (!buffer->isDviClean()) {
PathPush(path);
Path p(path);
ret = MenuRunLaTeX(buffer);
PathPop();
}
return ret;
}
@ -581,7 +580,7 @@ bool RunScript(Buffer *buffer, bool wait,
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
path = buffer->tmppath;
}
PathPush(path);
Path p(path);
cmd = command + ' ' + SpaceLess(name);
Systemcalls one;
@ -622,7 +621,6 @@ bool RunScript(Buffer *buffer, bool wait,
result = one.startscript(wait ? Systemcalls::Wait
: Systemcalls::DontWait, cmd);
}
PathPop();
return (result==0);
}
@ -706,10 +704,9 @@ bool MenuRunDvips(Buffer *buffer, bool wait=false)
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
path = buffer->tmppath;
}
PathPush(path);
Path p(path);
bool ret = RunScript(buffer, wait, command);
AllowInput();
PathPop();
return ret;
}
@ -734,9 +731,8 @@ bool MenuPreviewPS(Buffer *buffer)
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
path = buffer->tmppath;
}
PathPush(path);
Path p(path);
bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
PathPop();
AllowInput();
return ret;
}
@ -758,7 +754,7 @@ void MenuFax(Buffer *buffer)
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
path = buffer->tmppath;
}
PathPush(path);
Path p(path);
if (!lyxrc->fax_program.empty()) {
string help2 = lyxrc->fax_program;
subst(help2, "$$FName",ps);
@ -766,7 +762,6 @@ void MenuFax(Buffer *buffer)
Systemcalls one(Systemcalls::System, help2);
} else
send_fax(ps,lyxrc->fax_command);
PathPop();
}
@ -824,11 +819,10 @@ bool MenuPreview(Buffer *buffer)
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
path = buffer->tmppath;
}
PathPush(path);
Path p(path);
// Run dvi-viewer
string command = lyxrc->view_dvi_command + paper ;
bool ret = RunScript(buffer, false, command);
PathPop();
return ret;
}
@ -1254,7 +1248,7 @@ int RunLinuxDoc(int flag, string const & filename)
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
path = current_view->currentBuffer()->tmppath;
}
PathPush (path);
Path p(path);
if (flag != -1) {
if (!current_view->available())
@ -1300,7 +1294,6 @@ int RunLinuxDoc(int flag, string const & filename)
break;
}
PathPop();
AllowInput();
current_view->currentBuffer()->redraw();
@ -1326,7 +1319,7 @@ int RunDocBook(int flag, string const & filename)
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
path = current_view->currentBuffer()->tmppath;
}
PathPush (path);
Path p(path);
if (!current_view->available())
return 0;
@ -1357,7 +1350,6 @@ int RunDocBook(int flag, string const & filename)
break;
}
PathPop();
AllowInput();
current_view->currentBuffer()->redraw();
@ -3391,7 +3383,7 @@ void PrintApplyCB(FL_OBJECT *, long)
if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
path = buffer->tmppath;
}
PathPush(path);
Path p(path);
bool result;
if (!lyxrc->print_spool_command.empty() &&
@ -3406,7 +3398,6 @@ void PrintApplyCB(FL_OBJECT *, long)
}
} else
result = RunScript(buffer, false, command);
PathPop();
if (!result)
WriteAlert(_("Error:"),
@ -3561,10 +3552,10 @@ void Reconfigure()
minibuffer->Set(_("Running configure..."));
// Run configure in user lyx directory
PathPush(user_lyxdir);
Path p(user_lyxdir);
Systemcalls one(Systemcalls::System,
AddName(system_lyxdir,"configure"));
PathPop();
p.pop();
minibuffer->Set(_("Reloading configuration..."));
lyxrc->Read(LibFileSearch(string(), "lyxrc.defaults"));
WriteAlert(_("The system has been reconfigured."),

View File

@ -18,7 +18,7 @@
#include "lyx_gui.h"
#include "lyx_gui_misc.h"
#include "lyxrc.h"
#include "pathstack.h"
#include "support/path.h"
#include "support/filetools.h"
#include "bufferlist.h"
#include "debug.h"
@ -411,9 +411,8 @@ void LyX::queryUserLyXDir()
}
// Run configure in user lyx directory
PathPush(user_lyxdir);
Path p(user_lyxdir);
system(AddName(system_lyxdir,"configure").c_str());
PathPop();
lyxerr << "LyX: " << _("Done!") << endl;
}

View File

@ -22,7 +22,7 @@
#include "lyx_main.h"
#include "intl.h"
#include "tex-strings.h"
#include "pathstack.h"
#include "support/path.h"
#include "support/filetools.h"
#include "lyxtext.h"

View File

@ -10,7 +10,7 @@
#include "lyx_gui_misc.h"
#include "bufferlist.h"
#include "support/syscall.h"
#include "pathstack.h"
#include "support/path.h"
#include "support/filetools.h"
#include "support/FileInfo.h"
#include "gettext.h"
@ -385,8 +385,7 @@ int LyXVC::doVCCommand(string const & cmd)
{
lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
Systemcalls one;
PathPush(_owner->filepath);
Path p(_owner->filepath);
int ret = one.startscript(Systemcalls::System, cmd);
PathPop();
return ret;
}

View File

@ -35,6 +35,10 @@ enum {
///
typedef FL_OBJECT* FL_OBJECTP;
extern "C" {
int peek_event(FL_FORM *, void *);
}
/// Class to manage bitmap menu bars
class BitmapMenu {
///

View File

@ -232,6 +232,7 @@ int BitmapMenu::GetIndex(FL_OBJECT* ob)
return -1;
}
extern "C" {
int peek_event(FL_FORM * /*form*/, void *xev)
{
if (BitmapMenu::active==0)
@ -257,6 +258,7 @@ int peek_event(FL_FORM * /*form*/, void *xev)
}
return 0;
}
}
static void math_cb(FL_OBJECT* ob, long data)
{

View File

@ -1,86 +0,0 @@
// lyx-stack.C : implementation of PathStack class
// this file is part of LyX, the High Level Word Processor
// copyright (C) 1995-1996, Matthias Ettrich and the LyX Team
#include <config.h>
#include <unistd.h>
#ifdef __GNUG__
#pragma implementation "pathstack.h"
#endif
#include "pathstack.h"
#include "support/filetools.h"
#include "debug.h"
#include "LString.h"
#include "gettext.h"
// temporary hack
#include "lyx_gui_misc.h"
// global path stack
PathStack lyxPathStack;
// Standard constructor
PathStack::PathStack(string const & string)
: Path(string)
{
Next = 0;
}
// Destructor
PathStack::~PathStack()
{
if (Next)
delete Next;
}
// Changes to directory
int PathStack::PathPush(string const & Path)
{
// checks path string validity
if (Path.empty()) return 1;
PathStack *NewNode;
// gets current directory and switch to new one
string CurrentPath = GetCWD();
if ((CurrentPath.empty()) || chdir(Path.c_str())) {
WriteFSAlert(_("Error: Could not change to directory: "),
Path);
return 2;
}
lyxerr.debug() << "PathPush: " << Path << endl;
// adds new node
NewNode = new PathStack(CurrentPath);
NewNode->Next = Next;
Next = NewNode;
return 0;
}
// Goes back to previous directory
int PathStack::PathPop()
{
// checks stack validity and extracts old node
PathStack *OldNode = Next;
if (!OldNode) {
WriteAlert (_("LyX Internal Error:"), _("Path Stack underflow."));
return 1;
}
Next = OldNode->Next;
OldNode->Next = 0;
// switches to old directory
int Result = 0;
if (chdir(OldNode->Path.c_str())) {
WriteFSAlert(_("Error: Could not change to directory: "),
Path);
Result = 2;
}
lyxerr.debug() << "PathPop: " << OldNode->Path << endl;
delete OldNode;
return Result;
}

View File

@ -1,50 +0,0 @@
// -*- C++ -*-
// lyx-stack.H : definition of PathStack class
// this file is part of LyX, the High Level Word Processor
// copyright (C) 1995-1996, Matthias Ettrich and the LyX Team
#ifndef __LYX_STACK_H__
#define __LYX_STACK_H__
#ifdef __GNUG__
#pragma interface
#endif
#include "LString.h"
/// Path stack class definition
class PathStack {
public:
///
PathStack() {
Next = 0;
}
///
PathStack(string const & Path);
///
~PathStack();
///
int PathPush(string const & Path);
///
int PathPop();
private:
///
string Path;
///
PathStack *Next;
};
// global path stack
extern PathStack lyxPathStack;
/// some global wrapper functions
inline int PathPush(string const & szPath) {
return lyxPathStack.PathPush(szPath);
}
///
inline int PathPop() {
return lyxPathStack.PathPop();
}
#endif

View File

@ -17,6 +17,7 @@ libsupport_a_SOURCES = \
lyxstring.C \
lyxstring.h \
lyxsum.C \
path.h \
syscall.C \
syscall.h \
syscontr.C \

View File

@ -25,7 +25,7 @@
#include "filetools.h"
#include "lyx_gui_misc.h"
#include "FileInfo.h"
#include "pathstack.h" // I know it's OS/2 specific (SMiyata)
#include "support/path.h" // I know it's OS/2 specific (SMiyata)
#include "gettext.h"
#include "LAssert.h"

55
src/support/path.h Normal file
View File

@ -0,0 +1,55 @@
// -*- C++ -*-
#ifndef PATH_H
#define PATH_H
#include <unistd.h>
#include "LString.h"
#include "gettext.h"
#include "support/filetools.h"
#include "lyx_gui_misc.h"
class Path {
public:
///
Path(string const & path)
: popped_(false)
{
if (!path.empty()) {
pushedDir_ = GetCWD();
if (pushedDir_.empty() || chdir(path.c_str())) {
WriteFSAlert(_("Error: Could not change to directory: "),
path);
}
} else {
popped_ = true;
}
}
///
~Path()
{
if (!popped_) pop();
}
///
int pop()
{
if (popped_) {
WriteFSAlert(_("Error: Dir already popped: "),
pushedDir_);
return 0;
}
if (chdir(pushedDir_.c_str())) {
WriteFSAlert(
_("Error: Could not change to directory: "),
pushedDir_);
}
popped_ = true;
return 0;
}
private:
///
bool popped_;
///
string pushedDir_;
};
#endif