[GODCC][COMMITTED] Move read_from_file and write_to_file to utils.a68

Jose E. Marchesi jemarch@gnu.org
Sat Nov 22 00:11:51 GMT 2025


---
 src/format.a68 | 30 ------------------------------
 src/utils.a68  | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/src/format.a68 b/src/format.a68
index 4c760b6..1633fb5 100644
--- a/src/format.a68
+++ b/src/format.a68
@@ -77,35 +77,5 @@ def
           write_to_file (out_file, answer)
     end;
 
-    { Read the contents of the file at the given PATH and return them
-      as a string.
-
-      If PATH is - then read contents from the standard input.  Error
-      out if the file cannot be found.
-
-      Note how this routine returns a name rather than a string.  This
-      is because the contents of the file can be rather large.  The
-      string is allocated on the heap.  The returned reference allows
-      the caller to modify the string. }
-
-    pub proc read_from_file = (string path) ref string:
-    begin int fd = (path = "-" | 0 | fopen_checked (path, file_o_rdonly));
-          long long int size = fsize_checked (path, fd);
-          (size > LENG LENG max_int | error ("input file is too big"));
-          fgets (fd, SHORTEN SHORTEN fsize_checked (path, fd))
-    end;
-
-    { Create an output file in PATH and write the contents of the
-      given string CONTENTS to it.
-
-      If PATH is - then write to the standard output.  Error out if
-      the file cannot be created or written to.  }
-
-    pub proc write_to_file = (string path, string contents) void:
-    begin int fd = (path = "-" | 1 | fcreate_checked (path, 8r644));
-          fputs_checked (path, fd, contents);
-          (fd /= 1 | fclose_checked (path, fd))
-    end;
-
     skip
 fed
diff --git a/src/utils.a68 b/src/utils.a68
index a31cc0f..e09bf74 100644
--- a/src/utils.a68
+++ b/src/utils.a68
@@ -68,7 +68,7 @@ def
 
     proc errorno = (string msg) void:
        (error (msg + ": " + strerror (errno)));
-    
+
     pub proc fopen_checked = (string path, bits flags) int:
            (int res = fopen (path, flags);
             (res /= -1 | res | errorno ("opening " + path); skip));
@@ -89,5 +89,35 @@ def
            (long long int res = fsize (fd);
             (res = - long long 1 | errorno ("getting size of file " + path); skip | res));
 
+    { Read the contents of the file at the given PATH and return them
+      as a string.
+
+      If PATH is - then read contents from the standard input.  Error
+      out if the file cannot be found.
+
+      Note how this routine returns a name rather than a string.  This
+      is because the contents of the file can be rather large.  The
+      string is allocated on the heap.  The returned reference allows
+      the caller to modify the string. }
+
+    pub proc read_from_file = (string path) ref string:
+    begin int fd = (path = "-" | 0 | fopen_checked (path, file_o_rdonly));
+          long long int size = fsize_checked (path, fd);
+          (size > LENG LENG max_int | error ("input file is too big"));
+          fgets (fd, SHORTEN SHORTEN fsize_checked (path, fd))
+    end;
+
+    { Create an output file in PATH and write the contents of the
+      given string CONTENTS to it.
+
+      If PATH is - then write to the standard output.  Error out if
+      the file cannot be created or written to.  }
+
+    pub proc write_to_file = (string path, string contents) void:
+    begin int fd = (path = "-" | 1 | fcreate_checked (path, 8r644));
+          fputs_checked (path, fd, contents);
+          (fd /= 1 | fclose_checked (path, fd))
+    end;
+
     skip
 fed
-- 
2.30.2


More information about the Algol68 mailing list