Martin Brown
2013-02-18 09:30:04 UTC
I have a fair amount of legacy code in Topspeed/JPI dialect of Modula 2
that is sometimes useful. I now use XDS M2 and its Topspeed libraries.
The good news is that with the right minor adjustments the code ports,
compiles and works OK most of the time (and runs natively on Win 7
64bit). The bad news is that it is not all entirely well behaved.
In particular directory functions and iterating across files in a
directory fails miserably if there is no match on a wildcard search.
Here is a canonical example stripped to minimal code. XDS + Topspeed.
MODULE Dir;
<* +M2EXTENSIONS *>
<* +M2ADDTYPES *>
FROM FIO IMPORT DirEntry, FileAttr, ReadFirstEntry, ReadNextEntry;
FROM IO IMPORT WrLn, WrLngCard, WrStr;
FROM M2EXCEPTION IMPORT IsM2Exception, M2Exception;
VAR filename : ARRAY [0..255] OF CHAR;
fatt : FileAttr;
Entry: DirEntry;
OK : BOOLEAN;
BEGIN
filename := "*.*"; (* this works NB must be a variable *)
fatt := FileAttr({});
OK := ReadFirstEntry( filename, fatt, Entry); (* works *)
WHILE OK DO
WrStr(Entry.name) ; WrLn;
OK := ReadNextEntry(Entry);
END;
WrLn; WrStr("And now for a fatal crash :("); WrLn;
filename := "ZQJ*.LQW";
OK := ReadFirstEntry( filename, fatt, Entry); (* fails GPF *)
EXCEPT
IF IsM2Exception() THEN
WrLngCard(ORD(M2Exception()),6);
ELSE
WrStr("Boggle");
END;
WHILE OK DO
WrStr(Entry.name); WrLn;
OK := ReadNextEntry(Entry)
END;
END Dir.
The first search on "*.*" lists all files in the home directory and
works without any problems at all. The second crashes spectacularly
either with "Unhandled exception" or "GPF" depending on choice of code.
It is possible that doing IO from the handler is unwise. Comment out
"EXCEPT clause or "WrStr("Boggle") to get Unhandled exception.
The inability to list a directory where the template wildcard pattern
results in no matches is rather annoying. I can't spot anything useful
for doing this in the ISO libraries or other provided libraries.
What am I missing?
An alternative fix for me would be if I could figure out how to use the
allegedly inline assembler that XDS is supposed to contain. I have full
library sources of Topspeed so I could roll my own crucial FIO routines
if I could make the requisite DOSCALL. At the moment I am seriously
tempted to run the lot through MOD2C and give up on M2 entirely!
Thanks for any enlightenment.
that is sometimes useful. I now use XDS M2 and its Topspeed libraries.
The good news is that with the right minor adjustments the code ports,
compiles and works OK most of the time (and runs natively on Win 7
64bit). The bad news is that it is not all entirely well behaved.
In particular directory functions and iterating across files in a
directory fails miserably if there is no match on a wildcard search.
Here is a canonical example stripped to minimal code. XDS + Topspeed.
MODULE Dir;
<* +M2EXTENSIONS *>
<* +M2ADDTYPES *>
FROM FIO IMPORT DirEntry, FileAttr, ReadFirstEntry, ReadNextEntry;
FROM IO IMPORT WrLn, WrLngCard, WrStr;
FROM M2EXCEPTION IMPORT IsM2Exception, M2Exception;
VAR filename : ARRAY [0..255] OF CHAR;
fatt : FileAttr;
Entry: DirEntry;
OK : BOOLEAN;
BEGIN
filename := "*.*"; (* this works NB must be a variable *)
fatt := FileAttr({});
OK := ReadFirstEntry( filename, fatt, Entry); (* works *)
WHILE OK DO
WrStr(Entry.name) ; WrLn;
OK := ReadNextEntry(Entry);
END;
WrLn; WrStr("And now for a fatal crash :("); WrLn;
filename := "ZQJ*.LQW";
OK := ReadFirstEntry( filename, fatt, Entry); (* fails GPF *)
EXCEPT
IF IsM2Exception() THEN
WrLngCard(ORD(M2Exception()),6);
ELSE
WrStr("Boggle");
END;
WHILE OK DO
WrStr(Entry.name); WrLn;
OK := ReadNextEntry(Entry)
END;
END Dir.
The first search on "*.*" lists all files in the home directory and
works without any problems at all. The second crashes spectacularly
either with "Unhandled exception" or "GPF" depending on choice of code.
It is possible that doing IO from the handler is unwise. Comment out
"EXCEPT clause or "WrStr("Boggle") to get Unhandled exception.
The inability to list a directory where the template wildcard pattern
results in no matches is rather annoying. I can't spot anything useful
for doing this in the ISO libraries or other provided libraries.
What am I missing?
An alternative fix for me would be if I could figure out how to use the
allegedly inline assembler that XDS is supposed to contain. I have full
library sources of Topspeed so I could roll my own crucial FIO routines
if I could make the requisite DOSCALL. At the moment I am seriously
tempted to run the lot through MOD2C and give up on M2 entirely!
Thanks for any enlightenment.
--
Regards,
Martin Brown
Regards,
Martin Brown