Two little programs
- Posted by rforno at tutopia.com Aug 28, 2001
- 485 views
This is a multi-part message in MIME format. ------=_NextPart_000_00DB_01C1300B.A7964060 charset="iso-8859-1" Rob: I am sending the following little programs to put them in the Public Domain. tee.ex emulates UNIX's tee transl.ex translates text files from DOS to WINDOWS and vice-versa, in relation to the different representations of national characters in both systems. Comments in both source files explain their usage. Greetings. ------=_NextPart_000_00DB_01C1300B.A7964060 Content-Type: application/octet-stream; name="Tee.ex" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="Tee.ex" --Program to emulate Unix's tee --Author: R. M. Forno - Version 1.0 - 2001/08/24 --Example of use: --C:>program | ex tee zz --Or, if tee is compiled: --C:>program | tee zz --Will send output of program to both zz and Standard Output procedure tee() sequence c integer f, a c = command_line() if length(c) < 3 then printf(1, "%s\n", {"Missing output file"}) abort(1) end if c = c[3] f = open(c, "w") if f < 0 then printf(1, "%s\n", {"Cannot open output file " & c}) abort(2) end if while 1 do a = getc(0) if a < 0 then exit end if puts(f, a) puts(1, a) end while close(f) end procedure tee() ------=_NextPart_000_00DB_01C1300B.A7964060 Content-Type: application/octet-stream; name="transl.ex" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="transl.ex" --Program to translate characters from DOS to WINDOWS and vice-versa. --Author: R. M. Forno - Version 1.0 - 2000/08/24 --Representation of national characters differs between DOS and WINDOWS. --This program translates text files from one to the other = representation. --Usage: --C:>ex transl DOSTOWIN <input_file> <output_file> --Or: --C:>ex transl WINTODOS <input_file> <output_file> --When using the compiled version, replace 'ex transl' by 'transl' --Not all national characters are included in sequences 'dos' and 'win'. --If neccessary, add your national characters to both of them. --Characters in 'win' shold correspond, when viewed with a WINDOWS = program, -- to those in 'dos' when viewed with a DOS program. include wildcard.e sequence dos, win, c, inputfile, outputfile, direction, dostowin, = wintodos dos =3D = "=A0=82=A1=A2=A3=B5=90=D6=E0=E9=81=9A=A4=A5=A8=AD=87=80=A7=A6=85=8A=8D=95= =97=B7=D4=DE=E3=EB=83=88=8C=93=96=B6=D2=D7=E2=EA~=AA=8E=D3=D8=99=84=89=8B= =94=98" win =3D = "=E1=E9=ED=F3=FA=C1=C9=CD=D3=DA=FC=DC=F1=D1=BF=A1=E7=C7=BA=AA=E0=E8=EC=F2= =F9=C0=C8=CC=D2=D9=E2=EA=EE=F4=FB=C2=CA=CE=D4=DB~=AC=C4=CB=CF=D6=E4=EB=EF= =F6=FF" procedure init() dostowin =3D repeat(0, 256) for i =3D 2 to 256 do dostowin[i] =3D i - 1 end for wintodos =3D dostowin for i =3D 1 to length(win) do dostowin[dos[i] + 1] =3D win[i] wintodos[win[i] + 1] =3D dos[i] end for end procedure procedure translate() integer d, finput, foutput, a init() c =3D command_line() if length(c) < 5 then printf(1, "%s\n",=20 {"You need 3 parameters: direction, input file name and output file = name"}) abort(3) end if direction =3D upper(c[3]) inputfile =3D c[4] outputfile =3D c[5] if equal(direction, "DOSTOWIN") then d =3D 0 elsif equal(direction, "WINTODOS") then d =3D 1 else printf(1, "%s\n", {"Error - 1st parameter should be DOSTOWIN or WINTODOS"}) abort(1) end if finput =3D open(inputfile, "r") if finput < 0 then printf(1, "%s\n", {"Can't open input file " & inputfile}) abort(2) end if foutput =3D open(outputfile, "w") if foutput < 0 then printf(1, "%s\n", {"Can't open output file" & outputfile}) end if if d then while 1 do a =3D getc(finput) if a < 0 then exit end if puts(foutput, wintodos[a + 1]) end while else while 1 do a =3D getc(finput) if a < 0 then exit end if puts(foutput, dostowin[a + 1]) end while end if end procedure translate() ------=_NextPart_000_00DB_01C1300B.A7964060--