Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/stdio/ArrayIO.xsac
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma safe
module ArrayIO;

/******************************************************************************
Expand Down
1 change: 1 addition & 0 deletions src/stdio/BinFile.sac
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma safe
class BinFile;

external classtype;
Expand Down
1 change: 1 addition & 0 deletions src/stdio/ComplexIO.sac
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma safe
module ComplexIO;

use IOresources: all;
Expand Down
1 change: 1 addition & 0 deletions src/stdio/FibreIO.sac
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma safe
module FibreIO;

use Array: all;
Expand Down
181 changes: 83 additions & 98 deletions src/stdio/File.sac
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#pragma safe
class File;

external classtype;

use FileSystem: { TheFileSystem };
use String: {string};
use SysErr: {syserr};
use String: { string };
use SysErr: { syserr };

export all;

/*
* Functions to open and close files.
*/
/******************************************************************************
*
* Functions to open and close files.
*
******************************************************************************/


external syserr, File fopen(string NAME, string MODE);
#pragma linkobj "src/File/fopen.o"
external syserr, File fopen(string NAME, string MODE);
#pragma effect TheFileSystem
#pragma linkobj "src/File/fopen.o"
#pragma linkname "SACfopen"
#pragma linksign [0,1,2,3]
/*
Expand All @@ -25,203 +27,186 @@ external syserr, File fopen(string NAME, string MODE);
* using the file handle.
*/


external syserr, File, string mkstemp( string template);
#pragma linkobj "src/File/mkstemp.o"
external syserr, File, string mkstemp(string template);
#pragma effect TheFileSystem
#pragma linkobj "src/File/mkstemp.o"
#pragma linkname "SACmkstemp"
#pragma linksign [0,1,2,3]
#pragma refcounting [2]
/*
* Create a temporary file using a name generated by the function
* mkstemp, and returns the corresponding file handle. The file is
* mkstemp, and returns the corresponding file handle. The file is
* opened for update ("w+"). An error condition is
* returned as well. You should inspect the error condition before
* using the file handle.
* The name of the resulting file is derived from the template
* argument. It should look like a file name with six trailing 'X's.
* Each X is then replaced by a character from the portable file
* name character set. The characters are chosen such that the
* Each X is then replaced by a character from the portable file
* name character set. The characters are chosen such that the
* resulting name does not duplicate the name of an existing file.
*/

syserr, File, string tmpfile()
{
err, file, name = mkstemp( "TMP_XXXXXX");

return( err, file, name);
err, file, name = mkstemp("TMP_XXXXXX");
return(err, file, name);
}
/*
* Create a temporary file using a name generated by the function
* mkstemp, and returns the corresponding file handle. The file is
* mkstemp, and returns the corresponding file handle. The file is
* opened for update ("w+"). An error condition is
* returned as well. You should inspect the error condition before
* using the file handle.
*/

external void fclose(File STREAM);
#pragma linkobj "src/File/fclose.o"
external void fclose(File STREAM);
#pragma effect TheFileSystem
#pragma linkobj "src/File/fclose.o"
#pragma linkname "SACfclose"
/*
* Close the stream given by the file handle STREAM.
* Close the stream given by the file handle STREAM.
*/

external void fremove(string fname);
#pragma linkobj "src/File/rm.o"
#pragma effect TheFileSystem
#pragma linkobj "src/File/rm.o"
/*
* Remove file or directory
* Remove file or directory.
*/

/******************************************************************************
*
* Functions for low-level input / output operations.
*
******************************************************************************/


/*
* Functions for low-level input / output operations
*/


external void fputc(char C, File &STREAM);
#pragma linkname "SACfputc"
external void fputc(char C, File &STREAM);
#pragma linkobj "src/File/fputc.o"
#pragma linkname "SACfputc"
/*
* Write the character C to the output stream STREAM.
* Write the character C to the output stream STREAM.
*/

external char fgetc(File &STREAM);
#pragma linkname "SACfgetc"
external char fgetc(File &STREAM);
#pragma linkobj "src/File/fgetc.o"
#pragma linkname "SACfgetc"
#pragma linksign [0,1]
/*
* Get the next character from the input stream STREAM.
* Get the next character from the input stream STREAM.
*/


external void ungetc(char C, File &STREAM);
#pragma linkname "SACungetc"
external void ungetc(char C, File &STREAM);
#pragma linkobj "src/File/ungetc.o"
#pragma linkname "SACungetc"
/*
* Put the character C back to the input stream STREAM for further
* read operations. Only one character may be put back between two
* consecutive read operations, otherwise the character put back first
* is overwritten.
*/

external void fputs(string S, File &STREAM);
#pragma linkname "SACfputs"
external void fputs(string S, File &STREAM);
#pragma linkobj "src/File/fputs.o"
#pragma linkname "SACfputs"
/*
* Write string S to stream.
*/

/******************************************************************************
*
* Functions for formatted input / output operations.
*
******************************************************************************/


/*
* Functions for formatted input / output operations
*/


external void fprintf(File &STREAM, string FORMAT, ...);
external void fprintf(File &STREAM, string FORMAT, ...);
#pragma linkobj "src/File/fprintf.o"
#pragma linkname "SACfprintf"
/*
* Print formatted output to STREAM which must be open for writing.
* The syntax of format strings is identical to that known from C.
* This function may be used to print values of types
* char, string, int, float, and double.
* char, string, int, float, and double.
*/


external int, ... fscanf(File &STREAM, string FORMAT);
#pragma linksign [0,1,2]
external int, ... fscanf(File &STREAM, string FORMAT);
#pragma linkobj "src/File/fscanf.o"
#pragma linkname "SACfscanf"
#pragma linksign [0,1,2]
/*
* Scan the given stream STREAM concerning the format string FORMAT.
* The syntax of format strings is identical to C except that the
* string conversion specifier %s is not supported.
* string conversion specifier %s is not supported.
* This function may be used to scan values of types
* char, int, float, and double. To scan strings use either fscans
* or fscanl, respectively.
* The int result gives the number of successfully performed
* The int result gives the number of successfully performed
* conversions.
*/


external string fscans(File &STREAM, int MAX);
#pragma linksign [0,1,2]
external string fscans(File &STREAM, int MAX);
#pragma linkobj "src/File/fscans.o"
/*
* Read the next character string from the input stream STREAM. Strings
* are delimited by any whitespace character including the
* end-of-file symbol. Always read at most MAX characters.
* Upon failure an empty string is returned.
*/


external string fscanl(File &STREAM, int MAX);
#pragma linksign [0,1,2]
#pragma linkobj "src/File/fscanl.o"
/*
* Read the next line from the input stream STREAM. Lines are character
* strings delimited by any new-line or end-of-file symbol.
* Always read at most MAX characters.
* Upon failure an empty string is returned.
*/

/*
* Read the next character string from the input stream STREAM. Strings
* are delimited by any whitespace character including the
* end-of-file symbol. Always read at most MAX characters.
* Upon failure an empty string is returned.
*/

/*
* Functions for managing file-bound I/O-streams.
*/
external string fscanl(File &STREAM, int MAX);
#pragma linkobj "src/File/fscanl.o"
#pragma linksign [0,1,2]
/*
* Read the next line from the input stream STREAM. Lines are character
* strings delimited by any new-line or end-of-file symbol.
* Always read at most MAX characters.
* Upon failure an empty string is returned.
*/

/******************************************************************************
*
* Functions for managing file-bound I/O-streams.
*
******************************************************************************/

external bool feof(File &STREAM);
external bool feof(File &STREAM);
#pragma linkobj "src/File/feof.o"
#pragma linkname "SACfeof"
#pragma linkobj "src/File/feof.o"
#pragma linksign [0,1]
/*
* Test the stream STREAM for having reached the end of the respective
* file.
* Test the stream STREAM for having reached the end of the respective file.
*/


external void fflush(File &STREAM);
external void fflush(File &STREAM);
#pragma linkobj "src/File/fflush.o"
#pragma linkname "SACfflush"
#pragma linkobj "src/File/fflush.o"
/*
* Write the buffer of a buffered output stream STREAM to the
* respective file.
* Write the buffer of a buffered output stream STREAM
* to the respective file.
*/


external void fseek(File &STREAM, int OFFSET, int BASE);
external void fseek(File &STREAM, int OFFSET, int BASE);
#pragma linkobj "src/File/fseek.o"
#pragma linkname "SACfseek"
#pragma linkobj "src/File/fseek.o"
/*
* Reposition the stream STREAM. The new position is given as an offset
* in bytes relative to BASE which may be 0 (beginning of file),
* 1 (current position), or 2 (end of file).
*/


external int ftell(File &STREAM);
external int ftell(File &STREAM);
#pragma linkobj "src/File/ftell.o"
#pragma linkname "SACftell"
#pragma linkobj "src/File/ftell.o"
#pragma linksign [0,1]
/*
* Return the offset of the current byte relative to
* the beginning of the file associated with STREAM.
*/


external void rewind(File &STREAM);
external void rewind(File &STREAM);
#pragma linkobj "src/File/rewind.o"
#pragma linkname "SACrewind"
#pragma linkobj "src/File/rewind.o"
/*
* Reposition the stream STREAM to the beginning of the file associated
* with it (identical to fseek(<stream>, 0, 0)).
*/




13 changes: 7 additions & 6 deletions src/stdio/IOresources.sac
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module IOresources;
#pragma safe
module IOresources;

import File : { File };
import TermFile : { TermFile, stdin, stdout, stderr };
import Terminal : { TheTerminal };
import FileSystem : { TheFileSystem };
import World : { TheWorld };
import File: { File };
import TermFile: { TermFile, stdin, stdout, stderr };
import Terminal: { TheTerminal };
import FileSystem: { TheFileSystem };
import World: { TheWorld };

export all;
1 change: 1 addition & 0 deletions src/stdio/ListIO.sac
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma safe
module ListIO;

use IOresources: all;
Expand Down
1 change: 1 addition & 0 deletions src/stdio/ScalarIO.xsac
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma safe
module ScalarIO;

use IOresources: all;
Expand Down
1 change: 1 addition & 0 deletions src/stdio/StdIO.sac
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma safe
module StdIO;

import ArrayIO: all;
Expand Down
Loading