Skip to content
22 changes: 3 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,23 +270,7 @@ SET (C_DEPS_SRC
stdio/src/TermFile/fscanl.c
stdio/src/TermFile/fprintf.c
stdio/src/File/rm.c
stdio/src/File/mkstemp.c
stdio/src/File/fscans.c
stdio/src/File/fscanl.c
stdio/src/File/fscanf.c
stdio/src/File/fprintf.c
stdio/src/File/fopen.c
stdio/src/File/fputc.c
stdio/src/File/fgetc.c
stdio/src/File/fputs.c
stdio/src/File/fgets.c
stdio/src/File/ungetc.c
stdio/src/File/fflush.c
stdio/src/File/feof.c
stdio/src/File/rewind.c
stdio/src/File/fseek.c
stdio/src/File/ftell.c
stdio/src/File/fclose.c
stdio/src/File/File.c
stdio/src/FibreIO/ScanStringArr.c
stdio/src/FibreIO/ScanString.c
stdio/src/FibreIO/ScanOthersArr.c
Expand Down Expand Up @@ -346,8 +330,8 @@ MESSAGE (DEBUG "Compiled together all source paths: ${ALL_SAC_SRC}")
# core modules or core + extended modules are built.
ADD_CUSTOM_TARGET (${TARGET}-all-modules ALL)

# TODO(artem) We may want to introduce a mechanism of generating depenencies
# on a given sac2c versoin. That is, recompiler all modules if
# TODO(artem) We may want to introduce a mechanism of generating dependencies
# on a given sac2c version. That is, recompiler all modules if
# sac2c version changes.


Expand Down
93 changes: 53 additions & 40 deletions src/stdio/File.sac
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class File;

external classtype;
#pragma ctype "FILE*"

use Array: all;
use String: { string, strsel, strlen, strtake, strcat };
Expand All @@ -18,7 +19,8 @@ export all;

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

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


external syserr, File, string mkstemp(string template);
#pragma effect TheFileSystem
#pragma linkobj "src/File/mkstemp.o"
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
#pragma linkname "SACmkstemp"
#pragma linksign [0,1,2,3]
#pragma refcounting [2]
#pragma linksign [0,1,2,2]
/*
* Create a temporary file using a name generated by the function
* mkstemp, and returns the corresponding file handle. The file is
Expand All @@ -60,17 +72,10 @@ syserr, File, string tmpfile()
* using the file handle.
*/

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.
*/

external void fremove(string fname);
external syserr fremove(string fname);
#pragma effect TheFileSystem
#pragma linkobj "src/File/rm.o"
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
/*
* Remove file or directory.
*/
Expand All @@ -81,23 +86,25 @@ external void fremove(string fname);
*
******************************************************************************/

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

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

external void ungetc(char C, File &STREAM);
#pragma linkobj "src/File/ungetc.o"
external syserr ungetc(char C, File &STREAM);
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
#pragma linkname "SACungetc"
/*
* Put the character C back to the input stream STREAM for further
Expand All @@ -106,17 +113,20 @@ external void ungetc(char C, File &STREAM);
* is overwritten.
*/

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

external syserr, string fgets (int size, File &STREAM);
#pragma linkname "SACfgets_F"
#pragma linkobj "src/File/fgets.o"
#pragma linkname "SACfgets"
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
#pragma linksign [0,1,2,3]
#pragma sacarg [1]
/*
* Read a string of max. length size from the provided TermFile.
*/
Expand All @@ -142,7 +152,8 @@ syserr, string fgetl (File &stream)
******************************************************************************/

external void fprintf(File &STREAM, string FORMAT, ...);
#pragma linkobj "src/File/fprintf.o"
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
#pragma linkname "SACfprintf"
/*
* Print formatted output to STREAM which must be open for writing.
Expand All @@ -152,7 +163,8 @@ external void fprintf(File &STREAM, string FORMAT, ...);
*/

external int, ... fscanf(File &STREAM, string FORMAT);
#pragma linkobj "src/File/fscanf.o"
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
#pragma linkname "SACfscanf"
#pragma linksign [0,1,2]
/*
Expand All @@ -167,8 +179,8 @@ external int, ... fscanf(File &STREAM, string FORMAT);
*/

external string fscans(File &STREAM, int MAX);
#pragma linkobj "src/File/fscans.o"
#pragma linksign [0,1,2]
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
/*
* Read the next character string from the input stream STREAM. Strings
* are delimited by any whitespace character including the
Expand All @@ -177,8 +189,8 @@ external string fscans(File &STREAM, int MAX);
*/

external string fscanl(File &STREAM, int MAX);
#pragma linkobj "src/File/fscanl.o"
#pragma linksign [0,1,2]
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
/*
* Read the next line from the input stream STREAM. Lines are character
* strings delimited by any new-line or end-of-file symbol.
Expand All @@ -193,23 +205,25 @@ external string fscanl(File &STREAM, int MAX);
******************************************************************************/

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

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

external void fseek(File &STREAM, int OFFSET, int BASE);
#pragma linkobj "src/File/fseek.o"
external int fseek(File &STREAM, int OFFSET, int BASE);
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
#pragma linkname "SACfseek"
/*
* Reposition the stream STREAM. The new position is given as an offset
Expand All @@ -218,17 +232,16 @@ external void fseek(File &STREAM, int OFFSET, int BASE);
*/

external int ftell(File &STREAM);
#pragma linkobj "src/File/ftell.o"
#pragma linkobj "src/File/File.o"
// #pragma header "src/File/File.h"
#pragma linkname "SACftell"
#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);
#pragma linkobj "src/File/rewind.o"
#pragma linkname "SACrewind"
#pragma header "<stdio.h>"
/*
* Reposition the stream STREAM to the beginning of the file associated
* with it (identical to fseek(<stream>, 0, 0)).
Expand Down
Loading