[Oberon] FPGA - Oberon-7 - Plain File

Andreas Pirklbauer andreas_pirklbauer at yahoo.com
Thu Oct 4 15:43:22 CEST 2018


    > > Just thinking, how to remove rich format header with font names from a text file.
    > In Project Oberon this is already implemented for you: see Tools.Convert
    > Regards, Chris Burrows

… which is easy to modify such that it takes the name of an Oberon text *file* as input:


MODULE TextTools;
  IMPORT Files, Texts, Oberon;

  VAR W: Texts.Writer;

  PROCEDURE StoreAscii*; (*convert input file in Oberon text format to outputfile in txt-format*)
    VAR ch: CHAR;
      T: Texts.Text; R: Texts.Reader;  (*input*)
      F: Files.File; Q: Files.Rider;   (*output*)
      S: Texts.Scanner;
      name: ARRAY 32 OF CHAR;
  BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
    IF (S.class = Texts.Name) OR (S.class = Texts.String) THEN name := S.s; Texts.Scan(S);
      IF (S.class = Texts.Name) OR (S.class = Texts.String) THEN Texts.WriteString(W, "  StoreAscii ");
        Texts.WriteString(W, name); Texts.Write(W, " "); Texts.WriteString(W, S.s); F := Files.Old(name);
        IF F # NIL THEN F := Files.New(S.s);
          IF F # NIL THEN Files.Set(Q, F, 0);
            NEW(T); Texts.Open(T, name); Texts.OpenReader(R, T, 0); Texts.Read(R, ch);
            WHILE ~R.eot DO     (*same as Tools.Convert -> add your favourite encoding e.g. for line ending, tabs here*)
              IF ch = 0DX  (*CR*) THEN Files.Write(Q, 0DX);  (*CR*) Files.Write(Q, 0AX)  (*LF*)
              ELSIF ch = 9X THEN  (*TAB*) Files.Write(Q, " "); Files.Write(Q, " ")
              ELSE Files.Write(Q, ch)
              END ;
              Texts.Read(R, ch)
            END ;
            Files.Register(F); Texts.WriteString(W, " done")
          ELSE Texts.WriteString(W, "  cannot create output file")
          END
        ELSE Texts.WriteString(W, "  input file not found")
        END
      ELSE Texts.WriteString(W, "Usage: TextTools.StoreAscii inputfile outputfile")
      END
    END ;
    Texts.WriteLn(W); Texts.Append(Oberon.Log, W.buf)
  END StoreAscii;

BEGIN Texts.OpenWriter(W)
END TextTools.

ORP.Compile TextTools.Mod/s ~
TextTools.StoreAscii Oberon.Mod Oberon.Mod.txt ~




More information about the Oberon mailing list