home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c220 / 4.ddi / LIB / SRC / SYSTEM.PF < prev    next >
Encoding:
Text File  |  1990-12-16  |  13.6 KB  |  332 lines

  1. #if 0
  2.     Professional Pascal/High C Interface to Xenix-DOS I/O Services
  3.  
  4.     For functions that take strings, two interfaces are supplied:
  5.     one for Pascal and one for C.  The difference is that Pascal
  6.     uses strings preceded by a length, and C uses 0-terminated
  7.     strings.  Therefore, to allow Pascal and C programs to be linked
  8.     together, two copies of these routines must be provided.
  9.     Those functions having copies for C are marked {C} in the left
  10.     margin.  Note:    Linking in either the Pascal or C library alone
  11.     does NOT two versions of a routine.  Only if both libraries used are
  12.         two versions potentially linked in.
  13.     
  14. This file makes use of a define "CDOS" that is set True under
  15. Concurrent DOS 286 systems.  A few of the system-level routines differ
  16. for this OS.
  17. #endif
  18.  
  19. pragma c_include('implement.pf');
  20. pragma c_include('fileh.pf');
  21. pragma c_include('seek.pf');
  22.  
  23. package System;
  24.    pragma Routine_aliasing_convention(Implement.RTE_aliasing);
  25.    -- Some routines are additionally aliased to prevent conflicts
  26.    -- with Pascal intrinsic routines Write, Read, Trunc, and Close.
  27.    with Implement,Loopholes:[Address],Fileh_type Transmitted;
  28.    with Seek_method_type Transmitted;
  29.    type 
  30.       Sharing_mode_type =       -- For networking access; MSDOS 3.x only.
  31.          (Compatibility,Deny_read_write,Deny_write,Deny_read,Deny_none);
  32.       Open_method = (For_reading, For_writing, For_updating);
  33.       File_attribute =
  34.      (Attr_read_only,    -- File may not be modified.
  35.       Attr_hidden,        -- File is hidden.
  36.       Attr_system,        -- File is a "system" file.
  37.       Attr_volume_id,    -- File is the volume id.
  38.       Attr_directory,    -- File is a directory.
  39.       Attr_archive        -- File has not been archived.
  40. #if defined(CDOS)
  41.      ,Attr_security     -- File has security enabled.
  42. #elif defined(ADOS)
  43.      ,x6,x7,x8            -- Ensure the mode is a word.
  44. #endif
  45.      );
  46.       File_mode  = set of file_attribute;
  47.       File_class =
  48.      (Disk_file,        -- File is on disk.
  49.       Console_input,    -- File is the keyboard.
  50.       Console_output,    -- File is the monitor.
  51.       Printer_device,    -- File is the printer.
  52.       Other_device);    -- File is something else.
  53.    {
  54.      NOTE: Following every call, the imported variable Errno contains the
  55.        status of the call. If zero, then the call was successful, otherwise
  56.        it will contain one of the error codes specified after each
  57.        routine declaration below.
  58.    }
  59.  
  60.    -- Return the mode of a file.
  61.    function Filemode(const Name: String): File_mode;    External;
  62.       -- Error_path_not_found.
  63.       -- Error_access_denied.
  64.       -- Error_invalid_function -- this error should never occur.
  65. {C}function C_filemode(Name: Charp): File_mode;     External;
  66.  
  67.    -- Return the class of a file..
  68.    function Fileclass(F: File_handle): File_class;    External;
  69.  
  70.    -- Close file whose handle is "F".
  71.    procedure Close(F: File_handle); external;
  72.       -- Error_invalid_handle -- file was not open, or "F" contains garbage.
  73.       pragma Alias(Close,Implement.RTE || 'zclose');
  74.       -- The Alias avoids external conflict with Pascal Close intrinsic..
  75.  
  76.    -- Create file "name" and open it for writing.
  77.    function Create(const Name: String; Mode: File_mode): File_handle; external;
  78.       -- Error_access_denied.
  79.       -- Error_path_not_found.
  80.       -- Error_too_many_files - file created but not opened.
  81. {C}function C_Create(Name: Charp; Mode: File_mode): File_handle; external;
  82. #if defined(CDOS)
  83. pragma Data(Import);
  84.    var _open_and_mask, _open_or_mask: Cardinal;
  85.    -- And/or the CDOS open/create flags with these values:
  86.    -- Flags = (Flags & _open_and_mask) | _open_or_mask;   
  87.    -- This applies for both c_create and c_open calls.       
  88.    -- These are initialized to 0xffff and 0x0 initially.  
  89. pragma Data;
  90. #endif
  91.  
  92.    function Create_text(const Name: String; Mode: File_mode): File_handle; external;
  93.       -- Identical to "Create" except it creates a text file. On systems that have
  94.       -- a single file format, this function is equivalent to "Creat".
  95. {C}function C_Create_text(Name: Charp; Mode: File_mode): File_handle; external;
  96. #ifndef CTOS
  97.       pragma Alias(Create_text,Implement.RTE || 'create');
  98.       pragma Alias(C_Create_text,Implement.RTE || 'c_create');
  99. #endif
  100.  
  101.    -- Reposition the file pointer assoicated with "F" to location "Loc"
  102.    -- according to the method specified in "Method".
  103.    -- Lseek_ is identical to Lseek except that it returns the new position.
  104.    procedure Lseek(F: File_handle; Loc: Longint; Method: Seek_method); external;
  105.    function Lseek_(F: File_handle; Loc: Longint; Method: Seek_method): Longint;
  106.                                     external;
  107.       -- Error_invalid_handle.
  108.       -- Error_invalid_function - the parameter "method" contains garbage.
  109.       pragma Alias(Lseek_,RTE ||'lseek');
  110.  
  111.    -- Make a new directory named "Name".
  112.    procedure Mkdir(const Name: String); external;
  113.       -- Error_path_not_found.
  114.       -- Error_access_denied - file already exists or directory overflow.
  115. {C}procedure C_Mkdir(Name: Charp); external;
  116.  
  117.    -- Open file "Name" for reading, writing, or updating.
  118.    -- Variable Sharing_mode specifies the sharing mode for DOS 3.x and
  119.    -- is used for every open.  By default Sharing_mode is set to Compatibility.
  120.    var Sharing_mode: Sharing_mode_type;
  121.    function Open(const Name: String; Method: Open_method): File_handle; external;
  122.       -- Error_invalid_access -- "method" parameter contains garbage
  123.       -- Error_file_not_found
  124.       -- Error_access_denied  -- file is a directory, volume id or read-only
  125.       -- Error_too_many_files -- limit in CONFIG.SYS has been reached
  126. {C}function C_Open(Name: Charp; Method: Open_method): File_handle; external;
  127.  
  128.    function Open_text(const Name: String; Method: Open_method): File_handle; external;
  129.       -- Opens a text file. On systems that have a single file format, this routine
  130.       -- is identical to "Open"
  131. {C}function C_Open_text(Name: Charp; Method: Open_method): File_handle; external;
  132. #ifndef CTOS
  133.       pragma Alias(Open_text,Implement.RTE || 'open');
  134.       pragma Alias(C_Open_text,Implement.RTE || 'c_open');
  135. #endif
  136.  
  137.    -- Read "Cnt" bytes from file "F" into buffer whose address is "Bufp".
  138.    -- Returns the number of bytes actually read; 0 if at EOF.
  139.    function Read(F: File_handle; Bufp: Address; Cnt: Byte_count):Byte_count; external;
  140.       -- Error_invalid_handle  -- file not open.
  141.       -- Error_access_denied   -- "F" was opened but not for reading.
  142.       pragma Alias(Read,Implement.RTE || 'zread');
  143.  
  144.    -- Remove directory.
  145.    procedure Rmdir(const Name: String); external;
  146.       -- Error_path_not_found.
  147.       -- Error_access_denied.
  148.       -- Error_current_directory - "Name" is the name of the current directory.
  149. {C}procedure C_Rmdir(Name:Charp); external;
  150.  
  151.    -- Erase file from directory.
  152.    procedure Unlink(const Name: String); external;
  153.       -- Error_file_not_found.
  154.       -- Error_access_denied.
  155. {C}procedure C_Unlink(Name: Charp); external;
  156.  
  157.    -- Rename a file..
  158.    procedure Rename(const Old:String; const New:String); external;
  159.      -- Error_file_not_found.
  160.      -- Error_not_same_device.
  161.      -- Error_access_denied.
  162. {C}procedure C_Rename(Old:Charp; New:Charp); external;
  163.  
  164.    -- Write "Cnt" bytes from buffer whose address is "Bufp" into file "F".
  165.    -- Write_ is identical to Write except number of bytes written is returned.
  166.    -- Note: If disk overflow occurs, Errno will have the value Error_disk_overflow
  167.    --        and Write_ will return with the number of bytes actually written
  168.    -- NOTE:  For CTOS, you must close the file to get all the data written.
  169.    -- The CTOS OS will not do so.
  170.  
  171.    procedure Write(F: File_handle; Bufp: Address; Cnt: Byte_count);      external;
  172.    function Write_(F: File_handle; Bufp: Address; Cnt: Byte_count):Byte_count; external;
  173.       -- Error_invalid_handle - file not open.
  174.       -- Error_access_denied  - file not open for writing.
  175.       pragma Alias(Write ,Implement.RTE || 'zwrite');
  176.       pragma Alias(Write_,Implement.RTE || 'zwrite');
  177.  
  178.    -- Truncates file at current position.
  179.    procedure Trunc(F: File_handle);                  external;
  180.       -- Error_invalid_handle.
  181.       -- Error_access_denied.
  182.       pragma Alias(Trunc,Implement.RTE || 'ztrunc');
  183.  
  184. #if defined(CDOS)
  185.    type Time_and_date = record
  186.       fb_Year: Integer; fb_Month, fb_Day, fb_Hour, fb_Min, fb_Sec: 0..255;
  187.       end;
  188. #elif defined(ADOS)
  189.    type File_time_type = record
  190.       Creation_date, Creation_time, Access_date, Access_time,
  191.       Write_date, Write_time: Cardinal;
  192.       end;
  193. #endif            
  194.  
  195. #if defined(ADOS)
  196.    type Find_buffer = record
  197.       TD: File_time_type;
  198.       fb_size: Longint; -- Size of file.
  199.       fb_attr: File_mode;
  200.       Namelen: 0..255;    -- Length of upcoming name; redundant with nul-terminator.
  201.       fb_pname: packed array[1..13] of char;    -- Includes trailing nul.
  202. #elif defined(CDOS)
  203.    type Find_buffer = record
  204.       fb_key: Longint;           -- For subsequent finds.
  205.       fb_pname:packed array[1..18] of char;     -- 18 bytes of name; 0-terminated.
  206.       fb_attr: File_mode;       -- Attribute bits.
  207.       -- There is one byte of padding here.
  208.       fb_recsize: Integer;       -- File record size.
  209.       fb_user, fb_group: 0..255;   -- Uid, Gid.
  210.       fb_protection:Integer;       -- ??
  211.       Reserved1: packed array[1..6] of char;
  212.       fb_size: Longint;        -- File size.
  213.       fb_TD: Time_and_date;
  214.       Reserved2: char;
  215. #else    -- MS-DOS.      
  216.    type Find_buffer = packed record
  217.       Reserved: packed array[1..21] of char;
  218.       fb_attr: File_mode;
  219.       fb_time: Cardinal;
  220.       fb_date: Cardinal;
  221.       fb_size: Longint;
  222.       fb_pname: packed array[1..13] of char;
  223. #endif      
  224.       end;
  225.  
  226.    procedure Find_first(const Path: String; var S: Find_buffer; 
  227. #if not defined(CDOS)
  228.       Attr: File_mode;
  229. #if defined(ADOS)
  230.       var Dirhandle:Cardinal;    -- Must be presented next time.   
  231. #endif      
  232. #endif      
  233.       );
  234.                                 external;
  235.       -- "Path" is a path name with wild card characters. The first file
  236.       -- encountered that matches the path name and has a subset of the
  237.       -- attributes specified in "Attr" is returned in S.  (Attr is not
  238.       -- applicable for Concurrent DOS 286.)
  239.       -- This value of S must be passed to Find_next to get subsequent
  240.       -- matches.
  241.       --     Error_file_not_found  -- invalid path name }
  242.       --     Error_no_more_files   -- no files matching this specification}
  243. {C}procedure C_Find_first(Path: Charp; var S: Find_buffer; 
  244. #if not defined(CDOS)
  245.     Attr: File_mode;
  246. #if defined(ADOS)
  247.     var Dirhandle:Cardinal;    -- Must be presented next time.
  248. #endif    
  249. #endif    
  250.     ); external;
  251.  
  252. #if defined(ADOS)
  253.    procedure Find_next(Dirhandle:Cardinal; var S:Find_buffer);    external;
  254.    procedure Find_close(Dirhandle:Cardinal);    external;    -- terminate find.
  255. #elif not defined(CDOS)
  256.    procedure Find_next(var S: Find_buffer);      external;
  257.       -- Called after Find_first to retrieve subsequent matches.
  258.       -- Error_no_more_files    -- no more files that match.
  259. #else
  260.    procedure Find_next(
  261.     const Path:String;    -- CDOS requires the path a second time.
  262.        var S: Find_buffer);      external;
  263.       -- Called after Find_first to retrieve subsequent matches.
  264.       -- Error_no_more_files    -- no more files that match.
  265. {C}procedure C_Find_next(
  266.     Path:Charp;           -- CDOS requires the path a second time.
  267.        var S: Find_buffer);      external;
  268.       -- Called after Find_first to retrieve subsequent matches.
  269.       -- Error_no_more_files    -- no more files that match.
  270. #endif       
  271.  
  272. #if not defined(CDOS)
  273.    procedure Switch_char(var C:char; Set_it:Boolean);    external;
  274.       -- Set or retrieve the Switch character.
  275.       -- If Set_it, then set it; otherwise return it in C.
  276. #endif      
  277.  
  278. #if not defined(CDOS)
  279.    procedure File_times(F: File_handle; var Date,Time: Cardinal);   external;
  280. #else   
  281.    procedure File_times(F: File_handle; var TD:Time_and_date);   external;
  282. #endif   
  283.       -- Returns the date and time of an open file.
  284.       -- Error_invalid_handle    --- file not open
  285.  
  286. #if not defined(CDOS)
  287.    procedure Set_file_times(F: File_handle; Date,Time: Cardinal);  external;
  288. #else   
  289.    procedure Set_file_times(F: File_handle; var TD:Time_and_date);  external;
  290. #endif   
  291.       -- Sets the date/time of a file.
  292.       -- Error_invalid_handle  -- File not open
  293.       
  294.    procedure Get_date(var Day,Month,Year:cardinal);external;
  295.    procedure Get_time(var Hrs, Mins, Secs:cardinal);external;
  296.  
  297.    const Clock_precision = 100; -- Clock returns time in hundredths of a second.
  298.    function Clock:Longint;    { Time in 100ths of a second. }  external;
  299.  
  300.    type Dos_return_code = 0..255;
  301.    procedure DOS_exit(RC:Dos_return_code); external;
  302.  
  303.    iterator Each_file(const Path: String):(const FN: String); external;
  304.       {
  305.      Given a path name "Path" with wild cards, this iterator will yield
  306.      every file name that matches it.
  307.       }
  308.       { There is no corresponding version for C. }
  309.  
  310.    -- Change the current working directory to "name".
  311.    procedure Chdir(const Name: String); external;
  312.       -- Error_path_not_found.
  313.    procedure C_Chdir(Name: Charp); external;
  314.  
  315.    -- Change mode of file "name" to "Mode".
  316.    procedure Chmod(const Name: String; Mode: File_mode); external;
  317.       -- Error_path_not_found.
  318.       -- Error_access_denied.
  319.       -- Error_invalid_function -- this error should never occur.
  320.    procedure C_Chmod(Name: Charp; Mode:File_mode); external;
  321.  
  322.    -- Duplicate file handle "F".
  323.    function Dup(F: File_handle): File_handle;    external;
  324.       -- Error_invalid_handle.
  325.       -- Error_too_many_open_files -- file limit of CONFIG.SYS exceeded.
  326.  
  327.    -- Duplicate file handle "F" as file handle "Newfh".
  328.    procedure Dup2(F,Newfh: File_handle); external;
  329.       -- Error_invalid_handle.
  330.  
  331.    end;
  332. pragma Alias(System,Implement.RTE || 'system');