1. Translate from Pascal to Euphoria
- Posted by Paulo Fernandes <paulof1953 at gmail.com> Jun 01, 2007
- 646 views
- Last edited Jun 02, 2007
Hi, ALL! I would like somebody here translate MyProg below, from Pascal to Euphoria, because I intend to mensure the performances of both. Who would have the kindness to do for me? Thanks a lot! Paulo Fernandes P.Alegre/RS Brazil {----------------------------------------------------------------------* * Prog.: MyProg.pas * Data : 19/05/2007 * Obs. : Faz trabalho parcial de outro software *----------------------------------------------------------------------} Program MyProg (p1, p2, p3); Uses Dos; Const TAMBLOCO = 10000; NUMJOGOS = 14; Var totCPs : longint; limTol : longint; aCPs : array [1..TAMBLOCO] of string[NUMJOGOS]; mMgs : array [1..TAMBLOCO,1..4] of byte; {----------------------------------------------------------------------} procedure MostHora; var s1, s2 : string; f9 : text; begin s1:='C:\Windows\System32\Cmd.exe '; s2:='/C Time < C:\Enter. > Wrk09.txt'; exec(s1,s2); assign(f9,'Wrk09.txt'); reset (f9); readln(f9,s1); close (f9); s2:=copy(s1,13,20); write(s2); end; {----------------------------------------------------------------------} procedure PegaCPs; var comb : string[NUMJOGOS]; i, j : longint; f1 : text; begin MostHora; writeln('--Pegando CPs...'); assign (f1,'KillCPs.txt'); reset (f1); totCPs:=1; while not(eof(f1)) do begin read(f1,comb); aCPs[totCPs]:=comb; for i:=1 to 4 do begin {lê limites} read(f1,mMgs[totCPs,i]); end; read(f1,limTol); readln(f1); totCPs:=totCPs+1; end; totCPs:=totCPs-1; for i:=1 to totCPs do begin write(aCPs[i]:NUMJOGOS); for j:=1 to 4 do begin write(mMgs[i,j]:3); end; write(limTol:3); writeln(''); end; close(f1); end; {----------------------------------------------------------------------} procedure Expurga (arqEnt, arqSai, arqRes: string); var comb : string[NUMJOGOS]; f1, f2, f3 : text; iReg, oks : longint; i, j, nTol : longint; nPts : byte; perc : real; eBoa : boolean; begin MostHora; writeln('--Fazendo Expurgo...'); assign (f1,arqEnt); reset (f1); assign (f2,arqSai); rewrite(f2); iReg:=0; oks:=0; while not(eof(f1)) do begin readln(f1,comb); iReg:=iReg+1; eBoa:=true; nTol:=0; for i:=1 to totCPs do begin nPts:=0; for j:=1 to NUMJOGOS do begin if comb[j]=aCPs[i,j] then begin nPts:=nPts+1; end; end; if (nPts < mMgs[i,1]) or (nPts > mMgs[i,2]) then begin nTol:=nTol+1; if nTol > limTol then begin eBoa:=false; break; end; end; end; if eBoa=true then begin oks:=oks+1; writeln(f2,comb); end; end; perc:=(oks*1.00)/iReg*100.00; writeln(iReg:10, oks:10, perc:09:2,'%'); { salva dados em arquivo } assign (f3,arqRes); append (f3); writeln(f3, iReg:7, ' ', oks, ' ', perc:5:2, '%'); close(f1); close(f2); close(f3); end; Begin if ParamCount <> 3 then begin write(#7, #7); writeln('>> Necessário informar *arqEnt*, *arqSai*, *arqRes* '); readln; halt(1); end; PegaCPs; Expurga(ParamStr(1),ParamStr(2),ParamStr(3)); MostHora; writeln('--Fim de Programa======'); End.
2. Re: Translate from Pascal to Euphoria
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 02, 2007
- 639 views
Paulo Fernandes wrote: > > Hi, ALL! > > I would like somebody here translate MyProg below, from Pascal to > Euphoria, because I intend to mensure the performances of both. > Who would have the kindness to do for me? Thanks a lot! While there are some who speak portugese on this list, the majority do not; guessing what code does is sometimes fun, but hardly fair now, is it? What is this program actually supposed to do? Do I need to know what this says? > * Obs. : Faz trabalho parcial de outro software And I have no idea whatsoever what this is attempting to do: > s1:='C:\Windows\System32\Cmd.exe '; > s2:='/C Time < C:\Enter. > Wrk09.txt'; > exec(s1,s2); (I gave up after that point) Oh, and is this homework from Ricardo, perchance? Regards, Pete
3. Re: Translate from Pascal to Euphoria
- Posted by Paulo Fernandes <paulof1953 at gmail.com> Jun 03, 2007
- 626 views
Hello, Pete! Thank you for answer. >> * Obs. : Faz trabalho parcial de outro software; this means 'Does partial work to another software'. The original "system" is wrote in Visual Fox Pro, a wonderful software, but is slow to process huge data inputs. So, some routine I have wrote in Pascal language to gain time. The question is: is Euphoria faster than Pascal??!! I don't know... The program is simple: it reads a limits data file (KillCPs.txt, procedure PegaCPs) and, after, it reads another txt file (arqEnt or fileIn) passed through command line, throwing away uninteresting records, and save, in another file (arqSai or fileOut) passing through command line too, those records that are good (var eBoa), confronted with limits. Also is recorded "reads", "oks", "percent" in another file (arqRes, resultFile), passed through command line too. And it's all. Simple, no? The procedure MostHora is only to show the system time (ShowTime). How I don't know how to put the time on screen by Pascal, I get it by system, recording a file (Wrk09.txt) with the system time that is read to get the time. An anacronism, of course, but it has worked! I could do the translate, but I have many doubts, like: 1) how can I pass parameters through command line when I run the Euphoria program? 2) how can I pass (and receive, of course) parameters between procedures? 3) how can I may convert memory variable from Pascal to Euphoria? 4) how can I open and read a txt file, puting data into variables? 5) how can I write a txt file? 6) in Euphoria, is there an exe file, since Euphoria is a interpreted language? Can I call it from a Visual Fox Pro aplication? The most important answer that I need is to the question: is Euphoria faster than Pascal??!! Thanks for all. Paulo Fernandes Brazil Pete Lomax wrote: > > Paulo Fernandes wrote: > > > > Hi, ALL! > > > > I would like somebody here translate MyProg below, from Pascal to > > Euphoria, because I intend to mensure the performances of both. > > Who would have the kindness to do for me? Thanks a lot! > > While there are some who speak portugese on this list, the majority do not; > > guessing what code does is sometimes fun, but hardly fair now, is it? > What is this program actually supposed to do? > Do I need to know what this says? > > * Obs. : Faz trabalho parcial de outro software > And I have no idea whatsoever what this is attempting to do: > > s1:='C:\Windows\System32\Cmd.exe '; > > s2:='/C Time < C:\Enter. > Wrk09.txt'; > > exec(s1,s2); > (I gave up after that point) > > Oh, and is this homework from Ricardo, perchance? > > Regards, > Pete
4. Re: Translate from Pascal to Euphoria
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Jun 03, 2007
- 624 views
Paulo Fernandes wrote: > > Hi, ALL! > > I would like somebody here translate MyProg below, from Pascal to > Euphoria, because I intend to mensure the performances of both. > Who would have the kindness to do for me? Thanks a lot! > > Paulo Fernandes > P.Alegre/RS > Brazil > Here is a translation attempt. I haven't programmed in Pascal for a while, so I may have forgotten about subtleties of buffered and formatted file I/O. I left translation notes to help you see hw I translated nontrivial parts. Don't assume it will have the right formatting out of the box. For this sort of stuff, Pascal is way easier to write code with. CChris -- TR: {} comment brackets are replaced by trailing -- comments ---------------------------------------------------------------------- -- * Prog.: MyProg.pas -- * Data : 19/05/2007 -- * Obs. : Faz trabalho parcial de outro software -- *---------------------------------------------------------------------- -- TR: call your file MyProg.ex, and process cmd line therein -- Program MyProg (p1, p2, p3); -- TR: not needed, as we are going to use cross platform I/O routines -- Uses Dos; constant TAMBLOCO = 10000, NUMJOGOS = 14 integer totCPs integer limTol -- aCPs : array [1..TAMBLOCO] of string[NUMJOGOS]; -- TR: Eu doesn't know about arrays or typed sequences. This data will be used at initialisation time sequence aCPs -- mMgs : array [1..TAMBLOCO,1..4] of byte; sequence mMgs ---------------------------------------------------------------------- procedure MostHora() sequence s1, s2 -- TR: files are represented by integer handles integer f9 -- TR: Eu doesn't know about instruction groups -- begin -- TR: '\' must be escaped in manifest strings, as it is the escape character s1="C:\\Windows\\System32\\Cmd.exe " s2="/C Time < C:\\Enter. > Wrk09.txt" -- exec(s1,s2); -- TR: please refer to the date() and time() commands. I don't know if the formats are the same as yours. system_exec(s1 & s2,2) -- assign(f9,'Wrk09.txt'); -- reset (f9); f9 = open("Wrk09.txt","r") -- readln(f9,s1); s1 = gets(f9) close (f9) -- s2:=copy(s1,13,20); s2 = s1[13..13+20-1] -- write(s2); -- TR: 1 is standard output puts(1,s2) end procedure constant FieldSeparator = ',' -- hopefully include get.e function split(sequence s) -- This convrts a flat comme separated record into parts -- converting numeric text to values integer pos sequence field,result result={} while 1 do pos=find(FieldSeparator,s) field = value(s) if field[1] = GET_SUCCESS then -- number result &= field[2] else -- text if pos>0 then result=append(result,s[1..pos-1]) else result=append(result,s) end if end if if pos=0 then exit else s=s[pos+1..$] end if end while return result end function ---------------------------------------------------------------------- procedure PegaCPs() > var comb : string[NUMJOGOS]; -- TR: this may be an integer as it will receive the gets() output object comb integer i, j integer f1 -- TR: needed to read the blocks -- begin MostHora() -- writeln('--Pegando CPs...'); -- TR: The line break must be explicits puts(1,"\n--Pegando CPs...\n") -- assign (f1,'KillCPs.txt'); -- reset (f1); f1 = open("KillCPs.txt'","r") totCPs=1 -- TR: must initialise sequences before writing to them 3Mgs = repeat(0,TAMBLOCO) aCPs = repeat(0,TAMBLOCO) -- while not(eof(f1)) do begin -- TR: There is no eof(), use the type of what gets() returns while 1 do -- read(f1,comb); comb = gets(f1) if atom(comb) then exit end if -- TR: I assumed your record format is: a string,comma,byte1,comma,byte2,comma,byte3,comma,byte4,lineTol -- TR: the string being at most NUMJOGOS char long. comb = split(comb) aCPs[totCPs]= comb[1] -- for i=1 to 4 do --lê limites -- read(f1,mMgs[totCPs,i]); -- end for mMgs[totCPs] = comb[2..5] -- read(f1,limTol); limTol = comb[$] -- readln(f1); totCPs+=1 end while totCPs-=1 for i=1 to totCPs do -- write(aCPs[i]:NUMJOGOS); -- TR: can't use constants in formats directly -- TR: you'd have to build a format string and then apply it -- TR: I also assumed you want left justified text. Remove the '-' to get right justification. printf(1,"%-14s",{aCPs[i]}) for j=1 to 4 do printf(1,"%-3s",{mMgs[i][j]}) end for printf(1,"%-3s",{limTol}) -- writeln(''); puts(1,'\n') end for close(f1) end procedure ---------------------------------------------------------------------- constant false = 0, true = not false procedure Expurga (sequence arqEnt,sequence arqSai,sequence arqRes) object comb -- : string[NUMJOGOS]; integer f1, f2, f3 integer iReg, oks integer i, j, nTol integer nPts atom perc -- no builtin boolean type, although it was requested many times integer eBoa sequence splComb MostHora() puts(1,"\n--Fazendo Expurgo...\n") -- assign (f1,arqEnt); -- reset (f1); f1 = open(arqEnt,"r") -- assign (f2,arqSai); -- rewrite(f2); f2 = open(arqSai,"w") iReg=0 oks=0 while 1 do comb = gets(f1) if atom(comb) then exit end if iReg+=1 eBoa=true nTol=0 splComb = split(comb) for i=1 to totCPs do nPts=0 for j=1 to NUMJOGOS do > if splComb[j]=aCPs[i][j] then nPts+=1 end if end for if nPts < mMgs[i][1]) or (nPts > mMgs[i][2]) then nTol+=1 if nTol > limTol then eBoa=false exit end if end if end for if eBoa=true then oks+=1 -- writeln(f2,comb); -- TR: writing a flat file as I expect it to be on entry -- TR: this can be made simpler using one line by field, but then you'd have to convert older files -- TR: I don't know if this issue is relevant. puts(f2,comb) end if end while perc=oks/(iReg*100) -- writeln(iReg:10, oks:10, perc:09:2,'%'); printf(1,"%-10s %-10s %-9:2d%%",{iReg,oks,perc}) -- salva dados em arquivo -- assign (f3,arqRes); -- append (f3); f3 = open(arqRes,"a") -- writeln(f3, iReg:7, ' ', oks, ' ', perc:5:2, '%'); printf(f3,"%-7d %d %5:2d%%",{iReg,oks,perc}) close(f1) close(f2) close(f3) end procedure -- Begin sequence cmd cmd = command_line() integer ParamCount if ParamCount != 2+3 then -- write(#7, #7); beep() beep() -- writeln('>> Necessário informar *arqEnt*, *arqSai*, *arqRes* '); -- TR: 2 is standard error puts(2,">> Necessário informar *arqEnt*, *arqSai*, *arqRes*\n") -- TR: probably not needed, as there is no buffered input -- readln; -- halt(1); abort(1) end if PegaCPs() -- Expurga(ParamStr(1),ParamStr(2),ParamStr(3)); Expurga(cmd[3],cmd[4],cmd[5]) MostHora() puts(1,"\n--Fim de Programa======\n") -- TR: not needed -- End. HTH CChris
5. Re: Translate from Pascal to Euphoria
- Posted by Ricardo Forno <ricardoforno at tutopia.com> Jun 03, 2007
- 602 views
Pete Lomax wrote: > > Paulo Fernandes wrote: > > > > Hi, ALL! > > > > I would like somebody here translate MyProg below, from Pascal to > > Euphoria, because I intend to mensure the performances of both. > > Who would have the kindness to do for me? Thanks a lot! > > While there are some who speak portugese on this list, the majority do not; > > guessing what code does is sometimes fun, but hardly fair now, is it? > What is this program actually supposed to do? > Do I need to know what this says? > > * Obs. : Faz trabalho parcial de outro software > And I have no idea whatsoever what this is attempting to do: > > s1:='C:\Windows\System32\Cmd.exe '; > > s2:='/C Time < C:\Enter. > Wrk09.txt'; > > exec(s1,s2); > (I gave up after that point) > > Oh, and is this homework from Ricardo, perchance? > > Regards, > Pete Hi, Pete. Your guess was not accurate. While I taught some Euphoria at the Kennedy University in Buenos Aires, the students do not know Pascal but instead C and C++. And I didn't gave them homework to translate from a language to another, but insted to try writing original programs in Euphoria. Moreover, Buenos Aires is located in Argentina, where people speak Spanish and not Portuguese. Both languages being very similar, I usually have no difficulty understanding and even writing and speaking brazilian Portuguese, especially considering that I took my holydays in Brazil during many years, and even attended to a Portuguese course... Oi Paulo, onde você mora? Best regards to all.
6. Re: Translate from Pascal to Euphoria
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Jun 04, 2007
- 615 views
<snipped/> > > I could do the translate, but I have many doubts, like: > 1) how can I pass parameters through command line when I run the Euphoria > program? > 2) how can I pass (and receive, of course) parameters between procedures? > 3) how can I may convert memory variable from Pascal to Euphoria? > 4) how can I open and read a txt file, puting data into variables? > 5) how can I write a txt file? > 6) in Euphoria, is there an exe file, since Euphoria is a interpreted > language? Can I call it from a Visual Fox Pro aplication? > The translation should answer most of these, xcept that: a/ Eu doesn't have pass by reference clls, so that var parameters could proe tricky to translate; b/ you can either bind/translate your Eu program to get a regular .exe. You can also call ex.exe from your application, passing it the name of the program to execute, including the parameters passed to it. CChris
7. Re: Translate from Pascal to Euphoria
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Jun 09, 2007
- 655 views
Paulo Fernandes wrote: > > Hi, ALL! > > I would like somebody here translate MyProg below, from Pascal to > Euphoria, because I intend to mensure the performances of both. > Who would have the kindness to do for me? Thanks a lot! > > Paulo Fernandes > P.Alegre/RS > Brazil > Here is a revised version. I kept the retrieving of date/time through the system, but changed the file format to pure binary fixed length, so as to achieve faster file access. I skipped most of earlier translation notes. Original program is here: http://www.listfilter.com/EUforum/m14180.html First translation is here: http://www.listfilter.com/EUforum/m14188.html
----------------------------------------------------------------------* -- * Prog.: MyProg.pas -- * Data : 19/05/2007 -- * Obs. : Faz trabalho parcial de outro software -- *---------------------------------------------------------------------- -- Program MyProg (p1, p2, p3); -- Uses Dos; -- TR: Most file access functions are in this standard include file include get.e constant TAMBLOCO = 10000, NUMJOGOS = 14, TAMREC = NUMJOGOS+4+1 integer totCPs integer limTol -- aCPs : array [1..TAMBLOCO] of string[NUMJOGOS]; sequence aCPs -- mMgs : array [1..TAMBLOCO,1..4] of byte; sequence mMgs ----------------------------------------------------------------------} procedure MostHora() sequence s1, s2 integer f9 s1="'C:\\Windows\\System32\\Cmd.exe " s2="/C Time < C:\\Enter. > Wrk09.txt" system_exec(s1 & s2,2) f9=open("Wrk09.txt'","r") s1 = gets(f9) close(f9) s2=s1[13..13+20-1] puts(1,s2&'\n') end procedure ---------------------------------------------------------------------- procedure PegaCPs() sequence comb integer i, j integer f1 MostHora() puts(1,"--Pegando CPs...") -- TR: open file in binary mode f1=open("KillCPs.txt","rb") -- TR: changed so as to skip the correcion after loop ends totCPs=0 while 1 do -- TR: read a fixed length chunk comb=get_bytes(f1,NUMJOGOS) -- read(f1,comb) -- TR: comb is {} if nothing else to read, something shorter if there's -- TR: a partial truncated record at the end. if length(comb)<NUMJOGOS then exit end if aCPs[totCPs]=comb mMgs[totCPs] = get_bytes(f1,4) -- TR: not sure here. If that parameter may be bigger than a byte, there's -- TR: an adjustment to make. limTol = getc(f1) totCPs+=1 end while for i=1 to totCPs do puts(1,aCPs[i]) -- TR: remember to tweak the format as needed. printf(1," %-3d %-3d %-3d %-3d %-3d\n",{mMgs[i],limTol}) end for close(f1) end procedure ---------------------------------------------------------------------- procedure Expurga (sequence arqEnt, sequence arqSai, sequence arqRes: string) sequence comb -- : string[NUMJOGOS]; integer f1, f2, f3 integer iReg, oks integer i, j, nTol -- TR: Eu stores integers as 4 bytes. integer nPts atom perc integer eBoa MostHora() puts(1,"\n--Fazendo Expurgo...\n") f1=open(arqEnt,"rb") f2=open(arqSai,"wb") iReg=0 oks=0 while 1 do comb=get_bytes(f1,TAMREC) -- TR: full record length -- assuming last parm is byte sized again if length(comb)<TAMREC then exit end if iReg+=1 eBoa=true nTol=0 for i=1 to totCPs do nPts=0 for j:=1 to NUMJOGOS do nPts+= (comb[j]=aCPs[i][j]) end for if (nPts < mMgs[i][1]) or (nPts > mMgs[i][2]) then nTol+=1 if nTol > limTol then eBoa:=false exit end if end if end for if eBoa=true then oks+=1 puts(f2,comb) end if end for perc=(oks/iReg)*100.0 printf(1,"%-10d %-10d %-9:2d%%\n",{iReg, oks, perc}) -- salva dados em arquivo f3 = open(arqRes,"a") printf(f3,"%-7d %-d %-5:2d%%\n",{iReg,oks,perc}) close(f1) close(f2) close(f3) end procedure -- Begin main sequence cmd cmd = command_line() if length(cmd) != 3+2 then beep() beep() puts(2,"\n>> Necessário informar *arqEnt*, *arqSai*, *arqRes*\n") abort(1) end if PegaCPs() Expurga(cmd[3],cmd[4],cmd[5]) MostHora() puts(1,"\n--Fim de Programa======\n")
I assuled limTol receives a byte; if not, adjust reading and writing as needed. Don't forget/be afraid tweaking format strings until you get the desired result. HTH CChris