Laurentiu COCEA wrote:
- How do I suspend I/O error messages in order to detect the
presence/absence of a file? In Turbo Pascal, one does this as follows:
{$I-} reset(file); {$I+} if IOResult <> 0 then...
In SunWorkshop Pascal it's a little bit more complicated even if its different. Is there something similar to these in GNU Pascal?
Sorry, there's no {$I+-} directive in GPC yet, but some work has already been done towards implementing it.
As for checking if a file exists, there are other ways, e.g. searching the directory, or (at least under Un*x systems, I don't know if also under Dos) stat(2)ing the file. The following works on my Linux system, so it should be alright for you:
program FileExists;
type TStatBuf=Array[1..$4000] of Byte; {It's currently not easy to get the correct C structure into GPC, but since I don't use the contents of the structure here, it doesn't matter. The above should be big enough, anyway... ;-}
function stat(Name:CString;var Buf:TStatBuf):Integer; C;
function Exists(s:String):Boolean; var Buf:TStatBuf; begin Exists:=stat(s+#0,Buf)=0 end;
var a:String(200);
begin Write('Enter a file name: '); readln(a); if Exists(a) then Writeln(a,' exists.') else Writeln(a,' doesn''t exist.') end.
- Where do I get a list of compile-time and run-time errors?
I fear such a list doesn't exist -- there's much work to do about the documentation... :-(
If you get the source distribution of GPC, you can find a *non-complete* list of run-time errors in rts/rts-error.c. I don't know if the compile-time errors are listed somewhere