home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
17 Bit Software 1: Collection A
/
17Bit_Collection_A.iso
/
files
/
1065.dms
/
1065.adf
/
Cross
/
txt
/
PreProcessor.mod
< prev
Wrap
Text File
|
1987-06-04
|
6KB
|
258 lines
(***************************************************************************
:Program. PreProcessor
:Author. Jürgen Weinelt
:Address. Zur Kanzel 1, D-8783 Hammelburg, Germany
:Version. V1.1
:Copyright. Freeware; copy it, but don't sell it!
:Language. Modula-II
:Translator. M2Amiga V3.32d
:Imports. FileReq
:Contents. PreProcessor is part of the "Cross" (crossword puzzle
:Contents. Creator) package.
:Contents. PreProcessor takes any amiga ascii text file as input
:Contents. and produces a CPC word data file as output.
:History. V1.0 08-jan-91 first major release on AMOK
:History. V1.1 06-feb-91 minor changes
**************************************************************************)
MODULE PreProcessor;
FROM Arts
IMPORT Assert;
FROM ASCII
IMPORT lf,nul;
FROM Dos
IMPORT Delay;
FROM FileReq
IMPORT FileReq,MakeFRD,FileRequestData,FileString;
FROM FileSystem
IMPORT Lookup,Close,ReadChar,WriteBytes,WriteChar,File,Response;
FROM Heap
IMPORT Allocate;
FROM InOut
IMPORT WriteString,WriteLn;
FROM Str
IMPORT Compare,Length;
FROM SYSTEM
IMPORT ADR;
CONST
wordlen=25;
TYPE
WordString=ARRAY[0..wordlen] OF CHAR;
WordNodePtr=POINTER TO WordNode;
WordNode=
RECORD
word: WordString;
left,right: WordNodePtr;
END;
VAR
inf,outf: File;
inname,outname: FileString;
wrd: WordString;
frd: FileRequestData;
root: WordNodePtr;
act: LONGINT;
PROCEDURE GetChar(VAR file: File; VAR c,c2: CHAR): BOOLEAN;
VAR
legal: BOOLEAN;
BEGIN
ReadChar(file,c);
CASE c OF
|"a".."z":
c:=CHAR(INTEGER(c)-INTEGER("a")+INTEGER("A")); (* capitalize *)
c2:=nul;
legal:=TRUE;
|"A".."Z":
legal:=TRUE;
c2:=nul;
|"ä","Ä":
c:="A"; c2:="E"; legal:=TRUE;
|"ö","Ö":
c:="O"; c2:="E"; legal:=TRUE;
|"ü","Ü":
c:="U"; c2:="E"; legal:=TRUE;
|"ß": c:="S"; c2:="S"; legal:=TRUE;
|ELSE legal:=FALSE;
END;
RETURN legal;
END GetChar;
PROCEDURE GetWord(VAR file: File; VAR wrd: WordString);
VAR
c,c2: CHAR;
inx: INTEGER;
legal: BOOLEAN;
BEGIN
wrd[0]:=nul;
REPEAT
legal:=GetChar(file,c,c2);
UNTIL (legal) OR (file.eof);
IF (NOT file.eof) THEN
wrd[0]:=c;
IF c2<>nul THEN
wrd[1]:=c2;
inx:=2;
ELSE
inx:=1;
END;
REPEAT
legal:=GetChar(file,c,c2);
IF legal THEN
wrd[inx]:=c;
INC(inx);
IF c2<>nul THEN
wrd[inx]:=c2;
INC(inx);
END;
END;
UNTIL (inx>=wordlen) OR (NOT legal) OR (file.eof);
IF inx>wordlen THEN
DEC(inx);
END;
wrd[inx]:=nul;
END;
END GetWord;
PROCEDURE Remember(VAR w: WordString; VAR n: WordNodePtr);
BEGIN
(* builds a binary tree to store the words in *)
IF n=NIL THEN
Allocate(n,SIZE(WordNode));
Assert(n#NIL,ADR("ERROR: OUT OF MEMORY"));
n^.word:=w;
ELSE
IF Length(w)<Length(n^.word) THEN
Remember(w,n^.right);
END;
IF Length(w)>Length(n^.word) THEN
Remember(w,n^.left);
END;
IF Length(w)=Length(n^.word) THEN
CASE Compare(n^.word,w) OF
|1..wordlen+1:
Remember(w,n^.left);
|-wordlen-1..-1:
Remember(w,n^.right);
|ELSE (* NOP *)
END;
END;
END;
END Remember;
PROCEDURE PutWord(n: WordNodePtr; VAR f: File);
VAR
act: LONGINT;
(* traverses the binary tree and outputs the words alphabetically *)
BEGIN
IF (n^.left#NIL) THEN
PutWord(n^.left,f);
END;
WriteBytes(f,ADR(n^.word),Length(n^.word),act);
WriteChar(f,lf);
IF (n^.right#NIL) THEN
PutWord(n^.right,f);
END;
END PutWord;
BEGIN
WriteLn; WriteLn;
WriteString("Crossword Puzzle Creator: Word file PreProcessor");
WriteLn;
WriteString("------------------------------------------------");
WriteLn;
WriteString("Copyright © 1991 by J. Weinelt");
WriteLn; WriteLn;
WriteString("This is FreeWare; non-commercial distribution is encouraged");
WriteLn;
WriteString("No liabilities or warranties assumed; use at your own risk!");
WriteLn; WriteLn;
WriteString("Purpose:");
WriteLn;
WriteString(" Takes any ascii text file as input");
WriteLn;
WriteString(" Writes an CPC word data file as output");
WriteLn; WriteLn;
WriteString("PreProcessor has no command line parameters; file selection");
WriteLn;
WriteString("is completely done with file requesters.");
WriteLn; WriteLn;
Delay(100);
root:=NIL;
MakeFRD("Open input file","","",NIL,frd);
FileReq(frd,inname);
IF Length(inname)>0 THEN
Lookup(inf,inname,5000,FALSE);
Assert(inf.res=done,ADR("ERROR: CAN'T OPEN INPUT FILE"));
WriteString("Reading ");
WriteString(inname);
WriteString("... please wait!");
WriteLn; WriteLn;
REPEAT
GetWord(inf,wrd);
IF NOT (
(Length(wrd)<2) OR
(Length(wrd)>wordlen) OR
(NOT ODD(Length(wrd)))
)
OR (Length(wrd)=2)
THEN
Remember(wrd,root);
END;
UNTIL inf.eof;
frd.h:="Open output file";
FileReq(frd,outname);
IF Length(outname)>0 THEN
Lookup(outf,outname,5000,TRUE);
Assert(outf.res=done,ADR("ERROR: CAN'T OPEN OUTPUT FILE"));
WriteString("Writing ");
WriteString(outname);
WriteString("... please wait!");
WriteLn; WriteLn;
PutWord(root,outf);
WriteBytes(outf,ADR("***END***"),9,act);
WriteChar(outf,lf);
WriteString("Finished. Please edit output file with an ASCII editor and remove");
WriteLn;
WriteString("all unwanted words.");
WriteLn; WriteLn;
WriteString("Goodbye.");
WriteLn; WriteLn;
END;
END;
Close(inf);
Close(outf);
END PreProcessor.