From 859a525c6a735e2e14e271b34920e78715110888 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Fri, 12 Jul 2013 17:11:13 +0200 Subject: [PATCH] vlp-10 Using coding style in logcomp. --- doc/examples/geometria.log | 37 ---- src/preproc/prep.cpp | 427 +++++++++++++++++++------------------ 2 files changed, 217 insertions(+), 247 deletions(-) diff --git a/doc/examples/geometria.log b/doc/examples/geometria.log index 547792e..8a3cf96 100644 --- a/doc/examples/geometria.log +++ b/doc/examples/geometria.log @@ -2,7 +2,6 @@ #include "classes/gui.inc" (*Program ma pokazac dzialanie algorytmow geometrycznych *) (* o ktorych mowilam na wykladzie*) - signal ERROR_exec; CONST @@ -45,7 +44,6 @@ BEGIN While GUI_KeyPressed=/= 0 DO OD; END waitt; - UNIT clear_all : procedure; begin call GUI_Rect(my_ecranMinX, my_ecranMinY, my_ecranMaxX, @@ -53,7 +51,6 @@ call GUI_Rect(my_EcranMinX, MaxY-2*sz, my_EcranMaxX,MaxY-5,c_DarkGrey,c_DarkGrey); end clear_all; - UNIT clear : PROCEDURE(x0,y0,x1,y1,c1,c2: integer); (* wymaz wszystko w prostokacie (x0,y0)-(y1,y1) *) (* Zostaw ekran w kolorze c2*) @@ -115,9 +112,7 @@ BEGIN pref GRAPHICS block - (*-----------------------------------------------------------------------*) - (* M E N U *) (*-----------------------------------------------------------------------*) unit option : class(nb : integer); @@ -229,7 +224,6 @@ handlers call clear(minX+5,minY+sz+3,maxX-5,maxY-2*sz-1,c_white,c_lightGrey); call ENDRUN fi; - others call comment(" ERROR press YES to continue or NO to stop?"); @@ -299,7 +293,6 @@ end handlers; when 2 : call comment("Wczytanie danych do problemu otoczki."); call WczytajDane(il_punktow,TAB); when 3 : call comment("Dane do problemu przeciec odcinkow"); - when 4 : call comment("Tu ma byc informacja o algorytmie"); esac; @@ -310,7 +303,6 @@ end handlers; Nom(3) := "ODCINKI"; Nom(4) := "HELP"; end OPTIONS_MAIN; - unit OPTIONS_OTOCZKA : option class; unit virtual Action : procedure(j : integer); var x: integer, boo : boolean; @@ -387,7 +379,6 @@ end handlers; od; case i when 1 : il_punktow := il_punktow+10; - call GUI_Rect(pminX+150,pminY+10,pminX+180,pminY+25, c_green,c_green); call GUI_writeInt(pminX+150,pminY+10,il_punktow, c_darkGrey,c_green); when 2 : il_punktow := il_punktow-10; @@ -410,7 +401,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); call comment(""); call clear_all; end WczytajDane; - (*-------------------------------------------------------------*) UNIT PokazPunkty : procedure(il_punktow:integer, TAB:arrayof punkt); var i : integer, pp : punkt; @@ -420,7 +410,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); call pp.rysuj od; end PokazPunkty; - UNIT WylosujPunkty : procedure(il_punktow:integer; inout Tab:arrayof punkt); var pp : punkt; begin @@ -433,7 +422,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); od; call comment(""); end WylosujPunkty; - unit INFO : procedure(il,ilb : integer); begin call comment(""); @@ -447,7 +435,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); call STOP_IKONA.write_i; end INFO; (*--------------------------------------------------------------*) - Unit GRAHAM : procedure(il_punktow: integer, TAB : arrayof punkt); UNIT SORTUJ : procedure(p0:punkt); unit mniejsze : function(p,q:punkt) : boolean; @@ -458,7 +445,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); result := true fi; end mniejsze; - unit pokaz : procedure(c,k:integer); var i : integer; begin @@ -467,7 +453,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); od; call GUI_Line (p0.x,p0.y, Tab(k).x,Tab(k).y, c) end pokaz; - unit poprawHeap: procedure(k:integer); var i,j : integer, v : punkt; begin @@ -509,7 +494,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); call GUI_MousePressed(xx,yy,k); od; END SORTUJ; - var c, kk,i, lewy,prawy,gora,dol : integer , pp : punkt, Wielokat : arrayof punkt; begin @@ -524,7 +508,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); lewy:=1; prawy :=1; call STOP_IKONA.write_i; call continue_IKONA.write_i; - for i :=2 to il_punktow do if TAB(i).y>Tab(dol).y then dol:=i else @@ -560,15 +543,12 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); (*posortuj tablice Tab ze wzgledu na katy *) call SORTUJ(WIELOKAT(1)); (* Rysuj boki otoczki *) - end GRAHAM; - UNIT JARVIS : procedure(n:integer,TAB:arrayof punkt); BEGIN END JARVIS; - UNIT TROJKATY : procedure(n:integer,TAB:arrayof punkt); var Wielokat : arrayof punkt, i,j,k,x,kk :integer; BEGIN @@ -592,7 +572,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); od od; END TROJKATY; - UNIT NarysujWielokat : procedure(c,n:integer,T: arrayof punkt); var i : integer; BEGIN @@ -602,12 +581,10 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); od; call GUI_Line(T(1).x,T(1).y,T(n).x,T(n).y,c); END NarysujWielokat; - UNIT WYPISZ_INFO : procedure(cz,b,il_cz,il_b, ocena : integer); BEGIN END WYPISZ_INFO; - unit Insert: procedure(pp: punkt,Tab : arrayof punkt, il : integer); (* doloaczanie punktu pp do uporzadkowanej tablicy Tab o il-elementach *) var j : integer; @@ -620,14 +597,12 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); od; Tab(j+1) := pp; end Insert; - unit punkt : class(x,y,c: integer); var boo : boolean; unit mniejsze : function( p : punkt) : boolean; begin result := (y< p.y or (y=p.y and x< p.x)) end mniejsze; - unit naLewo : function(p1,p2: punkt):boolean; (*(x,y) jest na lewo (na ekranie ) od odcinka p1,p2 *) begin @@ -635,7 +610,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); result := true else result := false fi end naLewo; - unit rysuj : procedure; begin call GUI_Ellipse(x,y,5,5,0,360,c,c) @@ -646,7 +620,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); begin call GUI_Line(L(nr-1).x, L(nr-1).y, L(nr).x, L(nr).y, c_blue); end WYMAZ_KONIEC; - UNIT WNETRZE : procedure(n: integer, WIELOKAT: arrayof punkt;output k:integer); var i, j : integer, boo : boolean, pp: punkt; begin @@ -673,22 +646,18 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); fi od; end WNETRZE; - UNIT NaLewo : procedure(p1,p2:punkt; output cz,b : integer); var i : integer; begin end NaLewo; - UNIT chromosom : class(x,y, u,w,ocena: integer); begin end chromosom; - (*--------------------------------------------------------------*) UNIT ODCINKI : procedure; END Odcinki; - UNIT ALG_2 : procedure(ilCZ, ilB : integer); var POKOLENIE : arrayof chromosom, ch : chromosom, @@ -707,7 +676,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); (*--------------------------------------------------------------*) - VAR TAB : arrayof punkt, il_punktow, il_porownan: integer, OK_ikona,YES_ikona,NO_ikona, STOP_IKONA, EXIT_IKONA, CONTINUE_IKONA : IKONA, @@ -739,7 +707,6 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); STOP_IKONA := new IKONA(c_green,590,430,635,460,3,"STOP"); CONTINUE_IKONA := new IKONA(c_green,450,430,550,460,3,"CONTINUE"); - (* Strona tytulowa *) CALL GUI_Rect(minX+1,minY+1,maxX-2,maxY-2,c_black,c_lightGrey); @@ -760,11 +727,8 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); menu_main.ICONES(4).sub_menu := new menu(minX,maxX,minY,maxY,new OPTIONS_help(3)); - menu_main.ICONES(2).sub_menu := new menu(minX,maxX,minY,maxY,new OPTIONS_OTOCZKA(4)); - - attach(menu_main); @@ -776,5 +740,4 @@ call GUI_writeInt(pminX+150,pminY+45, i, c_darkGrey,c_green); END GEOMETRIA; - \ No newline at end of file diff --git a/src/preproc/prep.cpp b/src/preproc/prep.cpp index 4405768..7a00924 100644 --- a/src/preproc/prep.cpp +++ b/src/preproc/prep.cpp @@ -1,4 +1,3 @@ - #include #include #include @@ -12,224 +11,232 @@ class IncFile { public: - char filename[255]; - int start, len; - IncFile(char *s,int st) {strcpy(filename,s);start=st;len=0;}; + char filename[255]; + int start, len; + IncFile(char *s, int st) + { + strcpy(filename,s); + start=st; + len=0; + }; }; QList inc; IncFile *findTrueLine(int ln, int *trueline) { - IncFile *pom,*pom1; - QList pl; - int c1=0,c2=0; - - -if (inc.isEmpty()) { *trueline=ln;return(NULL);} -pl.clear(); -pom=inc.first(); -if (pom->start>ln) {*trueline=ln;return(NULL);} - -while ( (pom!=NULL) && (ln>pom->start)) - { - - if (lnstart+pom->len) {*trueline=ln-pom->start; - return(pom);} - pl.append(pom); - pom=inc.next(); - } - - if (pom != NULL) - { - pom1=pl.first();c1=0; - while (pom1!=NULL) { c1+=pom1->len;pom1=pl.next(); } - *trueline=ln-c1; return(NULL); - } - else - { - pom1=inc.first();c1=0; - while (pom1!=NULL) { c1+=pom1->len;pom1=inc.next(); } - *trueline=ln-c1; return(NULL); - } - return(NULL); + IncFile *pom, *pom1; + QList pl; + int c1 = 0, c2 = 0; + + if (inc.isEmpty()) { + *trueline = ln; + return NULL; + } + pl.clear(); + pom = inc.first(); + if (pom->start > ln) { + *trueline = ln; + return NULL; + } + + while ((pom != NULL) && (ln > pom->start)) { + if (ln < pom->start + pom->len) { + *trueline = ln-pom->start; + return pom; + } + pl.append(pom); + pom=inc.next(); + } + + if (pom != NULL) { + pom1 = pl.first(); + c1=0; + while (pom1 != NULL) { + c1 += pom1->len; + pom1 = pl.next(); + } + *trueline = ln - c1; + return NULL; + } else { + pom1 = inc.first(); + c1 = 0; + while (pom1 != NULL) { + c1 += pom1->len; + pom1=inc.next(); + } + *trueline = ln - c1; + return NULL; + } + return NULL; } int main(int argc,char **argv) { - char homedir[255]; - char mydir[255],ss[255],fname[255]; - QString poms,poms1,poms2; - - int currentline=1; - int i,j,line,tline; - - - - inc.clear(); - poms.sprintf("%s",argv[1]); - i=poms.findRev('/',poms.length()-1,FALSE); - - -//******* get home directory - if (i!=-1) - { - poms1=poms.left(i+1); - strcpy(homedir,poms1.data()); - } - else strcpy(homedir,""); - - poms.sprintf("%s",argv[0]); - i=poms.findRev('/',poms.length()-1,FALSE); - if (i!=-1) poms1=poms.left(i); - else poms1.sprintf("."); - strcpy(mydir,poms1.data()); - - poms.sprintf("%s",argv[1]); - i=poms.findRev(".log",poms.length()-1,FALSE); - poms1=poms.left(i); - strcpy(fname,poms1.data()); - - -// ******************** - - poms.sprintf("%s/.cmp00",mydir); - poms1.sprintf("%s/cmp01.log",mydir); - unlink(poms.data()); - unlink(poms1.data()); - - QFile compfile(poms1.data()); - QFile srcfile(argv[1]); - - - if (!compfile.open(IO_WriteOnly)) - {fprintf(stdout,"Cannot open temp file to write %s\n",poms1.data());exit(1);} - - if (!srcfile.open(IO_ReadOnly)) - {fprintf(stdout,"Cannot open file\n");exit(1);} - - QTextStream comps(&compfile); - QTextStream src(&srcfile); - - - while (!src.eof()) - { - poms = src.readLine(); - i=poms.find("#include"); - if (i!=-1) - { // get include file - i=poms.find('"'); - if (i!=-1) j=poms.find('"',i+1); - 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()); - if (!pomf.open(IO_ReadOnly)) - { - fprintf(stdout,"Cannot open include file: %s\n",poms2.data()); - exit(1); - } - QTextStream pomstream(&pomf); - while (!pomstream.eof()) - { - poms1=pomstream.readLine(); - comps<len++; - currentline++; - } - pomf.close(); - inc.append(p); - } - } - else - { - comps< %s/.cmp00",mydir,mydir,mydir); - if (system(ss)==-1) - { - fprintf(stdout,"Cannot execute compiler\n"); - exit(1); - } - - - poms1.sprintf("%s.lcd",fname); - - if (QFile::exists(poms.data())) - { - rename(poms.data(),poms1.data()); - unlink(poms.data()); - fprintf(stdout,"Compile ok\n"); - sprintf(ss,"%s/gen %s",mydir,fname); - if (system(ss)==-1) - { - fprintf(stdout,"Cannot execute generator\n"); - exit(1); - } - poms.sprintf("%s.ccd",fname); - if (QFile::exists(poms.data())) {unlink(poms1.data());} - } - else -{ - fprintf(stdout,"Errors\n"); - - poms.sprintf("%s/.cmp00",mydir); - QFile err(poms.data()); - - if (!err.open(IO_ReadOnly)) - { fprintf(stdout,"Cannot open error file\n"); - exit(1); - } - QTextStream errstream(&err); - IncFile *fl; - - poms=errstream.readLine(); - i=poms.find("LOGLAN-82"); - while( (!errstream.eof()) && (i==-1)) - { - poms=errstream.readLine(); - i=poms.find("LOGLAN-82"); - } // *** - - while (!errstream.eof()) - { - poms=errstream.readLine(); - i=poms.find("ERROR"); - if (i!=-1) - { - i=i-2; - j=poms.findRev(' ',i); - 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()); - } - } - err.close(); -} // errors - - poms.sprintf("%s/cmp01.log",mydir); - unlink(poms.data()); - poms.sprintf("%s/.cmp00",mydir); - unlink(poms.data()); + char homedir[255]; + char mydir[255]; + char ss[255]; + char fname[255]; + QString poms, poms1, poms2; + + int currentline = 1; + int i, j, line, tline; -return(0); + inc.clear(); + poms.sprintf("%s", argv[1]); + i = poms.findRev('/', poms.length() - 1, FALSE); + + //******* get home directory + if (i != -1) { + poms1 = poms.left(i + 1); + strcpy(homedir, poms1.data()); + } + else + strcpy(homedir, ""); + + poms.sprintf("%s", argv[0]); + i = poms.findRev('/', poms.length() - 1, FALSE); + if (i != -1) { + poms1=poms.left(i); + } + else + poms1.sprintf("."); + + strcpy(mydir,poms1.data()); + + poms.sprintf("%s", argv[1]); + i = poms.findRev(".log", poms.length()-1, FALSE); + poms1 = poms.left(i); + strcpy(fname, poms1.data()); + + // ******************** + + poms.sprintf("%s/.cmp00", mydir); + poms1.sprintf("%s/cmp01.log", mydir); + unlink(poms.data()); + unlink(poms1.data()); + + QFile compfile(poms1.data()); + QFile srcfile(argv[1]); + + if (!compfile.open(IO_WriteOnly)) { + fprintf(stdout,"Cannot open temp file to write %s\n", poms1.data()); + exit(1); + } + + if (!srcfile.open(IO_ReadOnly)) { + fprintf(stdout, "Cannot open file\n"); + exit(1); + } + + QTextStream comps(&compfile); + QTextStream src(&srcfile); + + while (!src.eof()) { + poms = src.readLine(); + i = poms.find("#include"); + if (i != -1) { + /* get include file */ + i=poms.find('"'); + if (i != -1) { + j=poms.find('"',i+1); + } + 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()); + if (!pomf.open(IO_ReadOnly)) { + fprintf(stdout, "Cannot open include file: %s\n", poms2.data()); + exit(1); + } + QTextStream pomstream(&pomf); + while (!pomstream.eof()) { + poms1 = pomstream.readLine(); + comps << poms1.data(); + comps << "\n"; + p->len++; + currentline++; + } + pomf.close(); + inc.append(p); + } + } else { + comps << poms.data(); + comps << "\n"; + } + currentline++; + }/* eof */ + + srcfile.close(); + compfile.close(); + + poms.sprintf("%s/cmp01.lcd", mydir); + unlink(poms.data()); + + sprintf(ss, "%s/loglan %s/cmp01 > %s/.cmp00", mydir, mydir, mydir); + if (system(ss) == -1) { + fprintf(stdout, "Cannot execute compiler\n"); + exit(1); + } + + poms1.sprintf("%s.lcd", fname); + + if (QFile::exists(poms.data())) { + rename(poms.data(), poms1.data()); + unlink(poms.data()); + fprintf(stdout, "Compile ok\n"); + sprintf(ss,"%s/gen %s", mydir, fname); + if (system(ss)==-1) { + fprintf(stdout, "Cannot execute generator\n"); + exit(1); + } + poms.sprintf("%s.ccd", fname); + if (QFile::exists(poms.data())) { + unlink(poms1.data()); + } + } else { + fprintf(stdout, "Errors\n"); + poms.sprintf("%s/.cmp00", mydir); + QFile err(poms.data()); + + if (!err.open(IO_ReadOnly)) { + fprintf(stdout,"Cannot open error file\n"); + exit(1); + } + QTextStream errstream(&err); + IncFile *fl; + + poms = errstream.readLine(); + i = poms.find("LOGLAN-82"); + while ((!errstream.eof()) && (i == -1)) { + poms = errstream.readLine(); + i = poms.find("LOGLAN-82"); + } // *** + + while (!errstream.eof()) { + poms = errstream.readLine(); + i = poms.find("ERROR"); + if (i != -1) { + i = i-2; + j = poms.findRev(' ', i); + 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()); + } + } + err.close(); + } // errors + + poms.sprintf("%s/cmp01.log",mydir); + unlink(poms.data()); + poms.sprintf("%s/.cmp00",mydir); + unlink(poms.data()); + + return 0; } -- 2.30.2