]> git.lyx.org Git - lyx.git/blob - src/ImportNoweb.C
small patch from Dekel, begin introducing the real boost framework, get rid of the...
[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 #include <cstdlib>
22
23 #include "ImportNoweb.h"
24 #include "lyxrc.h"
25 #include "support/syscall.h"
26 #include "bufferlist.h"
27
28 using std::ifstream;
29 using std::getline;
30
31 extern BufferList bufferlist;
32
33 /*
34  * Implementation the ImportNoweb methods.
35  */
36
37 Buffer * ImportNoweb::run()
38 {
39         // run reLyX -n
40         string tmp = lyxrc.relyx_command + " -n -c " +
41                                         documentclass() + " -f " + file;
42         Systemcalls one;
43         Buffer * buf = 0;
44         int result= one.startscript(Systemcalls::System, tmp);
45         if (result == 0) {
46                 string filename = file + ".lyx";
47                 // File was generated without problems. Load it.
48                 buf = bufferlist.loadLyXFile(filename);
49         }
50         return buf;
51 }
52
53
54 // Provide the literate documentclass by parsing the file.
55 string const ImportNoweb::documentclass()
56 {
57         string result = "literate-article"; // Default
58
59         ifstream ifs(file.c_str());
60
61         if (!ifs) return "nofile"; // Should not happen!
62         string line;
63         while (getline(ifs, line)) {
64                 string::size_type p = line.find("\\documentclass");
65                 if (p != string::npos) {
66                         p = line.find('{', p);
67                         string::size_type q = line.find('}', p);
68                         result = "literate-" + line.substr(p + 1, q - p - 1);
69                         break;
70                 }
71         }
72         return result;
73 }