home *** CD-ROM | disk | FTP | other *** search
- MODULE Hexer;
-
- FROM Arguments IMPORT NumArgs, GetArg;
- FROM Arts IMPORT wbStarted, Terminate;
- FROM Break IMPORT InstallException;
- FROM Conversions IMPORT StrToVal, ValToStr;
- FROM InOut IMPORT Write, WriteLn, WriteString;
- FROM SeqIO IMPORT SeqKey, OpenSeqIn, OpenSeqOut, CloseSeq, SeqOk,
- SeqInB, SeqOutB, SeqInLen, SeqOutCount;
- FROM SYSTEM IMPORT ADR;
-
- IMPORT A = ASCII;
-
- CONST Text1 = " : ";
-
- VAR
- In, Out, CharSet : SeqKey;
- InName, OutName,Str,
- CharSetName,WordBuf : ARRAY [0..255] OF CHAR;
- Printable : ARRAY CHAR OF BOOLEAN;
- MinLen, WordLen,
- i, act, Pos, Len : LONGINT;
- c, cMax : CHAR;
- int : INTEGER;
- Err,WordPool,OnlySpaces : BOOLEAN;
-
- BEGIN
- InstallException;
- IF wbStarted THEN Terminate; END;
-
- IF (NumArgs() < 3) THEN
- WriteString("Hexer 1.0 Copyright (c) 1995 by Dirk Held\n\n");
- WriteString("usage : Hexer <InFile> <OutFile> <MinWordLen> [CharSetFile]\n\n");
- Terminate;
- END;
-
- GetArg(1, InName, int);
- IF NOT OpenSeqIn(In, InName, 4000) THEN
- WriteString("Error while opening Infile !\n");
- Terminate;
- END;
-
- GetArg(2, OutName, int);
- IF NOT OpenSeqOut(Out, OutName, 4000) THEN
- WriteString("Error while opening OutFile !\n");
- Terminate;
- END;
-
- GetArg(3, Str, int);
- StrToVal(Str, MinLen, Err, 10, Err);
- IF (MinLen < 2) OR (MinLen > 255) THEN
- WriteString("MinWordLen is not within usable Range !\n");
- Terminate;
- END;
-
- IF (NumArgs() = 4) THEN
- GetArg(4, CharSetName, int);
- IF NOT OpenSeqIn(CharSet, CharSetName, 256) THEN
- WriteString("Error while opening CharSetfile !\n");
- Terminate;
- END;
-
- WordPool := TRUE; cMax := A.nul;
- FOR c := A.nul TO 377C DO Printable[c] := FALSE; END;
- FOR Pos := 1 TO SeqInLen(CharSet) DO
-
- c := SeqInB(CharSet);
- IF (c > cMax) THEN cMax := c; END;
- Printable[c] := TRUE;
-
- END;
-
- IF (cMax >= 200C) THEN WordPool := FALSE; ELSE WordPool := TRUE; END;
-
- ELSE
-
- WordPool := TRUE;
- FOR c := A.nul TO A.us DO Printable[c] := FALSE; END;
- FOR c := A.sp TO 176C DO Printable[c] := TRUE; END;
- FOR c := A.del TO 377C DO Printable[c] := FALSE; END;
-
- END;
-
- WordLen := 0; Len := SeqInLen(In) - 1; OnlySpaces := TRUE;
-
- FOR Pos := 0 TO Len DO
-
- c := SeqInB(In);
-
- IF NOT SeqOk(In) THEN
- WriteString("Error while reading InFile !\n");
- Terminate;
- END;
-
- IF Printable[c] THEN
-
- WordBuf[WordLen] := c; INC(WordLen);
- IF (c # A.sp) THEN OnlySpaces := FALSE; END;
-
- ELSE
-
- IF WordPool AND (c >= 240C) AND Printable[CHR(ORD(c)-128)] THEN
-
- WordBuf[WordLen] := CHR(ORD(c)-128); INC(WordLen);
-
- END;
-
- IF (WordLen >= MinLen) AND NOT OnlySpaces THEN
-
- ValToStr(Pos, FALSE, Str, 16, 8, " ", Err);
-
- SeqOutCount(Out, ADR(Str), 8 );
- SeqOutCount(Out, ADR(Text1), 3 );
- SeqOutCount(Out, ADR(WordBuf), WordLen);
- SeqOutB (Out, A.eol);
-
- IF NOT SeqOk(Out) THEN
- WriteString("Error while writing OutFile !\n");
- Terminate;
- END;
-
- END;
-
- WordLen := 0; OnlySpaces := TRUE;
-
- END;
- END;
-
- WriteString("All done !\n");
-
- CLOSE
-
- CloseSeq(In); CloseSeq(Out); CloseSeq(CharSet);
-
- END Hexer.
-