home *** CD-ROM | disk | FTP | other *** search
- { (C) Copyright 1986-1992 MetaWare Incorporated; Santa Cruz, CA 95060. }
-
- {
- Portable I/O Routines as Adapted to MetaWare Pascal
- }
-
- pragma c_include('filep.pf');
- pragma c_include('fileh.pf');
- pragma c_include('implement.pf');
- pragma C_include('SEEK.pf');
-
- package Portio;
- pragma Routine_aliasing_convention(Implement.RTE_ALIASING);
- with Loopholes:[Address];
- with Filep_type Transmitted;
- with Seek_method_type Transmitted;
- with Implement:[Byte_count] Transmitted;
- with Implement;
- var
- stdin, {Standard input}
- stdout, {Standard output}
- stderr: Filep; {Standard error file}
- IO_count: Byte_count; {Number of bytes read on last call to Fread}
- Line_incomplete: Boolean; {Set by Fgetline/Getline if EOL not encountered}
- BUFSIZE: Byte_count; -- Default buffer size: 512.
- -- File opens use this to allocate a buffer.
- -- Use powers of two for efficiency.
- stdstrg: Filep; -- We use this to implement readstr/writestr in the RTL.
-
- const
- EOFC = Chr(255); {End of file character indicator for fgetc}
- EOFW = -1; {End of file character for fgetw}
-
- type Real = Standard.Real; -- In case of VS Pascal, where real is redefined.
-
- #if 0
- Fopen - opens a file and returns a descriptor for it.
- Fname is the name of the file
- Mode is a sequence of one or more characters with the following
- meaning:
- 'w' = for writing
- 'r' = for reading
- 'a' = appending (mutually exclusive with 'w')
- 'u' = unbufferred
- Note: if the file is opened for both reading and writing ('rw'), then
- unbufferred will be assumed.
- If any character appears in the mode string other than those
- mentioned above, then Error_invalid_function will be returned in the
- imported variable Errno.
- #endif
-
- function Fopen(const Fname: String; const Mode: String): Filep; external;
-
- {
- Fclose - closes the specified file.
- }
- procedure Fclose(FP: Filep); external;
-
- {
- Fgetc - returns the next character from the input stream.
- EOFC is returned if EOF is encountered; however, since this is
- a perfectly valid (non-ASCII) character, Feof should be called
- to confirm true end-of-file.
- }
- function Fgetc(FP: Filep): Char; external;
- function Getc(): Char; external;
- {Equivalent to Fgetc(Default_input)}
-
- procedure Fflush(FP: Filep); external;
- {Flushes the buffer of a buffered output file}
- procedure Flush(); external;
- {Equivalent to Fflush(Default_output)}
- {
- Fputc - writes a character to a file.
- }
- procedure Fputc(FP: Filep; C: Char); external;
- procedure Putc(C: Char); external;
- {Equivalent to Fputc(Default_output,C)}
-
- {
- Fgetw - reads one 2-byte word from file. If end of file occurs, then
- the function returns EOFW. However, since this value is a valid
- integer, Feof should be confirmed to verify true end-of-file.
- }
- function Fgetw(FP: Filep): Integer; external;
- function Getw(): Integer; external;
-
- {
- Fputw - writes one word.
- }
- procedure Fputw(FP: Filep; I: Integer); external;
- procedure Putw(I: Integer); external;
-
- {
- Fread - reads "Len" number of bytes into buffer
- Number of bytes actually read returned in IO_count
- }
- procedure Fread(FP: Filep; BP: Address; Bytes: Byte_count);external;
-
- {
- Fwrite - writes "Len" bytes of data from Buf into "fp"
- }
- procedure Fwrite(FP: Filep; BP: Address; Bytes: Byte_count); external;
-
- procedure Fseek(FP: Filep; Offset: Longint; Method: Seek_method);external;
- {The location of the next byte in the stream FP is adjusted.}
-
- function Filepos(FP: Filep): Longint; external;
- { Returns the byte position of the next byte to be read/written. }
- { The position is origined such that 0 references the beginning of the file}
-
- function Feof(fp: Filep): Boolean; external;
- {Returns true if FP is positioned at the end of the file}
-
- function Getchar(): Char; external;
- {Same as Fgetc(Stdin)}
-
- procedure Putchar(C: Char); external;
- {Same as Fputc(Stdout,C)}
-
- procedure Fgets(fp: Filep; var S: String); external;
- {Read bytes into a string until end-of-line or until string filled to max}
- procedure Gets(var S:String); external;
- {Equivalent to Fgets(Default_input,S) }
-
- function Fgetline(FP: Filep; BP: Address; Bytes: Cardinal): Integer; external;
- function Getline(BP: Address; Bytes: Cardinal): Integer; external;
- {Reads bytes into a buffer until end-of-line encountered. The length}
- {of the line is returned. A value of -1 indicates end-of-file. }
- {The line terminator is not included in the length returned. }
- {For this reason, 0 is a valid line length. }
- {If there are more bytes on the line than Bytes, the boolean variable }
- {"Line_incomplete" (defined above) is set to true. }
-
- procedure Fputs(fp: Filep; const S: String); external;
- procedure Puts(const S: String); external;
- {Write contents of string}
-
- procedure Fprintl(fp: Filep; I: Longint); external;
- procedure Printl(I: Longint); external;
- {Print longint I in minimum field (no padding)}
-
- procedure Fprinti(fp: Filep; I: Integer); external;
- procedure Printi(I:Integer); external;
- {Print single word integer I}
- procedure FPrintu(fp: Filep; V: Cardinal); external;
- procedure Printu(V: Cardinal); external;
- {Print unsigned word integer}
-
- procedure FPrintll(fp: Filep; I: Longint; Len: Integer); external;
- procedure Printll(I: Longint; Len: Integer); external;
- {Print longint I in a field of minimum length |Len|. If Len > 0 then
- I will be right justified in the field. If Len < 0 then I will be left
- justified}
-
- procedure Fprintllr(fp: Filep; I: Longint; Len,Base: Integer); external;
- procedure Printllr(I:Longint; Len,Base: Integer); external;
- {Prints integer I in base |Base| in a field of at least |Len| characters}
- { Base must be within -16..16. A negative base will cause leading }
- { zeroes to be printed. }
-
- procedure Printr(R:real; FW, After_dot: Integer);external;
- procedure Fprintr(F:filep; R:real; FW, After_dot:Integer);external;
- #if 0
- Print real number R in FW:After_dot format, right-adjusted in field
- of at least FW (more chrs may be used.) Format is one of:
- After_dot < 0: (-/space) Digit.Digit More_digits e +/- Digit Digit
- After_dot >= 0: (- if negative) Digits . Digits
- where there are After_dot digits after . (no . if After_dot = 0).
- If FW is too small in latter case, first format is used.
- #endif
- procedure Printd(R:longreal; FW, After_dot: Integer);external;
- procedure Fprintd(F:filep; R:longreal; FW, After_dot:Integer);external;
- { Print longreal. }
- procedure Printx(R:extreal; FW, After_dot: Integer);external;
- procedure Fprintx(F:filep; R:extreal; FW, After_dot:Integer);external;
- { Print extreal. }
-
- procedure Ungetc(C: Char); external;
- procedure FUngetc(Fp: Filep; C: Char); external;
- {Inserts 'C' back into input buffer so that subsequent Fgetc will reread it}
- {Note: Guaranteed only to work once prior to calling Fgetc or Getchar}
-
- procedure Fputtext(Fp: Filep; BP: Address; Len: Cardinal; Field_width: Integer);
- external;
- procedure Puttext(BP:Address; Len: cardinal; Field_width: INteger); external;
- {Writes out an array of "Len" characters in a field of length }
- { Abs(Field_width). If field_width < 0 then the chars will be }
- { left justified instead of right justified }
-
- procedure Fnewline(Fp: Filep); external;
- procedure Newline(); external;
- {Terminates the current line. }
- {Depending on the host system, this routine will either write out a}
- { CR followed by LF, a LF only, or terminate the current logical record}
-
- function Fscani(Fp: Filep; Len: Cardinal): Longint; external;
- function Scani(Len: Cardinal): Longint; external;
- {Reads decimal integer from an Ascii file. Leading blanks are skipped}
- {Len is the number of bytes to scan. If Len=0 then leading blanks and}
- { CR/LF will be skipped until '+', '-', or digit detected; the bytes}
- { are then scanned until a non-digit is detected. }
- function Scanr(Len: Cardinal):real; external;
- function Fscanr(FP: Filep; Len: cardinal):real; external;
- {Like Fscani, but reads a real number. }
- function Scand(Len: Cardinal):Extreal; external;
- function Fscand(FP: Filep; Len: cardinal):Extreal; external;
- {Like Fscanr, but reads a long real. }
-
- procedure Fclose_all; external;
- {Closes all open files that where opened with Fopen}
-
- procedure FStackDump(F: Filep); external;
- {Produce stack dump of currently active procedures. }
-
- procedure Set_default_input(F: Filep); external;
- {Sets a new default input file}
-
- procedure Set_default_output(F: Filep); external;
- {Sets a new default output}
-
- function Default_input(): Filep; external;
- {Returns current default input}
-
- function Default_output(): Filep; external;
- {Returns current default output}
-
- procedure Restore_default_output(); external;
- {Restores default output prior to last call to "Set_default_output"}
-
- procedure Restore_default_input(); external;
- {Restores default output prior to last call to "Set_default_output"}
-
- function Handle(F: Filep): Fileh_type.File_handle; external;
- {Returns DOS file handle associated with F}
-
- procedure Make_buffered(F: Filep); external;
- procedure Make_unbuffered(F: Filep); external;
-
- type Temp_file_name = string(20); -- Handles most OSs.
- { Make a unique temporary name, typically used for temp files. }
- function Make_temp(const Prefix:String):Temp_file_name; external;
-
- pragma Alias(FStackDump,RTE || 'stackdump');
- {Alias so that StackDump(T:Text) in Debug_aids is same routine. }
- pragma Alias(Set_default_input,RTE || 'sdefin');
- pragma Alias(Set_default_output,RTE || 'sdefout');
- pragma Alias(Default_input,RTE || 'defin');
- pragma Alias(Default_output,RTE || 'defout');
- pragma Alias(Restore_default_output,RTE || 'rdefout');
- pragma Alias(Restore_default_input,RTE || 'rdefin');
- end;
- pragma alias(Portio,Implement.RTE || 'portio');
-