This commit was manufactured by cvs2svn to create tag
[lyx.git] / src / ImportNoweb.C
blobf366387a4ddd289c19cee57173fcb5f52f9c59c1
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  */
14 #include <config.h>
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
20 #include "ImportNoweb.h"
21 #include "lyxrc.h"
22 #include "support/syscall.h"
23 #include "support/filetools.h"
24 #include "bufferlist.h"
26 extern LyXRC * lyxrc;
27 extern BufferList bufferlist;
30  * Implementation the ImportNoweb methods.
31  */
33 Buffer * ImportNoweb::run()
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;
49 // Provide the literate documentclass by parsing the file.
51 string ImportNoweb::documentclass()
53         string result = "literate-article"; // Default
55         FilePtr inputfile(file, FilePtr::read); 
56         if (!inputfile()) return "nofile"; // Should not happen!
58         char buf[BUFSIZE], *p, *q;
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         }
74         return result;