<commit_before>(defpackage "PARSER4")
(defpackage "UNICODE")
(defpackage "IO-SPEC")
(in-package "IO-SPEC")

;;;  sort Filename = String
;;;  sort Time     = Nat          % Not a fixnum
;;;  sort Byte     = {x : Nat | 0 <= x &  x < 256} 
;;;
;;;  op getCurrentDirectory   : () -> Filename
;;;  op fileExistsAndReadable : Filename -> Boolean
;;;  op fileWriteTime         : Filename -> Time
;;;
;;;  op fileWritable          : Filename -> Boolean
;;;  op readBytesFromFile     : Filename -> List Byte
;;;  op writeBytesToFile      : List Byte * Filename -> ()
;;;  op writeStringToFile     : List Byte * Filename -> ()
;;;


;;; This returns true if, as the name suggests, the given file
;;; exists and is readable. Otherwise, it returns false.
(defun fileExistsAndReadable (x)
  (handler-case
      (progn (close (open x :direction :input)) t)
    (file-error (condition) 
      (declare (ignore condition))
      nil)
    #+gcl
    (error (condition) 
      (declare (ignore condition))
      nil)))

(defvar nullFileWriteTime 9999999999999)   ; eons from now: "Thu May 21 10:46:39 PST 318787"

(defun fileWriteTime (file)
  ;; bignum (i.e., not a lisp fixnum, not a C int)
  ;; Bigger than 536870911 = 2^29 - 1 = most-positive-fixnum
  ;; Bigger than 2147483648 = 2^31 = biggest 32-bit int 
  (or #+allegro(excl::filesys-write-date file)    ; faster?
      ;;
      ;; The allegro hack above returns nil for names such as "~/foo.sw"
      ;; The following should succeed where the above hack returns nil, 
      ;; but maybe this is all that the standard file-write-date does:
      ;;  (excl::filesys-write-date (namestring (truename  file))) 
      ;;
      ;; Call this when hack fails (or we're not running Allego CL) ...
      (file-write-date file)
      ;; If file doesn't exist then return a future time! 
      ;; 3288592472 = "Thu Mar 18 01:54:32 PST 2004"
      nullFileWriteTime))

(defun currentTime-0 ()
  ;; bignum (i.e., not a lisp fixnum, not a C int)
  ;; Bigger than 536870911 = 2^29 - 1 = most-positive-fixnum
  ;; Bigger than 2147483648 = 2^31 = biggest 32-bit int 
  (get-universal-time))

(defun getCurrentDirectory-0 ()
  (convert-windows-filename (namestring (specware::current-directory))))

(defun convert-windows-filename (filestr)
  (declare (simple-string filestr))
  (let ((strip-c-colon-nm
	 (if (string-equal "c:" (subseq filestr 0 2))  ; Ignore case of c in =
	     (subseq filestr 2 (length filestr))
	   filestr)))
    (substitute #\/ #\\ strip-c-colon-nm)))

;;;  (defun fileExists (x)
;;;    (probe-file x))
;;;  
;;;  (defun openFile (name mode)
;;;    (handler-case<commit_msg>Add size test<commit_after>(defpackage "PARSER4")
(defpackage "UNICODE")
(defpackage "IO-SPEC")
(in-package "IO-SPEC")

;;;  sort Filename = String
;;;  sort Time     = Nat          % Not a fixnum
;;;  sort Byte     = {x : Nat | 0 <= x &  x < 256} 
;;;
;;;  op getCurrentDirectory   : () -> Filename
;;;  op fileExistsAndReadable : Filename -> Boolean
;;;  op fileWriteTime         : Filename -> Time
;;;
;;;  op fileWritable          : Filename -> Boolean
;;;  op readBytesFromFile     : Filename -> List Byte
;;;  op writeBytesToFile      : List Byte * Filename -> ()
;;;  op writeStringToFile     : List Byte * Filename -> ()
;;;


;;; This returns true if, as the name suggests, the given file
;;; exists and is readable. Otherwise, it returns false.
(defun fileExistsAndReadable (x)
  (handler-case
      (progn (close (open x :direction :input)) t)
    (file-error (condition) 
      (declare (ignore condition))
      nil)
    #+gcl
    (error (condition) 
      (declare (ignore condition))
      nil)))

(defvar nullFileWriteTime 9999999999999)   ; eons from now: "Thu May 21 10:46:39 PST 318787"

(defun fileWriteTime (file)
  ;; bignum (i.e., not a lisp fixnum, not a C int)
  ;; Bigger than 536870911 = 2^29 - 1 = most-positive-fixnum
  ;; Bigger than 2147483648 = 2^31 = biggest 32-bit int 
  (or #+allegro(excl::filesys-write-date file)    ; faster?
      ;;
      ;; The allegro hack above returns nil for names such as "~/foo.sw"
      ;; The following should succeed where the above hack returns nil, 
      ;; but maybe this is all that the standard file-write-date does:
      ;;  (excl::filesys-write-date (namestring (truename  file))) 
      ;;
      ;; Call this when hack fails (or we're not running Allego CL) ...
      (file-write-date file)
      ;; If file doesn't exist then return a future time! 
      ;; 3288592472 = "Thu Mar 18 01:54:32 PST 2004"
      nullFileWriteTime))

(defun currentTime-0 ()
  ;; bignum (i.e., not a lisp fixnum, not a C int)
  ;; Bigger than 536870911 = 2^29 - 1 = most-positive-fixnum
  ;; Bigger than 2147483648 = 2^31 = biggest 32-bit int 
  (get-universal-time))

(defun getCurrentDirectory-0 ()
  (convert-windows-filename (namestring (specware::current-directory))))

(defun convert-windows-filename (filestr)
  (declare (simple-string filestr))
  (let ((strip-c-colon-nm
	 (if (and (> (length filestr) 1)
		  (string-equal "c:" (subseq filestr 0 2)))  ; Ignore case of c in =
	     (subseq filestr 2 (length filestr))
	   filestr)))
    (substitute #\/ #\\ strip-c-colon-nm)))

;;;  (defun fileExists (x)
;;;    (probe-file x))
;;;  
;;;  (defun openFile (name mode)
;;;    (handler-case
{'fraction_non_alphanumeric': 0.1410134750427026, 'fraction_numerical': 0.04384133611691023, 'mean_word_length': 2.9505247376311843, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4323269', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1777, 'n_words': 553}