home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / U3 < prev    next >
Encoding:
Text File  |  1992-12-09  |  13.7 KB  |  334 lines

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