Ordered words: Difference between revisions

→‎{{header|XPL0}}: simpler, better version
m (→‎{{header|Phix}}: rewrote to use unix_dict(), syntax coloured)
(→‎{{header|XPL0}}: simpler, better version)
Line 4,884:
=={{header|XPL0}}==
<lang XPL0>string 0; \use zero-terminated strings
int DIMaxLen, Pass, I, Ch, Ch0, MaxLen, Pass;
int Dict(26000); \pointers to words (enough for unixdict.txt)
char Word(25);
int DictSize; \actual number of pointers in Dict
int DI, I, Ch, Ch0, MaxLen, Pass;
char Word;
def LF=$0A, CR=$0D, EOF=$1A;
[FSet(FOpen("unixdict.txt", 0), ^I); \load dictionary into Dict
 
[FSet(FOpen("unixdict.txt", 0), ^I); \load dictionary into Dict
OpenI(3); \assume alphabetical order and all lowercase
DI:= 0; \ignore non-alpha characters: 0..9, ' and &
repeat Dict(DI):= Reserve(0); \get pointer to memory used to store Word
Word:= Dict(DI);
I:= 0;
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR
if Ch=LF or Ch=EOF then quit;
Word(I):= Ch;
I:= I+1;
];
Word(I):= 0; \terminate Word string
I:= Reserve(I+1); \reserve memory used for Word
DI:= DI+1; \next dictionary entry
until Ch = EOF;
DictSize:= DI;
 
MaxLen:= 0;
for Pass:= 1 to 2 do
[DI:= 0OpenI(3);
repeat WordI:= Dict(DI)0; Ch0:= 0;
I:=loop 0; Ch0 [repeat Ch:= 0ChIn(3) until Ch # CR; \remove possible CR
loop [ if Ch=LF or Ch:=EOF Word(I);then
[if ChI => 0MaxLen then MaxLen:= I;
[if I > MaxLen thenif I=MaxLen: & Pass=2 I;then
if [Word(I):=MaxLen &0; Text(0, Word); Pass=2 thenCrLf(0)];
[Text(0, Word); CrLf(0)]quit;
quit ];
Word(I):= ]Ch;
if Ch < Ch0 then quit;
loop [repeat Ch:= ChIn(3) until Ch=LF #or CRCh=EOF; \remove possible CR
DI:= 0; \ignore non-alpha characters: 0..9, ' and &quit;
if Ch=LF or Ch=EOF then quit ];
Ch0:= Ch;
I:= I+1;
];
until Ch DI:= DI+1EOF;
until DI >= DictSize;
];
]</lang>
772

edits