home *** CD-ROM | disk | FTP | other *** search
- { (C) Copyright 1986-1992 MetaWare Incorporated; Santa Cruz, CA 95060. }
-
- #if 0
- Professional Pascal/High C Interface to Xenix-DOS I/O Services
-
- For functions that take strings, two interfaces are supplied:
- one for Pascal and one for C. The difference is that Pascal
- uses strings preceded by a length, and C uses 0-terminated
- strings. Therefore, to allow Pascal and C programs to be linked
- together, two copies of these routines must be provided.
- Those functions having copies for C are marked {C} in the left
- margin. Note: Linking in either the Pascal or C library alone
- does NOT two versions of a routine. Only if both libraries used are
- two versions potentially linked in.
-
- This file makes use of a define "CDOS" that is set True under
- Concurrent DOS 286 systems. A few of the system-level routines differ
- for this OS.
- #endif
-
- pragma c_include('implement.pf');
- pragma c_include('fileh.pf');
- pragma c_include('seek.pf');
-
- package System;
- pragma Routine_aliasing_convention(Implement.RTE_aliasing);
- -- Some routines are additionally aliased to prevent conflicts
- -- with Pascal intrinsic routines Write, Read, Trunc, and Close.
- with Implement,Loopholes:[Address],Fileh_type Transmitted;
- with Seek_method_type Transmitted;
- type
- Sharing_mode_type = -- For networking access; MSDOS 3.x only.
- (Compatibility,Deny_read_write,Deny_write,Deny_read,Deny_none);
- Open_method = (For_reading, For_writing, For_updating);
- File_attribute =
- (Attr_read_only, -- File may not be modified.
- Attr_hidden, -- File is hidden.
- Attr_system, -- File is a "system" file.
- Attr_volume_id, -- File is the volume id.
- Attr_directory, -- File is a directory.
- Attr_archive -- File has not been archived.
- #if defined(CDOS)
- ,Attr_security -- File has security enabled.
- #elif defined(ADOS)
- ,x6,x7,x8 -- Ensure the mode is a word.
- #endif
- );
- File_mode = set of file_attribute;
- File_class =
- (Disk_file, -- File is on disk.
- Console_input, -- File is the keyboard.
- Console_output, -- File is the monitor.
- Printer_device, -- File is the printer.
- Other_device); -- File is something else.
- {
- NOTE: Following every call, the imported variable Errno contains the
- status of the call. If zero, then the call was successful, otherwise
- it will contain one of the error codes specified after each
- routine declaration below.
- }
-
- -- Return the mode of a file.
- function Filemode(const Name: String): File_mode; External;
- -- Error_path_not_found.
- -- Error_access_denied.
- -- Error_invalid_function -- this error should never occur.
- {C}function C_filemode(Name: Charp): File_mode; External;
-
- -- Return the class of a file..
- function Fileclass(F: File_handle): File_class; External;
-
- -- Close file whose handle is "F".
- procedure Close(F: File_handle); external;
- -- Error_invalid_handle -- file was not open, or "F" contains garbage.
- pragma Alias(Close,Implement.RTE || 'zclose');
- -- The Alias avoids external conflict with Pascal Close intrinsic..
-
- -- Create file "name" and open it for writing.
- function Create(const Name: String; Mode: File_mode): File_handle; external;
- -- Error_access_denied.
- -- Error_path_not_found.
- -- Error_too_many_files - file created but not opened.
- {C}function C_Create(Name: Charp; Mode: File_mode): File_handle; external;
- #if defined(CDOS)
- pragma Data(Import);
- var _open_and_mask, _open_or_mask: Cardinal;
- -- And/or the CDOS open/create flags with these values:
- -- Flags = (Flags & _open_and_mask) | _open_or_mask;
- -- This applies for both c_create and c_open calls.
- -- These are initialized to 0xffff and 0x0 initially.
- pragma Data;
- #endif
-
- function Create_text(const Name: String; Mode: File_mode): File_handle; external;
- -- Identical to "Create" except it creates a text file. On systems that have
- -- a single file format, this function is equivalent to "Creat".
- {C}function C_Create_text(Name: Charp; Mode: File_mode): File_handle; external;
- #ifndef CTOS
- pragma Alias(Create_text,Implement.RTE || 'create');
- pragma Alias(C_Create_text,Implement.RTE || 'c_create');
- #endif
-
- -- Reposition the file pointer assoicated with "F" to location "Loc"
- -- according to the method specified in "Method".
- -- Lseek_ is identical to Lseek except that it returns the new position.
- procedure Lseek(F: File_handle; Loc: Longint; Method: Seek_method); external;
- function Lseek_(F: File_handle; Loc: Longint; Method: Seek_method): Longint;
- external;
- -- Error_invalid_handle.
- -- Error_invalid_function - the parameter "method" contains garbage.
- pragma Alias(Lseek_,RTE ||'lseek');
-
- -- Make a new directory named "Name".
- procedure Mkdir(const Name: String); external;
- -- Error_path_not_found.
- -- Error_access_denied - file already exists or directory overflow.
- {C}procedure C_Mkdir(Name: Charp); external;
-
- -- Open file "Name" for reading, writing, or updating.
- -- Variable Sharing_mode specifies the sharing mode for DOS 3.x and
- -- is used for every open. By default Sharing_mode is set to Compatibility.
- var Sharing_mode: Sharing_mode_type;
- function Open(const Name: String; Method: Open_method): File_handle; external;
- -- Error_invalid_access -- "method" parameter contains garbage
- -- Error_file_not_found
- -- Error_access_denied -- file is a directory, volume id or read-only
- -- Error_too_many_files -- limit in CONFIG.SYS has been reached
- {C}function C_Open(Name: Charp; Method: Open_method): File_handle; external;
-
- function Open_text(const Name: String; Method: Open_method): File_handle; external;
- -- Opens a text file. On systems that have a single file format, this routine
- -- is identical to "Open"
- {C}function C_Open_text(Name: Charp; Method: Open_method): File_handle; external;
- #ifndef CTOS
- pragma Alias(Open_text,Implement.RTE || 'open');
- pragma Alias(C_Open_text,Implement.RTE || 'c_open');
- #endif
-
- -- Read "Cnt" bytes from file "F" into buffer whose address is "Bufp".
- -- Returns the number of bytes actually read; 0 if at EOF.
- function Read(F: File_handle; Bufp: Address; Cnt: Byte_count):Byte_count; external;
- -- Error_invalid_handle -- file not open.
- -- Error_access_denied -- "F" was opened but not for reading.
- pragma Alias(Read,Implement.RTE || 'zread');
-
- -- Remove directory.
- procedure Rmdir(const Name: String); external;
- -- Error_path_not_found.
- -- Error_access_denied.
- -- Error_current_directory - "Name" is the name of the current directory.
- {C}procedure C_Rmdir(Name:Charp); external;
-
- -- Erase file from directory.
- procedure Unlink(const Name: String); external;
- -- Error_file_not_found.
- -- Error_access_denied.
- {C}procedure C_Unlink(Name: Charp); external;
-
- -- Rename a file..
- procedure Rename(const Old:String; const New:String); external;
- -- Error_file_not_found.
- -- Error_not_same_device.
- -- Error_access_denied.
- {C}procedure C_Rename(Old:Charp; New:Charp); external;
-
- -- Write "Cnt" bytes from buffer whose address is "Bufp" into file "F".
- -- Write_ is identical to Write except number of bytes written is returned.
- -- Note: If disk overflow occurs, Errno will have the value Error_disk_overflow
- -- and Write_ will return with the number of bytes actually written
- -- NOTE: For CTOS, you must close the file to get all the data written.
- -- The CTOS OS will not do so.
-
- procedure Write(F: File_handle; Bufp: Address; Cnt: Byte_count); external;
- function Write_(F: File_handle; Bufp: Address; Cnt: Byte_count):Byte_count; external;
- -- Error_invalid_handle - file not open.
- -- Error_access_denied - file not open for writing.
- pragma Alias(Write ,Implement.RTE || 'zwrite');
- pragma Alias(Write_,Implement.RTE || 'zwrite');
-
- -- Truncates file at current position.
- procedure Trunc(F: File_handle); external;
- -- Error_invalid_handle.
- -- Error_access_denied.
- pragma Alias(Trunc,Implement.RTE || 'ztrunc');
-
- #if defined(CDOS)
- type Time_and_date = record
- fb_Year: Integer; fb_Month, fb_Day, fb_Hour, fb_Min, fb_Sec: 0..255;
- end;
- #elif defined(ADOS)
- type File_time_type = record
- Creation_date, Creation_time, Access_date, Access_time,
- Write_date, Write_time: Cardinal;
- end;
- #endif
-
- #if defined(ADOS)
- type Find_buffer = record
- TD: File_time_type;
- fb_size: Longint; -- Size of file.
- fb_attr: File_mode;
- Namelen: 0..255; -- Length of upcoming name; redundant with nul-terminator.
- fb_pname: packed array[1..13] of char; -- Includes trailing nul.
- #elif defined(CDOS)
- type Find_buffer = record
- fb_key: Longint; -- For subsequent finds.
- fb_pname:packed array[1..18] of char; -- 18 bytes of name; 0-terminated.
- fb_attr: File_mode; -- Attribute bits.
- -- There is one byte of padding here.
- fb_recsize: Integer; -- File record size.
- fb_user, fb_group: 0..255; -- Uid, Gid.
- fb_protection:Integer; -- ??
- Reserved1: packed array[1..6] of char;
- fb_size: Longint; -- File size.
- fb_TD: Time_and_date;
- Reserved2: char;
- #else -- MS-DOS.
- type Find_buffer = packed record
- Reserved: packed array[1..21] of char;
- fb_attr: File_mode;
- fb_time: Cardinal;
- fb_date: Cardinal;
- fb_size: Longint;
- fb_pname: packed array[1..13] of char;
- #endif
- end;
-
- procedure Find_first(const Path: String; var S: Find_buffer;
- #if not defined(CDOS)
- Attr: File_mode;
- #if defined(ADOS)
- var Dirhandle:Cardinal; -- Must be presented next time.
- #endif
- #endif
- );
- external;
- -- "Path" is a path name with wild card characters. The first file
- -- encountered that matches the path name and has a subset of the
- -- attributes specified in "Attr" is returned in S. (Attr is not
- -- applicable for Concurrent DOS 286.)
- -- This value of S must be passed to Find_next to get subsequent
- -- matches.
- -- Error_file_not_found -- invalid path name }
- -- Error_no_more_files -- no files matching this specification}
- {C}procedure C_Find_first(Path: Charp; var S: Find_buffer;
- #if not defined(CDOS)
- Attr: File_mode;
- #if defined(ADOS)
- var Dirhandle:Cardinal; -- Must be presented next time.
- #endif
- #endif
- ); external;
-
- #if defined(ADOS)
- procedure Find_next(Dirhandle:Cardinal; var S:Find_buffer); external;
- procedure Find_close(Dirhandle:Cardinal); external; -- terminate find.
- #elif not defined(CDOS)
- procedure Find_next(var S: Find_buffer); external;
- -- Called after Find_first to retrieve subsequent matches.
- -- Error_no_more_files -- no more files that match.
- #else
- procedure Find_next(
- const Path:String; -- CDOS requires the path a second time.
- var S: Find_buffer); external;
- -- Called after Find_first to retrieve subsequent matches.
- -- Error_no_more_files -- no more files that match.
- {C}procedure C_Find_next(
- Path:Charp; -- CDOS requires the path a second time.
- var S: Find_buffer); external;
- -- Called after Find_first to retrieve subsequent matches.
- -- Error_no_more_files -- no more files that match.
- #endif
-
- #if not defined(CDOS)
- procedure Switch_char(var C:char; Set_it:Boolean); external;
- -- Set or retrieve the Switch character.
- -- If Set_it, then set it; otherwise return it in C.
- #endif
-
- #if not defined(CDOS)
- procedure File_times(F: File_handle; var Date,Time: Cardinal); external;
- #else
- procedure File_times(F: File_handle; var TD:Time_and_date); external;
- #endif
- -- Returns the date and time of an open file.
- -- Error_invalid_handle --- file not open
-
- #if not defined(CDOS)
- procedure Set_file_times(F: File_handle; Date,Time: Cardinal); external;
- #else
- procedure Set_file_times(F: File_handle; var TD:Time_and_date); external;
- #endif
- -- Sets the date/time of a file.
- -- Error_invalid_handle -- File not open
-
- procedure Get_date(var Day,Month,Year:cardinal);external;
- procedure Get_time(var Hrs, Mins, Secs:cardinal);external;
-
- const Clock_precision = 100; -- Clock returns time in hundredths of a second.
- function Clock:Longint; { Time in 100ths of a second. } external;
-
- type Dos_return_code = 0..255;
- procedure DOS_exit(RC:Dos_return_code); external;
-
- iterator Each_file(const Path: String):(const FN: String); external;
- {
- Given a path name "Path" with wild cards, this iterator will yield
- every file name that matches it.
- }
- { There is no corresponding version for C. }
-
- -- Change the current working directory to "name".
- procedure Chdir(const Name: String); external;
- -- Error_path_not_found.
- procedure C_Chdir(Name: Charp); external;
-
- -- Change mode of file "name" to "Mode".
- procedure Chmod(const Name: String; Mode: File_mode); external;
- -- Error_path_not_found.
- -- Error_access_denied.
- -- Error_invalid_function -- this error should never occur.
- procedure C_Chmod(Name: Charp; Mode:File_mode); external;
-
- -- Duplicate file handle "F".
- function Dup(F: File_handle): File_handle; external;
- -- Error_invalid_handle.
- -- Error_too_many_open_files -- file limit of CONFIG.SYS exceeded.
-
- -- Duplicate file handle "F" as file handle "Newfh".
- procedure Dup2(F,Newfh: File_handle); external;
- -- Error_invalid_handle.
-
- end;
-