X-Git-Url: https://git.dlugolecki.net.pl/?a=blobdiff_plain;f=src%2Fpreproc%2Fprep.cpp;h=020b3321845d595edc32cfa84d78c13b0244c6c9;hb=HEAD;hp=7a00924f8a3c59c289b477bead18ee5cbc1d07db;hpb=859a525c6a735e2e14e271b34920e78715110888;p=vlp.git diff --git a/src/preproc/prep.cpp b/src/preproc/prep.cpp index 7a00924..020b332 100644 --- a/src/preproc/prep.cpp +++ b/src/preproc/prep.cpp @@ -1,12 +1,11 @@ -#include -#include +#include +#include #include -#include -#include +#include +#include #include -#include +#include #include -#include class IncFile { @@ -21,49 +20,52 @@ public: }; }; -QList inc; +QList inc; IncFile *findTrueLine(int ln, int *trueline) { - IncFile *pom, *pom1; - QList pl; - int c1 = 0, c2 = 0; - - if (inc.isEmpty()) { + IncFile *pom; + IncFile *pom1; + QList pl; + int c1 = 0; +// int c2 = 0; + + QListIterator incFileIterator(inc); + if (!incFileIterator.hasNext()) { *trueline = ln; return NULL; - } + } pl.clear(); - pom = inc.first(); + pom = incFileIterator.next(); if (pom->start > ln) { *trueline = ln; return NULL; } - while ((pom != NULL) && (ln > pom->start)) { + while ((incFileIterator.hasNext()) && (ln > pom->start)) { if (ln < pom->start + pom->len) { *trueline = ln-pom->start; return pom; } pl.append(pom); - pom=inc.next(); + pom=incFileIterator.next(); } - if (pom != NULL) { - pom1 = pl.first(); + if (incFileIterator.hasNext()) { + QListIterator plIterator(pl); c1=0; - while (pom1 != NULL) { + while (plIterator.hasNext()) { + pom1 = plIterator.next(); c1 += pom1->len; - pom1 = pl.next(); } *trueline = ln - c1; return NULL; } else { - pom1 = inc.first(); + incFileIterator.toFront(); c1 = 0; - while (pom1 != NULL) { + while (incFileIterator.hasNext()) { + pom1 = incFileIterator.next(); c1 += pom1->len; - pom1=inc.next(); } *trueline = ln - c1; return NULL; @@ -81,7 +83,7 @@ int main(int argc,char **argv) int currentline = 1; int i, j, line, tline; - + inc.clear(); poms.sprintf("%s", argv[1]); i = poms.findRev('/', poms.length() - 1, FALSE); @@ -89,7 +91,7 @@ int main(int argc,char **argv) //******* get home directory if (i != -1) { poms1 = poms.left(i + 1); - strcpy(homedir, poms1.data()); + strcpy(homedir, poms1.toStdString().c_str()); } else strcpy(homedir, ""); @@ -102,37 +104,37 @@ int main(int argc,char **argv) else poms1.sprintf("."); - strcpy(mydir,poms1.data()); + strcpy(mydir, poms1.toStdString().c_str()); poms.sprintf("%s", argv[1]); i = poms.findRev(".log", poms.length()-1, FALSE); poms1 = poms.left(i); - strcpy(fname, poms1.data()); + strcpy(fname, poms1.toStdString().c_str()); // ******************** poms.sprintf("%s/.cmp00", mydir); poms1.sprintf("%s/cmp01.log", mydir); - unlink(poms.data()); - unlink(poms1.data()); + unlink(poms.toStdString().c_str()); + unlink(poms1.toStdString().c_str()); - QFile compfile(poms1.data()); + QFile compfile(poms1); QFile srcfile(argv[1]); if (!compfile.open(IO_WriteOnly)) { - fprintf(stdout,"Cannot open temp file to write %s\n", poms1.data()); + fprintf(stdout,"Cannot open temp file to write %s\n", poms1.toStdString().c_str()); exit(1); } if (!srcfile.open(IO_ReadOnly)) { - fprintf(stdout, "Cannot open file\n"); + fprintf(stdout, "Cannot open file: %s\n", srcfile.fileName().toStdString().c_str()); exit(1); } QTextStream comps(&compfile); QTextStream src(&srcfile); - while (!src.eof()) { + while (!src.atEnd()) { poms = src.readLine(); i = poms.find("#include"); if (i != -1) { @@ -144,17 +146,19 @@ int main(int argc,char **argv) if ((i != -1) && (j != -1)) { IncFile *p; poms1 = poms.mid(i + 1, j - i - 1); - p = new IncFile((char*)poms1.ascii(), currentline); - poms2.sprintf("%s%s", homedir, poms1.data()); - QFile pomf(poms2.data()); + p = new IncFile((char*)poms1.ascii(), + currentline); + poms2.sprintf("%s%s", homedir, poms1.toStdString().c_str()); + QFile pomf(poms2.toStdString().c_str()); if (!pomf.open(IO_ReadOnly)) { - fprintf(stdout, "Cannot open include file: %s\n", poms2.data()); + fprintf(stdout, "Cannot open include " + "file: %s\n", poms2.toStdString().c_str()); exit(1); } QTextStream pomstream(&pomf); - while (!pomstream.eof()) { + while (!pomstream.atEnd()) { poms1 = pomstream.readLine(); - comps << poms1.data(); + comps << poms1.toStdString().c_str(); comps << "\n"; p->len++; currentline++; @@ -163,7 +167,7 @@ int main(int argc,char **argv) inc.append(p); } } else { - comps << poms.data(); + comps << poms.toStdString().c_str(); comps << "\n"; } currentline++; @@ -173,7 +177,7 @@ int main(int argc,char **argv) compfile.close(); poms.sprintf("%s/cmp01.lcd", mydir); - unlink(poms.data()); + unlink(poms.toStdString().c_str()); sprintf(ss, "%s/loglan %s/cmp01 > %s/.cmp00", mydir, mydir, mydir); if (system(ss) == -1) { @@ -183,9 +187,9 @@ int main(int argc,char **argv) poms1.sprintf("%s.lcd", fname); - if (QFile::exists(poms.data())) { - rename(poms.data(), poms1.data()); - unlink(poms.data()); + if (QFile::exists(poms.toStdString().c_str())) { + rename(poms.toStdString().c_str(), poms1.toStdString().c_str()); + unlink(poms.toStdString().c_str()); fprintf(stdout, "Compile ok\n"); sprintf(ss,"%s/gen %s", mydir, fname); if (system(ss)==-1) { @@ -193,13 +197,18 @@ int main(int argc,char **argv) exit(1); } poms.sprintf("%s.ccd", fname); - if (QFile::exists(poms.data())) { - unlink(poms1.data()); + if (QFile::exists(poms.toStdString().c_str())) { + unlink(poms1.toStdString().c_str()); } } else { - fprintf(stdout, "Errors\n"); + QString errors; + errors.sprintf("Errors: %s does not exists, current path: %s\n", + poms.toStdString().c_str(), + QDir::currentPath().toStdString().c_str() + ); + fprintf(stdout, errors.toStdString().c_str()); poms.sprintf("%s/.cmp00", mydir); - QFile err(poms.data()); + QFile err(poms.toStdString().c_str()); if (!err.open(IO_ReadOnly)) { fprintf(stdout,"Cannot open error file\n"); @@ -210,33 +219,34 @@ int main(int argc,char **argv) poms = errstream.readLine(); i = poms.find("LOGLAN-82"); - while ((!errstream.eof()) && (i == -1)) { + while ((!errstream.atEnd()) && (i == -1)) { poms = errstream.readLine(); i = poms.find("LOGLAN-82"); - } // *** + } - while (!errstream.eof()) { + while (!errstream.atEnd()) { poms = errstream.readLine(); i = poms.find("ERROR"); if (i != -1) { i = i-2; j = poms.findRev(' ', i); - poms1 = poms.mid(j+1, i-j); + poms1 = poms.mid(j + 1, i - j); line = poms1.toInt(); fl = findTrueLine(line, &tline); poms2 = poms.right(poms.length() - i - 1); if (fl != NULL) fprintf(stdout, "%s: ", fl->filename); - fprintf(stdout, "%d %s\n", tline, poms2.data()); + fprintf(stdout, "%d %s\n", + tline, poms2.toStdString().c_str()); } } err.close(); - } // errors + } /* errors */ poms.sprintf("%s/cmp01.log",mydir); - unlink(poms.data()); + unlink(poms.toStdString().c_str()); poms.sprintf("%s/.cmp00",mydir); - unlink(poms.data()); + unlink(poms.toStdString().c_str()); return 0; }