Ordered words: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: rewrote to use unix_dict(), syntax coloured)
(→‎{{header|XPL0}}: simpler, better version)
Line 4,884: Line 4,884:
=={{header|XPL0}}==
=={{header|XPL0}}==
<lang XPL0>string 0; \use zero-terminated strings
<lang XPL0>string 0; \use zero-terminated strings
int MaxLen, Pass, I, Ch, Ch0;
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;
def LF=$0A, CR=$0D, EOF=$1A;
[FSet(FOpen("unixdict.txt", 0), ^I);

[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;
MaxLen:= 0;
for Pass:= 1 to 2 do
for Pass:= 1 to 2 do
[DI:= 0;
[OpenI(3);
repeat Word:= Dict(DI);
repeat I:= 0; Ch0:= 0;
I:= 0; Ch0:= 0;
loop [repeat Ch:= ChIn(3) until Ch # CR; \remove possible CR
loop [Ch:= Word(I);
if Ch=LF or Ch=EOF then
if Ch = 0 then
[if I > MaxLen then MaxLen:= I;
[if I > MaxLen then MaxLen:= I;
if I=MaxLen & Pass=2 then
if I=MaxLen & Pass=2 then
[Word(I):= 0; Text(0, Word); CrLf(0)];
[Text(0, Word); CrLf(0)];
quit;
quit;
];
];
Word(I):= Ch;
if Ch < Ch0 then quit;
if Ch < Ch0 then
[repeat Ch:= ChIn(3) until Ch=LF or Ch=EOF;
quit;
];
Ch0:= Ch;
Ch0:= Ch;
I:= I+1;
I:= I+1;
];
];
DI:= DI+1;
until Ch = EOF;
until DI >= DictSize;
];
];
]</lang>
]</lang>