]> git.lyx.org Git - lyx.git/blob - src/ImportNoweb.C
remove wrong sections
[lyx.git] / src / ImportNoweb.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor         
5  *           Copyright 1995 Matthias Ettrich
6  *           Copyright 1995-2000 The LyX Team.
7  *
8  *           This file is Copyright 1999
9  *           Kayvan A. Sylvan
10  *
11  * ====================================================== 
12  */
13
14 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include <fstream>
21 using std::ifstream;
22
23 #include "ImportNoweb.h"
24 #include "lyxrc.h"
25 #include "support/syscall.h"
26 #include "bufferlist.h"
27
28 extern BufferList bufferlist;
29
30 /*
31  * Implementation the ImportNoweb methods.
32  */
33
34 Buffer * ImportNoweb::run()
35 {
36         // run reLyX -n
37         string tmp = lyxrc.relyx_command + " -n -c " +
38                                         documentclass() + " -f " + file;
39         Systemcalls one;
40         Buffer * buf = 0;
41         int result= one.startscript(Systemcalls::System, tmp);
42         if (result == 0) {
43                 string filename = file + ".lyx";
44                 // File was generated without problems. Load it.
45                 buf = bufferlist.loadLyXFile(filename);
46         }
47         return buf;
48 }
49
50
51 // Provide the literate documentclass by parsing the file.
52 string ImportNoweb::documentclass()
53 {
54         string result = "literate-article"; // Default
55
56         ifstream ifs(file.c_str());
57
58         if (!ifs) return "nofile"; // Should not happen!
59         string line;
60         while (getline(ifs, line)) {
61                 string::size_type p = line.find("\\documentclass");
62                 if (p != string::npos) {
63                         p = line.find('{', p);
64                         string::size_type q = line.find('}', p);
65                         result = "literate-" + line.substr(p + 1, q - p - 1);
66                         break;
67                 }
68         }
69         return result;
70 }