]> git.lyx.org Git - lyx.git/blobdiff - src/lyxvc.C
removed a warning from screen and added CFLAGS in lyx.spec.in.
[lyx.git] / src / lyxvc.C
index 1c01548d1f3724ca4140a716e06ae4d606be60c9..31aca999eac6133cc80efc98b1b3f600969f4c49 100644 (file)
@@ -6,13 +6,13 @@
 
 #include FORMS_H_LOCATION
 #include "lyxvc.h"
-#include "error.h"
+#include "debug.h"
 #include "lyx_gui_misc.h"
 #include "bufferlist.h"
-#include "syscall.h"
-#include "pathstack.h"
-#include "filetools.h"
-#include "FileInfo.h"
+#include "support/syscall.h"
+#include "support/path.h"
+#include "support/filetools.h"
+#include "support/FileInfo.h"
 #include "gettext.h"
 #include "LyXView.h"
 #include "lyxfunc.h"
@@ -43,15 +43,16 @@ LyXVC::~LyXVC()
 }
 
 
-bool LyXVC::file_found_hook(LString const & fn)
+bool LyXVC::file_found_hook(string const & fn)
 {
-       LString tmp(fn);
+       string tmp(fn);
        FileInfo f;
        // Check if *,v exists.
        tmp += ",v";
-       lyxerr.debug(LString("Checking if file is under vc: ") + tmp, Error::LYXVC);
+       lyxerr[Debug::LYXVC] << "Checking if file is under vc: "
+                            << tmp << endl;
        if (f.newFile(tmp).readable()) {
-               lyxerr.debug("Yes it is under vc.", Error::LYXVC);
+               lyxerr[Debug::LYXVC] << "Yes it is under vc." << endl;
                master = tmp;
                backend = RCS_VCS;
                scanMaster();
@@ -60,9 +61,10 @@ bool LyXVC::file_found_hook(LString const & fn)
                // Check if RCS/*,v exists.
                tmp = AddName(AddPath(OnlyPath(fn), "RCS"), fn);
                tmp += ",v";
-               lyxerr.debug("Checking if file is under vc: " + tmp, Error::LYXVC);
+               lyxerr[Debug::LYXVC] << "Checking if file is under vc: "
+                                    << tmp << endl;
                if (f.newFile(tmp).readable()) {
-                       lyxerr.debug("Yes it is under vc.", Error::LYXVC);
+                       lyxerr[Debug::LYXVC] << "Yes it is under vc."<< endl;
                        master = tmp;
                        backend = RCS_VCS;
                        scanMaster();
@@ -76,7 +78,7 @@ bool LyXVC::file_found_hook(LString const & fn)
 }
 
 
-bool LyXVC::file_not_found_hook(LString const &)
+bool LyXVC::file_not_found_hook(string const &)
 {
        // file is not under any VCS.
        return false;
@@ -85,61 +87,60 @@ bool LyXVC::file_not_found_hook(LString const &)
 
 void LyXVC::scanMaster()
 {
-       lyxerr.debug("LyXVC: This file is a VC file.", Error::LYXVC);
+       lyxerr[Debug::LYXVC] << "LyXVC: This file is a VC file." << endl;
 
-       LyXLex lex(NULL, 0);
+       LyXLex lex(0, 0);
        lex.setFile(master);
 
-       LString token;
+       string token;
        bool read_enough = false;
        while (lex.IsOK() && !read_enough) {
                lex.next();
                token = lex.GetString();
                
-               lyxerr.debug("LyXVC::scanMaster: current lex text: `"
-                               +token+"'", Error::LYXVC);
+               lyxerr[Debug::LYXVC] <<"LyXVC::scanMaster: current lex text: `"
+                                    << token << "'" << endl;
 
                if (token.empty())
                        continue;
                else if (token == "head") {
                        // get version here
                        lex.next();
-                       LString tmv = lex.GetString();
-                       tmv.strip(';');
+                       string tmv = strip(lex.GetString(), ';');
                        version = tmv;
-               } else if (token.contains("access")
-                          || token.contains("symbols")
-                          || token.contains("strict")) {
+               } else if (contains(token, "access")
+                          || contains(token, "symbols")
+                          || contains(token, "strict")) {
                        // nothing
-               } else if (token.contains("locks")) {
+               } else if (contains(token, "locks")) {
                        // get locker here
-                       if (token.contains(";")) {
+                       if (contains(token, ";")) {
                                locker = "Unlocked";
                                vcstat = UNLOCKED;
                                continue;
                        }
-                       LString tmpt, s1, s2;
+                       string tmpt, s1, s2;
                        do {
                                lex.next();
-                               tmpt = lex.GetString();
-                               s1 = tmpt;
-                               s1.strip(';');
+                               s1 = strip(tmpt = lex.GetString(), ';');
                                // tmp is now in the format <user>:<version>
-                               s1.split(s2, ':');
+                               s1 = split(s1, s2, ':');
                                // s2 is user, and s1 is version
                                if (s1 == version) {
                                        locker = s2;
                                        vcstat = LOCKED;
                                        break;
                                }
-                       } while (!tmpt.contains(";"));
+                       } while (!contains(tmpt, ";"));
                        
                } else if (token == "comment") {
                        // we don't need to read any further than this.
                        read_enough = true;
                } else {
                        // unexpected
-                       lyxerr.debug("LyXVC::scanMaster(): unexpected token", Error::LYXVC);
+                       lyxerr[Debug::LYXVC]
+                               << "LyXVC::scanMaster(): unexpected token"
+                               << endl;
                }
        }
 }
@@ -179,15 +180,15 @@ void LyXVC::registrer()
                return;
        }
 
-       lyxerr.debug("LyXVC: registrer", Error::LYXVC);
-       LString tmp = askForText(_("LyX VC: Initial description"),
+       lyxerr[Debug::LYXVC] << "LyXVC: registrer" << endl;
+       string tmp = askForText(_("LyX VC: Initial description"),
                                 _("(no initial description)"));
        if (tmp.empty()) {
-               lyxerr.debug("LyXVC: user cancelled", Error::LYXVC);
+               lyxerr[Debug::LYXVC] << "LyXVC: user cancelled" << endl;
                WriteAlert(_("Info"), _("This document has NOT been registered."));
                return;
        }
-       LString cmd = "ci -q -u -i -t-\"";
+       string cmd = "ci -q -u -i -t-\"";
        cmd += tmp;
        cmd += "\" \"";
        cmd += OnlyFilename(_owner->getFileName());
@@ -213,9 +214,9 @@ void LyXVC::checkIn()
                return;
        }
 
-       lyxerr.debug("LyXVC: checkIn", Error::LYXVC);
+       lyxerr[Debug::LYXVC] << "LyXVC: checkIn" << endl;
        _owner->getUser()->getOwner()->getLyXFunc()->Dispatch(LFUN_MENUWRITE);
-       LString tmp = askForText(_("LyX VC: Log Message"));
+       string tmp = askForText(_("LyX VC: Log Message"));
        if (tmp.empty()) tmp = "(no log msg)";
        doVCCommand("ci -q -u -m\"" + tmp + "\" \""
                    + OnlyFilename(_owner->getFileName()) + "\"");
@@ -225,7 +226,7 @@ void LyXVC::checkIn()
 
 void LyXVC::checkOut()
 {
-       lyxerr.debug("LyXVC: checkOut", Error::LYXVC);
+       lyxerr[Debug::LYXVC] << "LyXVC: checkOut" << endl;
        if (!_owner->isLyxClean() 
            && !AskQuestion(_("Changes in document:"),
                           MakeDisplayPath(_owner->getFileName(),50),
@@ -242,7 +243,7 @@ void LyXVC::checkOut()
 
 void LyXVC::revert()
 {
-       lyxerr.debug("LyXVC: revert", Error::LYXVC);
+       lyxerr[Debug::LYXVC] << "LyXVC: revert" << endl;
        // Here we should check if the buffer is dirty. And if it is
        // we should warn the user that reverting will discard all
        // changes made since the last check in.
@@ -262,7 +263,7 @@ void LyXVC::revert()
 
 void LyXVC::undoLast()
 {
-       lyxerr.debug("LyXVC: undoLast", Error::LYXVC);
+       lyxerr[Debug::LYXVC] << "LyXVC: undoLast" << endl;
        doVCCommand("rcs -o" + getVersion() + " \""
                    + OnlyFilename(_owner->getFileName()) + "\"");
 }
@@ -289,13 +290,13 @@ bool LyXVC::inUse()
 }
 
 
-LString const LyXVC::getVersion() const
+string const LyXVC::getVersion() const
 {
        return version;
 }
 
 
-LString const LyXVC::getLocker() const
+string const LyXVC::getLocker() const
 {
        return locker;
 }
@@ -307,6 +308,12 @@ void LyXVC::logClose(FL_OBJECT *obj, long)
        fl_hide_form(This->browser->LaTeXLog);
 }
 
+// and, hack over hack, here is a C wrapper :)
+extern "C" void C_LyXVC_logClose(FL_OBJECT *ob, long data)
+{
+       LyXVC::logClose(ob, data);
+}
+
 
 void LyXVC::logUpdate(FL_OBJECT *obj, long)
 {
@@ -314,9 +321,16 @@ void LyXVC::logUpdate(FL_OBJECT *obj, long)
        This->showLog();
 }
 
+extern "C" void C_LyXVC_logUpdate(FL_OBJECT *ob, long data)
+{
+       LyXVC::logUpdate(ob, data);
+}
+
 
-void LyXVC::viewLog(LString const & fil)
+void LyXVC::viewLog(string const & fil)
 {
+       static int ow = -1, oh;
+
        if (!browser) {
                FL_OBJECT *obj;
                browser = (FD_LaTeXLog *) fl_calloc(1, sizeof(*browser));
@@ -327,14 +341,14 @@ void LyXVC::viewLog(LString const & fil)
                browser->browser_latexlog = fl_add_browser(FL_NORMAL_BROWSER, 10, 10, 450, 320, "");
                obj = fl_add_button(FL_RETURN_BUTTON, 270, 340, 90, 30, _("Close"));
                fl_set_object_lsize(obj, FL_NORMAL_SIZE);
-               fl_set_object_callback(obj, logClose, 0);
+               fl_set_object_callback(obj, C_LyXVC_logClose, 0);
                obj = fl_add_button(FL_NORMAL_BUTTON,370,340,90,30,
                                    idex(_("Update|#Uu")));
                fl_set_button_shortcut(obj,scex(_("Update|#Uu")),1);
                fl_set_object_lsize(obj,FL_NORMAL_SIZE);
-               fl_set_object_callback(obj,logUpdate,0);
+               fl_set_object_callback(obj, C_LyXVC_logUpdate,0);
                fl_end_form();
-               fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, NULL);
+               fl_set_form_atclose(browser->LaTeXLog, CancelCloseBoxCB, 0);
        }
 
        if (!fl_load_browser(browser->browser_latexlog, fil.c_str()))
@@ -346,6 +360,11 @@ void LyXVC::viewLog(LString const & fil)
                fl_show_form(browser->LaTeXLog,
                             FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
                             _("RCS History"));
+               if (ow < 0) {
+                       ow = browser->LaTeXLog->w;
+                       oh = browser->LaTeXLog->h;
+               }
+               fl_set_form_minsize(browser->LaTeXLog, ow, oh);
        }
 }
 
@@ -372,7 +391,7 @@ void LyXVC::showLog()
                return;
        }
 #endif
-       LString tmpf = tmpnam(NULL);
+       string tmpf = tmpnam(0);
        doVCCommand("rlog \""
                    + OnlyFilename(_owner->getFileName()) + "\" > " + tmpf);
        viewLog(tmpf);
@@ -380,12 +399,11 @@ void LyXVC::showLog()
 }
 
 
-int LyXVC::doVCCommand(LString const & cmd)
+int LyXVC::doVCCommand(string const & cmd)
 {
-       lyxerr.debug("doVCCommand: " + cmd, Error::LYXVC);
+       lyxerr[Debug::LYXVC] << "doVCCommand: " << cmd << endl;
         Systemcalls one;
-       PathPush(_owner->filepath);
-       int ret = one.Startscript(Systemcalls::System, cmd);
-       PathPop();
+       Path p(_owner->filepath);
+       int ret = one.startscript(Systemcalls::System, cmd);
        return ret;
 }