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)
34 QListIterator<IncFile*> incFileIterator(inc);
35 if (!incFileIterator.hasNext()) {
40 pom = incFileIterator.next();
41 if (pom->start > ln) {
46 while ((incFileIterator.hasNext()) && (ln > pom->start)) {
47 if (ln < pom->start + pom->len) {
48 *trueline = ln-pom->start;
52 pom=incFileIterator.next();
55 if (incFileIterator.hasNext()) {
56 QListIterator<IncFile*> plIterator(pl);
58 while (plIterator.hasNext()) {
59 pom1 = plIterator.next();
65 incFileIterator.toFront();
67 while (incFileIterator.hasNext()) {
68 pom1 = incFileIterator.next();
77 int main(int argc,char **argv)
83 QString poms, poms1, poms2;
86 int i, j, line, tline;
89 poms.sprintf("%s", argv[1]);
90 i = poms.findRev('/', poms.length() - 1, FALSE);
92 //******* get home directory
94 poms1 = poms.left(i + 1);
95 strcpy(homedir, poms1.toStdString().c_str());
100 poms.sprintf("%s", argv[0]);
101 i = poms.findRev('/', poms.length() - 1, FALSE);
108 strcpy(mydir, poms1.toStdString().c_str());
110 poms.sprintf("%s", argv[1]);
111 i = poms.findRev(".log", poms.length()-1, FALSE);
112 poms1 = poms.left(i);
113 strcpy(fname, poms1.toStdString().c_str());
115 // ********************
117 poms.sprintf("%s/.cmp00", mydir);
118 poms1.sprintf("%s/cmp01.log", mydir);
119 unlink(poms.toStdString().c_str());
120 unlink(poms1.toStdString().c_str());
122 QFile compfile(poms1);
123 QFile srcfile(argv[1]);
125 if (!compfile.open(IO_WriteOnly)) {
126 fprintf(stdout,"Cannot open temp file to write %s\n", poms1.toStdString().c_str());
130 if (!srcfile.open(IO_ReadOnly)) {
131 fprintf(stdout, "Cannot open file\n");
135 QTextStream comps(&compfile);
136 QTextStream src(&srcfile);
138 while (!src.atEnd()) {
139 poms = src.readLine();
140 i = poms.find("#include");
142 /* get include file */
145 j=poms.find('"',i+1);
147 if ((i != -1) && (j != -1)) {
149 poms1 = poms.mid(i + 1, j - i - 1);
150 p = new IncFile((char*)poms1.ascii(),
152 poms2.sprintf("%s%s", homedir, poms1.toStdString().c_str());
153 QFile pomf(poms2.toStdString().c_str());
154 if (!pomf.open(IO_ReadOnly)) {
155 fprintf(stdout, "Cannot open include "
156 "file: %s\n", poms2.toStdString().c_str());
159 QTextStream pomstream(&pomf);
160 while (!pomstream.atEnd()) {
161 poms1 = pomstream.readLine();
162 comps << poms1.toStdString().c_str();
171 comps << poms.toStdString().c_str();
180 poms.sprintf("%s/cmp01.lcd", mydir);
181 unlink(poms.toStdString().c_str());
183 sprintf(ss, "%s/loglan %s/cmp01 > %s/.cmp00", mydir, mydir, mydir);
184 if (system(ss) == -1) {
185 fprintf(stdout, "Cannot execute compiler\n");
189 poms1.sprintf("%s.lcd", fname);
191 if (QFile::exists(poms.toStdString().c_str())) {
192 rename(poms.toStdString().c_str(), poms1.toStdString().c_str());
193 unlink(poms.toStdString().c_str());
194 fprintf(stdout, "Compile ok\n");
195 sprintf(ss,"%s/gen %s", mydir, fname);
196 if (system(ss)==-1) {
197 fprintf(stdout, "Cannot execute generator\n");
200 poms.sprintf("%s.ccd", fname);
201 if (QFile::exists(poms.toStdString().c_str())) {
202 unlink(poms1.toStdString().c_str());
205 fprintf(stdout, "Errors\n");
206 poms.sprintf("%s/.cmp00", mydir);
207 QFile err(poms.toStdString().c_str());
209 if (!err.open(IO_ReadOnly)) {
210 fprintf(stdout,"Cannot open error file\n");
213 QTextStream errstream(&err);
216 poms = errstream.readLine();
217 i = poms.find("LOGLAN-82");
218 while ((!errstream.atEnd()) && (i == -1)) {
219 poms = errstream.readLine();
220 i = poms.find("LOGLAN-82");
223 while (!errstream.atEnd()) {
224 poms = errstream.readLine();
225 i = poms.find("ERROR");
228 j = poms.findRev(' ', i);
229 poms1 = poms.mid(j + 1, i - j);
230 line = poms1.toInt();
231 fl = findTrueLine(line, &tline);
232 poms2 = poms.right(poms.length() - i - 1);
234 fprintf(stdout, "%s: ", fl->filename);
235 fprintf(stdout, "%d %s\n",
236 tline, poms2.toStdString().c_str());
242 poms.sprintf("%s/cmp01.log",mydir);
243 unlink(poms.toStdString().c_str());
244 poms.sprintf("%s/.cmp00",mydir);
245 unlink(poms.toStdString().c_str());