]> git.lyx.org Git - lyx.git/blob - src/ImportNoweb.C
66071111e375ec7d461dff9ba74c765557559d05
[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-1999 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 "ImportNoweb.h"
21 #include "lyxrc.h"
22 #include "support/syscall.h"
23 #include "support/filetools.h"
24 #include "bufferlist.h"
25
26 extern LyXRC * lyxrc;
27 extern BufferList bufferlist;
28
29 /*
30  * Implementation the ImportNoweb methods.
31  */
32
33 Buffer * ImportNoweb::run()
34 {
35         // run reLyX -n
36         string tmp = lyxrc->relyx_command + " -n -c " +
37                                         documentclass() + " -f " + file;
38         Systemcalls one;
39         Buffer * buf = 0;
40         int result= one.startscript(Systemcalls::System, tmp);
41         if (result==0) {
42                 string filename = file + ".lyx";
43                 // File was generated without problems. Load it.
44                 buf = bufferlist.loadLyXFile(filename);
45         }
46         return buf;
47 }
48
49 // Provide the literate documentclass by parsing the file.
50 //
51 string ImportNoweb::documentclass()
52 {
53         string result = "literate-article"; // Default
54
55         FilePtr inputfile(file, FilePtr::read); 
56         if (!inputfile()) return "nofile"; // Should not happen!
57
58         char buf[BUFSIZE], *p, *q;
59
60         while(!feof(inputfile())) {
61                 (void)fgets(buf, BUFSIZE, inputfile());
62                 if ((p = strstr(buf, "\\documentclass"))) {
63                         while ((*p) && (*p != '{'))
64                                 p++;
65                         q = p++;
66                         while ((*q) && (*q != '}'))
67                                 q++;
68                         *q = '\0';
69                         result = p;
70                         result = "literate-" + result;
71                 }
72         }
73
74         return result;
75 }