]> git.lyx.org Git - lyx.git/blobdiff - src/ImportNoweb.C
Baruch's graphic-inset patch.
[lyx.git] / src / ImportNoweb.C
index 66071111e375ec7d461dff9ba74c765557559d05..31c30bdd7890cb299200e6a7aeea0f71f604c13e 100644 (file)
@@ -1,14 +1,14 @@
 /* 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.
  *
  *           This file is Copyright 1999
  *           Kayvan A. Sylvan
  *
- * ======================================================
+ * ====================================================== 
  */
 
 #include <config.h>
 #pragma implementation
 #endif
 
+#include <fstream>
+#include <cstdlib>
+
 #include "ImportNoweb.h"
 #include "lyxrc.h"
 #include "support/syscall.h"
-#include "support/filetools.h"
 #include "bufferlist.h"
 
-extern LyXRC * lyxrc;
+using std::ifstream;
+using std::getline;
+
 extern BufferList bufferlist;
 
 /*
@@ -33,12 +37,12 @@ extern BufferList bufferlist;
 Buffer * ImportNoweb::run()
 {
        // run reLyX -n
-       string tmp = lyxrc->relyx_command + " -n -c " +
+       string tmp = lyxrc.relyx_command + " -n -c " +
                                        documentclass() + " -f " + file;
         Systemcalls one;
        Buffer * buf = 0;
        int result= one.startscript(Systemcalls::System, tmp);
-       if (result==0) {
+       if (result == 0) {
                string filename = file + ".lyx";
                // File was generated without problems. Load it.
                buf = bufferlist.loadLyXFile(filename);
@@ -46,30 +50,24 @@ Buffer * ImportNoweb::run()
        return buf;
 }
 
+
 // Provide the literate documentclass by parsing the file.
-//
 string ImportNoweb::documentclass()
 {
        string result = "literate-article"; // Default
 
-       FilePtr inputfile(file, FilePtr::read); 
-       if (!inputfile()) return "nofile"; // Should not happen!
+       ifstream ifs(file.c_str());
 
-       char buf[BUFSIZE], *p, *q;
-
-       while(!feof(inputfile())) {
-               (void)fgets(buf, BUFSIZE, inputfile());
-               if ((p = strstr(buf, "\\documentclass"))) {
-                       while ((*p) && (*p != '{'))
-                               p++;
-                       q = p++;
-                       while ((*q) && (*q != '}'))
-                               q++;
-                       *q = '\0';
-                       result = p;
-                       result = "literate-" + result;
+       if (!ifs) return "nofile"; // Should not happen!
+       string line;
+       while (getline(ifs, line)) {
+               string::size_type p = line.find("\\documentclass");
+               if (p != string::npos) {
+                       p = line.find('{', p);
+                       string::size_type q = line.find('}', p);
+                       result = "literate-" + line.substr(p + 1, q - p - 1);
+                       break;
                }
        }
-
        return result;
 }