]> git.lyx.org Git - lyx.git/blobdiff - src/Literate.C
NEW_INSETS changes, + some small things in insettabular.C
[lyx.git] / src / Literate.C
index 28e2f886abf51bc0d84bd0e116498e1cf46b4227..134d6d310e8876cf75e52b1b26e0a44019bdf92f 100644 (file)
@@ -1,56 +1,57 @@
 /* This file is part of
- * ======================================================
+ * ====================================================== 
  * 
  *           LyX, The Document Processor        
  *          Copyright 1995 Matthias Ettrich
- *           Copyright 1995-1999 The LyX Team.
+ *           Copyright 1995-2000 The LyX Team.
  *
- * ======================================================
+ * ====================================================== 
  */
 
 #include <config.h>
 
-#include <cstdio>
-#include <cstdlib>
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
+#include <fstream>
 
 #include "support/filetools.h"
 #include "LaTeX.h"
 #include "Literate.h"
-#include "lyxlex.h"
 #include "support/FileInfo.h"
 #include "debug.h"
 #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"
 
+using std::ifstream;
+using std::getline;
+using std::endl;
+
 extern BufferList bufferlist;
 
 Literate::Literate(string const & latex, string const & f, string const & p, 
                   string const & l, 
                   string const & literate, string const & literate_f, 
                   string const & build, string const & build_f)
-                   : LaTeX (latex, f, p),
+                   : LaTeX(latex, f, p),
                     litfile(l),
                     literate_cmd(literate), literate_filter(literate_f), 
                     build_cmd(build), build_filter(build_f)
-{
-}
+{}
 
 
-int Literate::weave(TeXErrors &terr, MiniBuffer *minib)
+int Literate::weave(TeXErrors & terr, MiniBuffer * minib)
 {
         int scanres = Literate::NO_ERRORS;
         string tmp1, tmp2;
         int ret1, ret2;
         Systemcalls one, two;
+       string logfile = OnlyFilename(ChangeExtension(file, ".log"));
 
         // The class LaTeX does not know the temp path.
         bufferlist.updateIncludedTeXfiles(GetCWD());
@@ -62,28 +63,28 @@ int Literate::weave(TeXErrors &terr, MiniBuffer *minib)
         // Run the literate program to convert \literate_extension file to .tex file
         //
         tmp1 = literate_cmd + " < " + litfile + " > " + file + " 2> " + litfile + ".out";
-        tmp2 = literate_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
-        ret1 = one.Startscript(Systemcalls::System, tmp1);
-        ret2 = two.Startscript(Systemcalls::System, tmp2);
+        tmp2 = literate_filter + " < " + litfile + ".out" + " > " + logfile;
+        ret1 = one.startscript(Systemcalls::System, tmp1);
+        ret2 = two.startscript(Systemcalls::System, tmp2);
         lyxerr.debug() << "LITERATE {" << tmp1 << "} {" << tmp2 << "}" << endl;
-       scanres = scanLiterateLogFile(terr);
-       if (scanres & Literate::ERRORS) return scanres; // return on literate error
 
+       scanres = scanLogFile(terr);
+       if (scanres & Literate::ERRORS) return scanres; // return on literate error
        return run(terr, minib);
 }
 
 
-int Literate::build(TeXErrors &terr, MiniBuffer *minib)
+int Literate::build(TeXErrors & terr, MiniBuffer * minib)
         // We know that this function will only be run if the lyx buffer
         // has been changed. 
 {
         int scanres = Literate::NO_ERRORS;
         num_errors = 0; // just to make sure.
-        // DepTable head; // empty head // unused
-        // bool rerun = false; // rerun requested // unused
         string tmp1, tmp2;
         int ret1, ret2;
         Systemcalls one, two;
+       string logfile = OnlyFilename(ChangeExtension(file, ".log"));
+
         
         // The class LaTeX does not know the temp path.
         bufferlist.updateIncludedTeXfiles(GetCWD());
@@ -95,99 +96,12 @@ int Literate::build(TeXErrors &terr, MiniBuffer *minib)
         // Run the build program
         //
         tmp1 = build_cmd + ' ' + litfile + " > " + litfile + ".out 2>&1";
-        tmp2 = build_filter + " < " + litfile + ".out" + " > " + litfile + ".log";
-        ret1 = one.Startscript(Systemcalls::System, tmp1);
-        ret2 = two.Startscript(Systemcalls::System, tmp2);
-        scanres = scanBuildLogFile(terr);
+        tmp2 = build_filter + " < " + litfile + ".out" + " > " + logfile;
+        ret1 = one.startscript(Systemcalls::System, tmp1);
+        ret2 = two.startscript(Systemcalls::System, tmp2);
+
+       scanres = scanLogFile(terr);
         lyxerr[Debug::LATEX] << "Done." << endl;
 
         return scanres;
 }
-
-
-int Literate::scanLiterateLogFile(TeXErrors &terr)
-{
-        string token;
-        int retval = NO_ERRORS;
-        
-        LyXLex lex(0, 0);
-        string tmp = litfile + ".log";
-        
-        if (!lex.setFile(tmp)) {
-                // unable to open file
-                // return at once
-                retval |= NO_LOGFILE;
-                return retval;
-        }
-        
-        while (lex.IsOK()) {
-                if (lex.EatLine())
-                        token = lex.GetString();
-                else // blank line in the file being read
-                        continue;
-                lyxerr[Debug::LATEX] << token << endl;
-                
-                if (prefixIs(token, "Build Warning:")) {
-                        // Here shall we handle different
-                        // types of warnings
-                        retval |= LATEX_WARNING;
-                        lyxerr[Debug::LATEX] << "Build Warning." << endl;
-                } else if (prefixIs(token, "! Build Error:")) {
-                        // Here shall we handle different
-                        // types of errors
-                        retval |= LATEX_ERROR;
-                        lyxerr[Debug::LATEX] << "Build Error." << endl;
-                        // this is not correct yet
-                        terr.scanError(lex);
-                        num_errors++;
-                }
-        }       
-        return retval;
-}
-
-
-int Literate::scanBuildLogFile(TeXErrors &terr)
-{
-        string token;
-        int retval = NO_ERRORS;
-        
-        LyXLex lex(0, 0);
-        string tmp = litfile + ".log";
-        
-        if (!lex.setFile(tmp)) {
-                // unable to open file
-                // return at once
-                retval |= NO_LOGFILE;
-                return retval;
-        }
-        
-        while (lex.IsOK()) {
-                if (lex.EatLine())
-                        token = lex.GetString();
-                else // blank line in the file being read
-                        continue;
-                lyxerr[Debug::LATEX] << token << endl;
-                
-                if (prefixIs(token, "Build Warning:")) {
-                        // Here shall we handle different
-                        // types of warnings
-                        retval |= LATEX_WARNING;
-                        lyxerr[Debug::LATEX] << "Build Warning." << endl;
-                } else if (prefixIs(token, "! Build Error:")) {
-                        // Here shall we handle different
-                        // types of errors
-                        retval |= LATEX_ERROR;
-                        lyxerr[Debug::LATEX] << "Build Error." << endl;
-                        // this is not correct yet
-                        terr.scanError(lex);
-                        num_errors++;
-                }
-        }       
-        return retval;
-}
-
-