[Oberon] Need V4 Code for trivial task.
Douglas G Danforth
danforth at greenwoodfarm.com
Sun Dec 4 11:12:13 CET 2016
Chris,
I am just as lazy as you are, but I stuck with it and have a command
line version that works.
Command line in that within the V4 system one can middle mouse on the line
Eol.Fix inFileName outFileName
and the conversion will happen.
Here is the code
---
MODULE Eol;
IMPORT
Files,
Oberon,
Out,
Texts;
VAR
rd: Files.Rider;
wr: Files.Rider;
inFile: Files.File;
outFile: Files.File;
PROCEDURE Open* (out, in: ARRAY OF CHAR): BOOLEAN;
VAR flag: BOOLEAN;
BEGIN
inFile := Files.Old(in);
flag := (inFile # NIL);
IF flag THEN
Files.Set(rd, inFile, 0);
outFile := Files.New(out);
flag := (outFile # NIL);
IF flag THEN
Files.Set(wr, outFile, 0)
ELSE
Out.String("Could not open output <"); Out.String(out);
Out.String(">"); Out.Ln
END
ELSE
Out.String("Could not open input <"); Out.String(in);
Out.String(">"); Out.Ln
END;
RETURN flag
END Open;
PROCEDURE Strip* ;
VAR c: CHAR;
BEGIN
Files.Read(rd, c);
WHILE ~rd.eof DO
IF (c = 0DX) OR (c = 0AX) THEN c := " " END;
Files.Write(wr, c);
Files.Read(rd, c);
END;
Files.Register(outFile);
Files.Close(inFile)
END Strip;
PROCEDURE Fix*;
VAR s: Texts.Scanner; inName, outName: ARRAY 256 OF CHAR;
BEGIN
Out.Open;
Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos);
Texts.Scan(s);
IF s.class # Texts.Name THEN
Out.String("input name not found"); Out.Ln ;
Out.Int(s.class,3); Out.String(" = s.class"); Out.Ln
ELSE
COPY(s.s, inName) ;
Texts.Scan(s);
IF s.class # Texts.Name THEN
Out .String("output name not found"); Out.Ln ;
Out.Int(s.class,3); Out.String(" = s.class"); Out.Ln
ELSE
COPY(s.s, outName);
IF Open(outName, inName) THEN
Strip;
Out.String("File converted"); Out.Ln
END
END
END
END Fix;
END Eol.
---
On 12/3/2016 10:32 PM, eas lab wrote:
> Douglas G Danforth wrote:-
>> This V4 code seems to work!
>> Needing to cast a BYTE using ORD threw me for a while.
>> You don't need to do that with Component Pascal.
> Yes thank, I'm using your code. And I'd like to refine it to syntax:-
> ELO.Fix <InFile> <OutFile> ~
> Because it's a production tool for me; so I want minimal handling;
> but I've also lost the *.Text with the nice tutorial examples of S3
> which I believe would also work with V4.
> Ie. to scan ahead to fetch "<InFile> <OutFile> ~" .
>
> Yes, I'm lazy and resisiting relearning old stuff.
> It's more fruitfull to discuss extensions to Oberon.
> That's also why I included the terse examples of *nix script.
>
> .... With hold till later
> discussion re. massive power/economy-of-effort from functional/piping
> programming style, as demonstrated in this tread's linux snippet.
>
> == Chris Glur.
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
--
Danforth of the Greenwood
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20161204/8ae5d01b/attachment.html>
More information about the Oberon
mailing list