[ prog / sol / mona ]

prog


Running SchemeBBS using MIT Scheme 11.2

18 2022-05-30 13:40

>>15
This is a wasteful double conversion back to the source bytes that throws away the intermediate result. It also uses the deprecated form of read-string.

(string->utf8
    (call-with-input-file filename
                          (lambda (port)
                            (read-string (char-set) port)))))

https://www.gnu.org/software/mit-scheme/documentation/stable/mit-scheme-ref/Input-Procedures.html#index-read_002dstring

Note: MIT/GNU Scheme previously defined this procedure differently, and this alternate usage is deprecated; please use read-delimited-string instead. For now, read-string will redirect to read-delimited-string as needed, but this redirection will be eliminated in a future release.

(alternative fix: open file using open-binary-input-file, read file using call-with-port and read-bytevector)

You can use call-with-binary-input-file directly:

(define (read-file filename)
  (let ((size (file-length filename)))
    (if (zero? size)
        (make-bytevector 0)
        (call-with-binary-input-file
          filename
          (lambda (port)
            (read-bytevector size port))))))

SchemeBBS now works on MIT Scheme 11.2!

Conga rats.

There's one problem left: multi-byte characters. If you try to submit "一二三" through the textarea, you will get something like "一二三". Not sure how to fix this.

See whether https://textboard.org/prog/39#t39p263 still applies. If it doesn't, provide the hex bytes of a garbled post body and the corresponding original text from the textarea.

56


VIP:

do not edit these