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