]> git.lyx.org Git - features.git/blob - src/ImportNoweb.C
Initial revision
[features.git] / src / ImportNoweb.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor         
5  *           Copyright (C) 1995 Matthias Ettrich
6  *           Copyright (C) 1995-1999 The LyX Team.
7  *
8  *           This file is Copyright (C) 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 "syscall.h"
23 #include "filetools.h"
24 #include "bufferlist.h"
25
26 extern LyXRC * lyxrc;
27 extern BufferList bufferlist;
28
29 //      $Id: ImportNoweb.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $
30
31 #if !defined(lint) && !defined(WITH_WARNINGS)
32 static char vcid[] = "$Id: ImportNoweb.C,v 1.1 1999/09/27 18:44:36 larsbj Exp $";
33 #endif /* lint */
34
35 /*
36  * Implementation the ImportNoweb methods.
37  */
38
39 Buffer * ImportNoweb::run()
40 {
41         // run reLyX -n
42         LString tmp = lyxrc->relyx_command + " -n -c " +
43                                         documentclass() + " -f " + file;
44         Systemcalls one;
45         Buffer * buf = 0;
46         int result= one.Startscript(Systemcalls::System, tmp);
47         if (result==0) {
48                 LString filename = file + ".lyx";
49                 // File was generated without problems. Load it.
50                 buf = bufferlist.loadLyXFile(filename);
51         }
52         return buf;
53 }
54
55 // Provide the literate documentclass by parsing the file.
56 //
57 LString ImportNoweb::documentclass()
58 {
59         LString result = "literate-article"; // Default
60
61         FilePtr inputfile(file, FilePtr::read); 
62         if (!inputfile()) return "nofile"; // Should not happen!
63
64         char buf[BUFSIZE], *p, *q;
65
66         while(!feof(inputfile())) {
67                 (void)fgets(buf, BUFSIZE, inputfile());
68                 if ((p = strstr(buf, "\\documentclass"))) {
69                         while ((*p) && (*p != '{'))
70                                 p++;
71                         q = p++;
72                         while ((*q) && (*q != '}'))
73                                 q++;
74                         *q = '\0';
75                         result = p;
76                         result = "literate-" + result;
77                 }
78         }
79
80         return result;
81 }