home *** CD-ROM | disk | FTP | other *** search
- (***************************************************************************
-
- $RCSfile: Text2Ascii.mod $
- Description: A utility to convert Project Oberon text files into plain
- ASCII text. Formatting information is stripped and CRs are
- converted into LFs
- Requires: AmigaDOS V2.04 or greater
-
- Created by: fjc (Frank Copeland)
- $Revision: 1.6 $
- $Author: fjc $
- $Date: 1995/01/26 01:05:15 $
-
- Copyright © 1994, Frank Copeland.
- This file is part of Oberon-A.
- See Oberon-A.doc for conditions of use and distribution.
-
- Log entries are at the end of the file.
-
- ***************************************************************************)
-
- <*STANDARD-*>
-
- MODULE Text2Ascii;
-
- (*
- The example source code and documentation I downloaded from
- neptune.inf.ethz.ch was in Project Oberon's Text format which is
- unreadable by my Amiga text viewers and editors. The main problem is
- that lines are terminated by CR (0DX) instead of LF (0AX). The
- formatting information is also a pain.
-
- Text2Ascii reads one or more files in Text format and outputs the
- contents as pure ASCII text, converting CRs to LFs in the process.
- Formatting information is ignored. Lines longer than 75 characters
- are broken at the first space after the 75th character. Tabs are
- replaced with two spaces.
-
- The syntax of a Text file, as far as we are concerned, is:
-
- TextBlockId:2 off:4 {byte} len:4 {char}
- TextBlockId = 01F0H or F001H
-
- off is the offset of the start of the text proper from the location of
- TextBlockId. len is the length in characters of the text and is at
- Position(TextBlockId) + off - 4.
-
- off and len are stored in little-endian form: that is, the low-order
- word and low-order byte first. This must be converted to the internal
- representation used by the MC68k processors.
- *)
-
- IMPORT SYS := SYSTEM, Args, Dos, Files, IO := StdIO, Exec;
-
- VAR
- pattern, dest : ARRAY 256 OF CHAR;
-
- (*------------------------------------*)
- PROCEDURE GetArgs ();
-
- BEGIN (* GetArgs *)
- IF Args.argc = 3 THEN
- COPY (Args.argv [1]^, pattern);
- COPY (Args.argv [2]^, dest);
- ELSE
- IO.WriteStr ("Usage : Text2Ascii <pattern> <dest>\n");
- HALT (Dos.warn)
- END; (* ELSE *)
- END GetArgs;
-
- (*------------------------------------*)
- PROCEDURE ConvertFile (fileName : ARRAY OF CHAR);
-
- CONST
- TextBlockId1 = 01F0H;
- TextBlockId2 = -0FFFH;
- CR = 0DX; LF = 0AX; TAB = 09X;
-
- VAR
- newFileName : ARRAY 256 OF CHAR;
- oldFile, newFile : Files.File;
- r, w : Files.Rider;
- id, col : INTEGER;
- off, len, i : LONGINT;
- ch : CHAR; ignore : BOOLEAN;
- filePart : Exec.LSTRPTR;
-
- (*------------------------------------*)
- PROCEDURE ReadLongint (VAR l : LONGINT);
-
- VAR byte : ARRAY 4 OF SYS.BYTE; msb : INTEGER;
-
- BEGIN (* ReadLongint *)
- Files.ReadBytes (r, byte, 4);
- msb := ORD (byte [3]); IF msb > 127 THEN DEC (msb, 256) END;
- l :=
- (msb * 1000000H) + (ORD (byte [2]) * 10000H)
- + (LONG (ORD (byte [1])) * 100H) + LONG (ORD (byte [0]))
- END ReadLongint;
-
- <*$CopyArrays-*>
- BEGIN (* ConvertFile *)
- oldFile := Files.Old (fileName);
- IF oldFile # NIL THEN
- Files.Set (r, oldFile, 0);
- Files.ReadBytes (r, id, 2);
- IF (id = TextBlockId1) OR (id = TextBlockId2) THEN
- COPY (dest, newFileName);
- filePart := Dos.FilePart (fileName);
- ignore := Dos.AddPart (newFileName, filePart^, 256);
- newFile := Files.New (newFileName);
- IF newFile # NIL THEN
- IO.WriteF2
- (" !! %s -> %s\n", SYS.ADR (fileName), SYS.ADR (newFileName));
- Files.Set (w, newFile, 0);
- ReadLongint (off);
- Files.Set (r, oldFile, off - 4);
- ReadLongint (len); i := Files.Length (oldFile) - off;
- IF len > i THEN len := i END;
- i := 0; col := 1;
- WHILE i < len DO
- Files.Read (r, ch);
- IF ch = CR THEN
- Files.Write (w, LF); col := 1
- ELSIF ch = TAB THEN
- Files.Write (w, " "); Files.Write (w, " ");
- INC (col, 2)
- ELSIF (ch = " ") & (col > 75) THEN
- Files.Write (w, LF); col := 1
- ELSIF (ch >= 80X) & (ch <= 85X) THEN
- CASE ch OF
- 80X : Files.Write (w, "Ä") |
- 81X : Files.Write (w, "Ö") |
- 82X : Files.Write (w, "Ü") |
- 83X : Files.Write (w, "ä") |
- 84X : Files.Write (w, "ö") |
- 85X : Files.Write (w, "ü") |
- END; (* CASE ch *)
- INC (col)
- ELSIF ch >= " " THEN
- Files.Write (w, ch); INC (col)
- END;
- INC (i)
- END; (* WHILE *)
- Files.Register (newFile)
- ELSE
- IO.WriteF1 (" !! Could not open %s\n", SYS.ADR (newFileName))
- END; (* ELSE *)
- ELSE
- IO.WriteF1 (" !! %s is not a Text file\n", SYS.ADR (fileName))
- END; (* ELSE *)
- Files.Close (oldFile)
- ELSE
- IO.WriteF1 (" !! Could not open %s\n", SYS.ADR (fileName))
- END; (* ELSE *)
- END ConvertFile;
-
- (*------------------------------------*)
- PROCEDURE ConvertFiles ();
-
- VAR
- myAnchor : Dos.AnchorPath;
- result : LONGINT;
-
- BEGIN (* ConvertFiles *)
- myAnchor.strlen := 256;
- result := Dos.MatchFirst (pattern, myAnchor);
- WHILE result = 0 DO
- ConvertFile (myAnchor.buf);
- result := Dos.MatchNext (myAnchor)
- END; (* WHILE *)
- END ConvertFiles;
-
- BEGIN (* Text2Ascii *)
- IO.WriteStr ("Text2Ascii\nWritten by Frank Copeland\n");
- IF Dos.base.lib.version < 37 THEN
- IO.WriteStr ("Requires AmigaDOS 2.04+\nSorry :-(\n");
- ELSE
- GetArgs ();
- ConvertFiles ()
- END; (* ELSE *)
- END Text2Ascii.
-
- (***************************************************************************
-
- $Log: Text2Ascii.mod $
- Revision 1.6 1995/01/26 01:05:15 fjc
- - Release 1.5
-
- Revision 1.5 1994/09/25 18:25:17 fjc
- - Uses new syntax for external code declarations
-
- Revision 1.4 1994/06/17 17:35:24 fjc
- - Updated for release
-
- Revision 1.3 1994/06/09 14:30:29 fjc
- - Incorporates changes to Amiga interface
-
- Revision 1.2 1994/06/05 22:23:09 fjc
- - Changed to use new Amiga interface
-
- Revision 1.1 1994/05/12 20:20:07 fjc
- - Prepared for release
-
- Revision 1.0 1994/01/16 14:02:35 fjc
- Start of version control
-
-
- 0.2 (30-Nov-93) Added conversions for German chars
- 0.1 (02-Nov-93) Initial version
-
- ***************************************************************************)
-
-
-