1 #include <QtCore/QList>
2 #include <QtCore/QString>
4 #include <QtCore/qfile.h>
5 #include <QtCore/QTextStream>
16 IncFile(char *s, int st)
26 IncFile *findTrueLine(int ln, int *trueline)
40 if (pom->start > ln) {
45 while ((pom != NULL) && (ln > pom->start)) {
46 if (ln < pom->start + pom->len) {
47 *trueline = ln-pom->start;
57 while (pom1 != NULL) {
59 pom1 = pl.takeFirst();
66 while (pom1 != NULL) {
76 int main(int argc,char **argv)
82 QString poms, poms1, poms2;
85 int i, j, line, tline;
88 poms.sprintf("%s", argv[1]);
89 i = poms.findRev('/', poms.length() - 1, FALSE);
91 //******* get home directory
93 poms1 = poms.left(i + 1);
94 strcpy(homedir, poms1.toStdString().c_str());
99 poms.sprintf("%s", argv[0]);
100 i = poms.findRev('/', poms.length() - 1, FALSE);
107 strcpy(mydir, poms1.toStdString().c_str());
109 poms.sprintf("%s", argv[1]);
110 i = poms.findRev(".log", poms.length()-1, FALSE);
111 poms1 = poms.left(i);
112 strcpy(fname, poms1.toStdString().c_str());
114 // ********************
116 poms.sprintf("%s/.cmp00", mydir);
117 poms1.sprintf("%s/cmp01.log", mydir);
118 unlink(poms.toStdString().c_str());
119 unlink(poms1.toStdString().c_str());
121 QFile compfile(poms1);
122 QFile srcfile(argv[1]);
124 if (!compfile.open(IO_WriteOnly)) {
125 fprintf(stdout,"Cannot open temp file to write %s\n", poms1.toStdString().c_str());
129 if (!srcfile.open(IO_ReadOnly)) {
130 fprintf(stdout, "Cannot open file\n");
134 QTextStream comps(&compfile);
135 QTextStream src(&srcfile);
137 while (!src.atEnd()) {
138 poms = src.readLine();
139 i = poms.find("#include");
141 /* get include file */
144 j=poms.find('"',i+1);
146 if ((i != -1) && (j != -1)) {
148 poms1 = poms.mid(i + 1, j - i - 1);
149 p = new IncFile((char*)poms1.ascii(),
151 poms2.sprintf("%s%s", homedir, poms1.toStdString().c_str());
152 QFile pomf(poms2.toStdString().c_str());
153 if (!pomf.open(IO_ReadOnly)) {
154 fprintf(stdout, "Cannot open include "
155 "file: %s\n", poms2.toStdString().c_str());
158 QTextStream pomstream(&pomf);
159 while (!pomstream.atEnd()) {
160 poms1 = pomstream.readLine();
161 comps << poms1.toStdString().c_str();
170 comps << poms.toStdString().c_str();
179 poms.sprintf("%s/cmp01.lcd", mydir);
180 unlink(poms.toStdString().c_str());
182 sprintf(ss, "%s/loglan %s/cmp01 > %s/.cmp00", mydir, mydir, mydir);
183 if (system(ss) == -1) {
184 fprintf(stdout, "Cannot execute compiler\n");
188 poms1.sprintf("%s.lcd", fname);
190 if (QFile::exists(poms.toStdString().c_str())) {
191 rename(poms.toStdString().c_str(), poms1.toStdString().c_str());
192 unlink(poms.toStdString().c_str());
193 fprintf(stdout, "Compile ok\n");
194 sprintf(ss,"%s/gen %s", mydir, fname);
195 if (system(ss)==-1) {
196 fprintf(stdout, "Cannot execute generator\n");
199 poms.sprintf("%s.ccd", fname);
200 if (QFile::exists(poms.toStdString().c_str())) {
201 unlink(poms1.toStdString().c_str());
204 fprintf(stdout, "Errors\n");
205 poms.sprintf("%s/.cmp00", mydir);
206 QFile err(poms.toStdString().c_str());
208 if (!err.open(IO_ReadOnly)) {
209 fprintf(stdout,"Cannot open error file\n");
212 QTextStream errstream(&err);
215 poms = errstream.readLine();
216 i = poms.find("LOGLAN-82");
217 while ((!errstream.atEnd()) && (i == -1)) {
218 poms = errstream.readLine();
219 i = poms.find("LOGLAN-82");
222 while (!errstream.atEnd()) {
223 poms = errstream.readLine();
224 i = poms.find("ERROR");
227 j = poms.findRev(' ', i);
228 poms1 = poms.mid(j + 1, i - j);
229 line = poms1.toInt();
230 fl = findTrueLine(line, &tline);
231 poms2 = poms.right(poms.length() - i - 1);
233 fprintf(stdout, "%s: ", fl->filename);
234 fprintf(stdout, "%d %s\n",
235 tline, poms2.toStdString().c_str());
241 poms.sprintf("%s/cmp01.log",mydir);
242 unlink(poms.toStdString().c_str());
243 poms.sprintf("%s/.cmp00",mydir);
244 unlink(poms.toStdString().c_str());