generator.registers assocs kernel kernel.private libc math
namespaces parser sequences strings words assocs splitting
math.parser cpu.architecture alien alien.accessors quotations
-system compiler.units ;
+system compiler.units io.encodings.binary ;
IN: alien.c-types
DEFER: <int>
r> add*
] when ;
+: malloc-file-contents ( path -- alien )
+ binary file-contents >byte-array malloc-byte-array ;
+
[
[ alien-cell ]
[ set-alien-cell ]
splitting growable classes tuples words.private
io.binary io.files vocabs vocabs.loader source-files
definitions debugger float-arrays quotations.private
-sequences.private combinators ;
+sequences.private combinators io.encodings.binary ;
IN: bootstrap.image
: my-arch ( -- arch )
"Writing image to " write
architecture get boot-image-name resource-path
dup write "..." print flush
- [ (write-image) ] with-file-writer ;
+ binary [ (write-image) ] with-file-writer ;
PRIVATE>
-IN: io.encodings.binary
-SYMBOL: binary
+IN: io.encodings.binary SYMBOL: binary
! Copyright (C) 2006, 2007 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: math kernel sequences sbufs vectors namespaces
-growable strings io classes io.streams.c continuations
+growable strings io classes continuations
io.styles io.streams.nested io.encodings.binary ;
IN: io.encodings
SYMBOL: begin
-: decoded ( buf ch -- buf ch state )
+: push-decoded ( buf ch -- buf ch state )
over push 0 begin ;
: push-replacement ( buf -- buf ch state )
! This is the replacement character
- HEX: fffd decoded ;
+ HEX: fffd push-decoded ;
: finish-decoding ( buf ch state -- str )
begin eq? [ decode-error ] unless drop "" like ;
decoded construct
] if ;
-: cr+ t swap set-line-reader-cr ; inline
+: cr+ t swap set-decoded-cr ; inline
-: cr- f swap set-line-reader-cr ; inline
+: cr- f swap set-decoded-cr ; inline
: line-ends/eof ( stream str -- str ) f like swap cr- ; inline
: line-ends\r ( stream str -- str ) swap cr+ ; inline
: line-ends\n ( stream str -- str )
- over line-reader-cr over empty? and
+ over decoded-cr over empty? and
[ drop dup cr- stream-readln ] [ swap cr- ] if ; inline
: handle-readln ( stream str ch -- str )
} case ;
: fix-read ( stream string -- string )
- over line-reader-cr [
+ over decoded-cr [
over cr-
"\n" ?head [
swap stream-read1 [ add ] when*
M: decoded stream-read-partial tuck stream-read fix-read ;
+: read-until-loop ( stream delim -- ch )
+ ! Copied from { c-reader stream-read-until }!!!
+ over stream-read1 dup [
+ dup pick memq? [ 2nip ] [ , read-until-loop ] if
+ ] [
+ 2nip
+ ] if ;
+
M: decoded stream-read-until
! Copied from { c-reader stream-read-until }!!!
[ swap read-until-loop ] "" make
swap over empty? over not and [ 2drop f f ] when ;
: fix-read1 ( stream char -- char )
- over line-reader-cr [
+ over decoded-cr [
over cr-
dup CHAR: \n = [
drop stream-read1
M: decoded stream-read1 1 over stream-read ;
-M: line-reader stream-readln ( stream -- str )
+M: decoded stream-readln ( stream -- str )
"\r\n" over stream-read-until handle-readln ;
! Encoding
8 shift bitor ;
: end-multibyte ( buf byte ch -- buf ch state )
- append-nums decoded ;
+ append-nums push-decoded ;
: begin-utf16be ( buf byte -- buf ch state )
dup -3 shift BIN: 11011 number= [
{ double [ end-multibyte ] }
{ quad1 [ append-nums quad2 ] }
{ quad2 [ handle-quad2be ] }
- { quad3 [ append-nums HEX: 10000 + decoded ] }
+ { quad3 [ append-nums HEX: 10000 + push-decoded ] }
{ ignore [ 2drop push-replacement ] }
} case ;
: handle-quad3le ( buf byte ch -- buf ch state )
swap dup -2 shift BIN: 110111 = [
- BIN: 11 bitand append-nums HEX: 10000 + decoded
+ BIN: 11 bitand append-nums HEX: 10000 + push-decoded
] [ 2drop push-replacement ] if ;
: decode-utf16le-step ( buf byte ch state -- buf ch state )
: begin-utf8 ( buf byte -- buf ch state )
{
- { [ dup -7 shift zero? ] [ decoded ] }
+ { [ dup -7 shift zero? ] [ push-decoded ] }
{ [ dup -5 shift BIN: 110 number= ] [ BIN: 11111 bitand double ] }
{ [ dup -4 shift BIN: 1110 number= ] [ BIN: 1111 bitand triple ] }
{ [ dup -3 shift BIN: 11110 number= ] [ BIN: 111 bitand quad ] }
} cond ;
: end-multibyte ( buf byte ch -- buf ch state )
- f append-nums [ decoded ] unless* ;
+ f append-nums [ push-decoded ] unless* ;
: decode-utf8-step ( buf byte ch state -- buf ch state )
{
IN: temporary
-USING: tools.test io.files io threads kernel continuations ;
+USING: tools.test io.files io threads kernel continuations io.encodings.ascii ;
[ "passwd" ] [ "/etc/passwd" file-name ] unit-test
[ "awk" ] [ "/usr/libexec/awk/" file-name ] unit-test
[ "awk" ] [ "/usr/libexec/awk///" file-name ] unit-test
[ ] [
- "test-foo.txt" resource-path [
+ "test-foo.txt" resource-path ascii [
"Hello world." print
] with-file-writer
] unit-test
[ ] [
- "test-foo.txt" resource-path <file-appender> [
+ "test-foo.txt" resource-path ascii [
"Hello appender." print
- ] with-stream
+ ] with-file-appender
] unit-test
[ ] [
- "test-bar.txt" resource-path <file-appender> [
+ "test-bar.txt" resource-path ascii [
"Hello appender." print
- ] with-stream
+ ] with-file-appender
] unit-test
[ "Hello world.\nHello appender.\n" ] [
- "test-foo.txt" resource-path file-contents
+ "test-foo.txt" resource-path ascii file-contents
] unit-test
[ "Hello appender.\n" ] [
- "test-bar.txt" resource-path file-contents
+ "test-bar.txt" resource-path ascii file-contents
] unit-test
[ ] [ "test-foo.txt" resource-path delete-file ] unit-test
[ ] [ "test-blah" resource-path make-directory ] unit-test
[ ] [
- "test-blah/fooz" resource-path <file-writer> dispose
+ "test-blah/fooz" resource-path ascii <file-writer> dispose
] unit-test
[ t ] [
[ f ] [ "test-blah" resource-path exists? ] unit-test
-[ ] [ "test-quux.txt" resource-path [ [ yield "Hi" write ] in-thread ] with-file-writer ] unit-test
+[ ] [ "test-quux.txt" resource-path ascii [ [ yield "Hi" write ] in-thread ] with-file-writer ] unit-test
[ ] [ "test-quux.txt" resource-path delete-file ] unit-test
-[ ] [ "test-quux.txt" resource-path [ [ yield "Hi" write ] in-thread ] with-file-writer ] unit-test
+[ ] [ "test-quux.txt" resource-path ascii [ [ yield "Hi" write ] in-thread ] with-file-writer ] unit-test
[ ] [ "test-quux.txt" "quux-test.txt" [ resource-path ] 2apply rename-file ] unit-test
[ t ] [ "quux-test.txt" resource-path exists? ] unit-test
USING: arrays io io.files kernel math parser strings system
-tools.test words namespaces io.encodings.ascii ;
+tools.test words namespaces io.encodings.ascii io.encodings.binary ;
IN: temporary
[ f ] [
] unit-test
: <resource-reader> ( resource -- stream )
- resource-path binary ascii <file-reader> ;
+ resource-path ascii <file-reader> ;
[
"This is a line.\rThis is another line.\r"
] unit-test
[ ] [
- image [
+ image binary [
10 [ 65536 read drop ] times
] with-file-reader
] unit-test
IN: temporary
[ "hello world" ] [
- "test.txt" resource-path [
+ "test.txt" resource-path ascii [
"hello world" write
] with-file-writer
! See http://factorcode.org/license.txt for BSD license.
USING: kernel kernel.private namespaces io
strings sequences math generic threads.private classes
-io.backend io.streams.lines io.streams.plain io.streams.duplex
-io.files continuations ;
+io.backend io.streams.duplex io.files continuations ;
IN: io.streams.c
TUPLE: c-writer handle ;
! Copyright (C) 2004, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: io.streams.lines
-USING: io.encodings.latin1 io.encodings ;
+! USING: io.encodings.latin1 io.encodings ;
-TUPLE: line-reader cr ;
-
-: <line-reader> ( stream -- new-stream )
- latin1 <decoded> ;
+! : <line-reader> ( stream -- new-stream )
+! latin1 <decoded> ;
namespaces prettyprint sequences strings vectors words
quotations inspector io.styles io combinators sorting
splitting math.parser effects continuations debugger
-io.files io.streams.string io.streams.lines vocabs
+io.files io.streams.string io.streams.lines vocabs io.encodings.utf8
source-files classes hashtables compiler.errors compiler.units ;
IN: parser
[
[
[ parsing-file ] keep
- [ ?resource-path <file-reader> ] keep
+ [ ?resource-path utf8 <file-reader> ] keep
parse-stream
] with-compiler-errors
] [
quotations inspector io.styles io combinators sorting
splitting math.parser effects continuations debugger
io.files io.crc32 io.streams.string io.streams.lines vocabs
-hashtables graphs compiler.units ;
+hashtables graphs compiler.units io.encodings.utf8 ;
IN: source-files
SYMBOL: source-files
: (source-modified?) ( path modified checksum -- ? )
pick file-modified rot [ 0 or ] 2apply >
- [ swap file-lines lines-crc32 = not ] [ 2drop f ] if ;
+ [ swap utf8 file-lines lines-crc32 = not ] [ 2drop f ] if ;
: source-modified? ( path -- ? )
dup source-files get at [
: reset-checksums ( -- )
source-files get [
swap ?resource-path dup exists?
- [ file-lines swap record-checksum ] [ 2drop ] if
+ [ utf8 file-lines swap record-checksum ] [ 2drop ] if
] assoc-each ;
M: pathname where pathname-string 1 2array ;
! Based on http://shootout.alioth.debian.org/gp4/benchmark.php?test=fasta&lang=java&id=2
USING: math kernel io io.files locals multiline assocs sequences
-sequences.private benchmark.reverse-complement hints
+sequences.private benchmark.reverse-complement hints io.encodings.ascii
byte-arrays float-arrays ;
IN: benchmark.fasta
n [ ]
seed [ initial-seed ] |
- out [
+ out ascii [
n 2 * ALU "Homo sapiens alu" "ONE" write-repeat-fasta
initial-seed
-USING: kernel io io.files splitting strings
+USING: kernel io io.files splitting strings io.encodings.ascii
hashtables sequences assocs math namespaces prettyprint
math.parser combinators arrays sorting unicode.case ;
: knucleotide ( -- )
"extra/benchmark/knucleotide/knucleotide-input.txt" resource-path
- [ read-input ] with-file-reader
+ ascii [ read-input ] with-file-reader
process-input ;
MAIN: knucleotide
IN: benchmark.mandel
USING: arrays io kernel math namespaces sequences strings sbufs
-math.functions math.parser io.files colors.hsv ;
+math.functions math.parser io.files colors.hsv io.encodings.binary ;
: max-color 360 ; inline
: zoom-fact 0.8 ; inline
: mandel-main ( -- )
"mandel.ppm" resource-path
- [ mandel write ] with-file-writer ;
+ binary [ mandel write ] with-file-writer ;
MAIN: mandel-main
USING: float-arrays compiler generic io io.files kernel math
math.functions math.vectors math.parser namespaces sequences
-sequences.private words ;
+sequences.private words io.encodings.binary ;
IN: benchmark.raytracer
! parameters
: raytracer-main
"raytracer.pnm" resource-path
- [ run write ] with-file-writer ;
+ binary [ run write ] with-file-writer ;
MAIN: raytracer-main
USING: io io.files io.streams.duplex kernel sequences
sequences.private strings vectors words memoize splitting
-hints unicode.case ;
+hints unicode.case io.encodings.latin1 ;
IN: benchmark.reverse-complement
MEMO: trans-map ( -- str )
readln [ do-line (reverse-complement) ] [ show-seq ] if* ;
: reverse-complement ( infile outfile -- )
- <file-writer> >r <file-reader> r> <duplex-stream> [
+ latin1 <file-writer> >r latin1 <file-reader> r> <duplex-stream> [
500000 <vector> (reverse-complement)
] with-stream ;
-USING: io io.files math math.parser kernel prettyprint ;
+USING: io io.files math math.parser kernel prettyprint io.encodings.ascii ;
IN: benchmark.sum-file
: sum-file-loop ( n -- n' )
readln [ string>number + sum-file-loop ] when* ;
: sum-file ( file -- )
- [ 0 sum-file-loop ] with-file-reader . ;
+ ascii [ 0 sum-file-loop ] with-file-reader . ;
: sum-file-main ( -- )
home "sum-file-in.txt" path+ sum-file ;
! See http://factorcode.org/license.txt for BSD license.
IN: bootstrap.image.upload
USING: http.client crypto.md5 splitting assocs kernel io.files
-bootstrap.image sequences io namespaces io.launcher math ;
+bootstrap.image sequences io namespaces io.launcher math io.encodings.ascii ;
: destination "slava@factorcode.org:www/images/latest/" ;
: boot-image-names images [ boot-image-name ] map ;
: compute-checksums ( -- )
- "checksums.txt" [
+ "checksums.txt" ascii [
boot-image-names [ dup write bl file>md5str print ] each
] with-file-writer ;
USING: alien alien.c-types arrays sequences math math.vectors math.matrices
- math.parser io io.files kernel opengl opengl.gl opengl.glu
+ math.parser io io.files kernel opengl opengl.gl opengl.glu io.encodings.ascii
opengl.capabilities shuffle http.client vectors splitting tools.time system
combinators combinators.cleave float-arrays continuations namespaces
sequences.lib ;
: read-model ( stream -- model )
"Reading model" print flush [
- [ parse-model ] with-file-reader
+ ascii [ parse-model ] with-file-reader
[ normals ] 2keep 3array
] time ;
USING: kernel math sequences words arrays io
io.files namespaces math.parser kernel.private
assocs quotations parser parser-combinators tools.time
- sequences.private compiler.units ;
+ sequences.private compiler.units io.encodings.binary ;
IN: cpu.8080.emulator
TUPLE: cpu b c d e f h l a pc sp halted? last-interrupt cycles ram ;
: load-rom ( filename cpu -- )
#! Load the contents of the file into ROM.
#! (address 0x0000-0x1FFF).
- cpu-ram swap [
+ cpu-ram swap binary [
0 swap (load-rom)
] with-file-reader ;
#! file path shoul dbe relative to the '/roms' resource path.
rom-dir [
cpu-ram [
- swap first2 rom-dir swap path+ [
+ swap first2 rom-dir swap path+ binary [
swap (load-rom)
] with-file-reader
] curry each
USING: cryptlib.libcl cryptlib prettyprint kernel alien sequences libc math
-tools.test io io.files continuations alien.c-types splitting generic.math ;
+tools.test io io.files continuations alien.c-types splitting generic.math
+io.encodings.binary ;
"=========================================================" print
"Envelope/de-envelop test..." print
! envelope
CRYPT_FORMAT_CRYPTLIB [
"extra/cryptlib/test/large_data.txt" resource-path
- file-contents set-pop-buffer
+ binary file-contents set-pop-buffer
envelope-handle CRYPT_ATTRIBUTE_BUFFERSIZE
get-pop-buffer alien>char-string length 10000 + set-attribute
envelope-handle CRYPT_ENVINFO_DATASIZE
CRYPT_FORMAT_CRYPTLIB [
envelope-handle CRYPT_ENVINFO_PASSWORD "password" set-attribute-string
"extra/cryptlib/test/large_data.txt" resource-path
- file-contents set-pop-buffer
+ binary file-contents set-pop-buffer
envelope-handle CRYPT_ATTRIBUTE_BUFFERSIZE
get-pop-buffer alien>char-string length 10000 + set-attribute
envelope-handle CRYPT_ENVINFO_DATASIZE
USING: arrays combinators crypto.common crypto.md5 crypto.sha1
crypto.md5.private io io.binary io.files io.streams.string
-kernel math math.vectors memoize sequences ;
+kernel math math.vectors memoize sequences io.encodings.binary ;
IN: crypto.hmac
: sha1-hmac ( Ko Ki -- hmac )
[ init-hmac sha1-hmac ] with-stream ;
: file>sha1-hmac ( K path -- hmac )
- <file-reader> stream>sha1-hmac ;
+ binary <file-reader> stream>sha1-hmac ;
: string>sha1-hmac ( K string -- hmac )
<string-reader> stream>sha1-hmac ;
[ init-hmac md5-hmac ] with-stream ;
: file>md5-hmac ( K path -- hmac )
- <file-reader> stream>md5-hmac ;
+ binary <file-reader> stream>md5-hmac ;
: string>md5-hmac ( K string -- hmac )
<string-reader> stream>md5-hmac ;
USING: kernel io io.binary io.files io.streams.string math
math.functions math.parser namespaces splitting strings
-sequences crypto.common byte-arrays locals sequences.private ;
+sequences crypto.common byte-arrays locals sequences.private
+io.encodings.binary ;
IN: crypto.md5
<PRIVATE
: string>md5 ( string -- byte-array ) <string-reader> stream>md5 ;
: string>md5str ( string -- md5-string ) string>md5 hex-string ;
-: file>md5 ( path -- byte-array ) <file-reader> stream>md5 ;
+: file>md5 ( path -- byte-array ) binary <file-reader> stream>md5 ;
: file>md5str ( path -- md5-string ) file>md5 hex-string ;
-USING: arrays combinators crypto.common kernel io io.binary
+USING: arrays combinators crypto.common kernel io io.encodings.binary
io.files io.streams.string math.vectors strings sequences
namespaces math parser sequences vectors
hashtables ;
: string>sha1 ( string -- sha1 ) <string-reader> stream>sha1 ;
: string>sha1str ( string -- str ) string>sha1 hex-string ;
: string>sha1-bignum ( string -- n ) string>sha1 be> ;
-: file>sha1 ( file -- sha1 ) <file-reader> stream>sha1 ;
+: file>sha1 ( file -- sha1 ) binary <file-reader> stream>sha1 ;
: string>sha1-interleave ( string -- seq )
[ zero? ] left-trim
USING: arrays definitions io kernel math
namespaces parser prettyprint sequences strings words
editors io.files io.sockets io.streams.string io.binary
-math.parser ;
+math.parser io.encodings.ascii ;
IN: editors.jedit
: jedit-server-info ( -- port auth )
- home "/.jedit/server" path+ [
+ home "/.jedit/server" path+ ascii [
readln drop
readln string>number
readln string>number
http.server.responders http.server.templating io.files kernel
math namespaces quotations sequences splitting words strings
vectors webapps.callback continuations tuples classes vocabs
-html io ;
+html io io.encodings.binary ;
IN: furnace
: code>quotation ( word/quot -- quot )
</a> ;
: send-resource ( name -- )
- template-path get swap path+ resource-path <file-reader>
+ template-path get swap path+ resource-path binary <file-reader>
stdio get stream-copy ;
: render-link ( quot name -- )
USING: alien arrays byte-arrays combinators
graphics.viewer io io.binary io.files kernel libc math
math.functions namespaces opengl opengl.gl prettyprint
-sequences strings ui ui.gadgets.panes ;
+sequences strings ui ui.gadgets.panes io.encodings.binary ;
IN: graphics.bitmap
! Currently can only handle 24bit bitmaps.
dup color-index-length read swap set-bitmap-color-index ;
: load-bitmap ( path -- bitmap )
- [
+ binary [
T{ bitmap } clone
dup parse-file-header
dup parse-bitmap-header
raw-bitmap>string >byte-array over set-bitmap-array ;
: save-bitmap ( bitmap path -- )
- [
+ binary [
"BM" write
dup bitmap-array length 14 + 40 + 4 >le write
0 4 >le write
}
"Print the lines of a file in sorted order:"
{ $code
- "\"lines.txt\" file-lines natural-sort [ print ] each"
+ "utf8 \"lines.txt\" file-lines natural-sort [ print ] each"
}
"Read 1024 bytes from a file:"
{ $code
- "\"data.bin\" [ 1024 read ] with-file-reader"
+ "\"data.bin\" binary [ 1024 read ] with-file-reader"
}
"Convert a file of 4-byte cells from little to big endian or vice versa, by directly mapping it into memory:"
{ $code
! See http://factorcode.org/license.txt for BSD license.
USING: assocs http kernel math math.parser namespaces sequences
io io.sockets io.streams.string io.files io.timeouts strings
-splitting continuations assocs.lib ;
+splitting continuations assocs.lib io.encodings.binary ;
IN: http.client
: parse-host ( url -- host port )
: download-to ( url file -- )
#! Downloads the contents of a URL to a file.
>r http-get-stream check-response
- r> <file-writer> stream-copy ;
+ r> binary <file-writer> stream-copy ;
: download ( url -- )
dup download-name download-to ;
USING: io io.files io.streams.string http.server.templating kernel tools.test
- sequences ;
+ sequences io.encodings.utf8 ;
IN: temporary
: test-template ( path -- ? )
".fhtml" append resource-path
[ run-template-file ] with-string-writer
] keep
- ".html" append resource-path file-contents = ;
+ ".html" append resource-path utf8 file-contents = ;
[ t ] [ "example" test-template ] unit-test
[ t ] [ "bug" test-template ] unit-test
USING: continuations sequences kernel parser namespaces io
io.files io.streams.lines io.streams.string html html.elements
source-files debugger combinators math quotations generic
-strings splitting ;
+strings splitting io.encodings.utf8 ;
IN: http.server.templating
templating-vocab use+
dup source-file file set ! so that reload works properly
[
- ?resource-path file-contents
+ ?resource-path utf8 file-contents
[ eval-template ] [ html-error. drop ] recover
] keep
] with-file-vocabs
swap path+ run-template-file ;
: template-convert ( infile outfile -- )
- [ run-template-file ] with-file-writer ;
+ utf8 [ run-template-file ] with-file-writer ;
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math sequences kernel.private namespaces arrays io
io.files splitting io.binary math.functions vectors quotations
-combinators ;
+combinators io.encodings.binary ;
IN: icfp.2006
SYMBOL: regs
[ run-op exec-loop ] unless ;
: load-platters ( path -- )
- file-contents 4 group [ be> ] map
+ binary file-contents 4 group [ be> ] map
0 arrays get set-nth ;
: init ( path -- )
USING: arrays combinators io io.binary io.files io.paths
io.encodings.utf16 kernel math math.parser namespaces sequences
-splitting strings assocs unicode.categories ;
+splitting strings assocs unicode.categories io.encodings.binary ;
IN: id3
read-header read-frames <tag> ;
: supported-version? ( version -- ? )
- [ 3 4 ] member? ;
+ { 3 4 } member? ;
: read-id3v2 ( -- tag/f )
read1 dup supported-version?
[ (read-id3v2) ] [ drop f ] if ;
: id3v2? ( -- ? )
- 3 read "ID3" = ;
+ 3 read "ID3" sequence= ;
: read-tag ( stream -- tag/f )
id3v2? [ read-id3v2 ] [ f ] if ;
: id3v2 ( filename -- tag/f )
- [ read-tag ] with-file-reader ;
+ binary [ read-tag ] with-file-reader ;
: file? ( path -- ? )
stat 3drop not ;
[ mp3? ] subset ;
: id3? ( file -- ? )
- [ id3v2? ] with-file-reader ;
+ binary [ id3v2? ] with-file-reader ;
: id3s ( files -- id3s )
[ id3? ] subset ;
-USING: io io.mmap io.files kernel tools.test continuations sequences ;
+USING: io io.mmap io.files kernel tools.test continuations
+sequences io.encodings.ascii ;
IN: temporary
[ "mmap-test-file.txt" resource-path delete-file ] ignore-errors
-[ ] [ "mmap-test-file.txt" resource-path [ "12345" write ] with-file-writer ] unit-test
+[ ] [ "mmap-test-file.txt" resource-path ascii [ "12345" write ] with-file-writer ] unit-test
[ ] [ "mmap-test-file.txt" resource-path dup file-length [ CHAR: 2 0 pick set-nth drop ] with-mapped-file ] unit-test
[ 5 ] [ "mmap-test-file.txt" resource-path dup file-length [ length ] with-mapped-file ] unit-test
-[ "22345" ] [ "mmap-test-file.txt" resource-path file-contents ] unit-test
+[ "22345" ] [ "mmap-test-file.txt" resource-path ascii file-contents ] unit-test
[ "mmap-test-file.txt" resource-path delete-file ] ignore-errors
USING: io.files io.sockets io kernel threads namespaces
tools.test continuations strings byte-arrays sequences
-prettyprint system ;
+prettyprint system io.encodings.binary ;
IN: temporary
! Unix domain stream sockets
! Invalid parameter tests
[
- image [ stdio get accept ] with-file-reader
+ image binary [ stdio get accept ] with-file-reader
] must-fail
[
- image [ stdio get receive ] with-file-reader
+ image binary [ stdio get receive ] with-file-reader
] must-fail
[
- image [
+ image binary [
B{ 1 2 } server-addr
stdio get send
] with-file-reader
-USING: kernel io io.files io.monitors ;\r
+USING: kernel io io.files io.monitors io.encodings.utf8 ;\r
IN: log-viewer\r
\r
: read-lines ( stream -- )\r
dup next-change 2drop over read-lines tail-file-loop ;\r
\r
: tail-file ( file -- )\r
- dup <file-reader> dup read-lines\r
+ dup utf8 <file-reader> dup read-lines\r
swap parent-directory f <monitor>\r
tail-file-loop ;\r
! Copyright (C) 2008 Slava Pestov.\r
! See http://factorcode.org/license.txt for BSD license.\r
USING: logging.analysis logging.server logging smtp io.sockets\r
-kernel io.files io.streams.string namespaces raptor.cron assocs ;\r
+kernel io.files io.streams.string namespaces raptor.cron assocs\r
+io.encodings.utf8 ;\r
IN: logging.insomniac\r
\r
SYMBOL: insomniac-smtp-host\r
\r
: ?analyze-log ( service word-names -- string/f )\r
>r log-path 1 log# dup exists? [\r
- file-lines r> [ analyze-log ] with-string-writer\r
+ utf8 file-lines r> [ analyze-log ] with-string-writer\r
] [\r
r> 2drop f\r
] if ;\r
USING: namespaces kernel io calendar sequences io.files\r
io.sockets continuations prettyprint assocs math.parser\r
words debugger math combinators concurrency arrays init\r
-math.ranges strings ;\r
+math.ranges strings io.encodings.utf8 ;\r
IN: logging.server\r
\r
: log-root ( -- string )\r
: open-log-stream ( service -- stream )\r
log-path\r
dup make-directories\r
- 1 log# <file-appender> ;\r
+ 1 log# utf8 <file-appender> ;\r
\r
: log-stream ( service -- stream )\r
log-files get [ open-log-stream ] cache ;\r
! Copyright (C) 2007 Adam Wendt.\r
! See http://factorcode.org/license.txt for BSD license.\r
USING: alien alien.c-types byte-arrays io io.binary io.files kernel mad\r
- namespaces prettyprint sbufs sequences tools.interpreter vars ;\r
+ namespaces prettyprint sbufs sequences tools.interpreter vars\r
+ io.encodings.binary ;\r
IN: mad.api\r
\r
VARS: buffer-start buffer-length output-callback-var ;\r
: make-decoder ( -- decoder )\r
"mad_decoder" malloc-object ;\r
\r
-: malloc-file-contents ( path -- alien )\r
- file-contents >byte-array malloc-byte-array ;\r
-\r
: mad-run ( -- int )\r
make-decoder [ mad-init ] keep MAD_DECODER_MODE_SYNC mad_decoder_run ;\r
\r
-USING: io io.files sequences xml xml.utilities ;
+USING: io io.files sequences xml xml.utilities io.encodings.utf8 ;
IN: msxml-to-csv
: print-csv ( table -- ) [ "," join print ] each ;
] map ;
: msxml>csv ( infile outfile -- )
- [
+ utf8 [
file>xml (msxml>csv) print-csv
] with-file-writer ;
sequences libc shuffle alien.c-types system openal math\r
namespaces threads shuffle opengl arrays ui.gadgets.worlds\r
combinators math.parser ui.gadgets ui.render opengl.gl ui\r
- continuations io.files hints combinators.lib sequences.lib ;\r
+ continuations io.files hints combinators.lib sequences.lib\r
+ io.encodings.binary ;\r
\r
IN: ogg.player\r
\r
<player> play-ogg ;\r
\r
: play-vorbis-file ( filename -- )\r
- <file-reader> play-vorbis-stream ;\r
+ binary <file-reader> play-vorbis-stream ;\r
\r
: play-theora-stream ( stream -- )\r
<player>\r
play-ogg ;\r
\r
: play-theora-file ( filename -- )\r
- <file-reader> play-theora-stream ;\r
+ binary <file-reader> play-theora-stream ;\r
\r
IN: temporary
USING: arrays io kernel porter-stemmer sequences tools.test
-io.files ;
+io.files io.encodings.utf8 ;
[ 0 ] [ "xa" consonant-seq ] unit-test
[ 0 ] [ "xxaa" consonant-seq ] unit-test
[ "hell" ] [ "hell" step5 "" like ] unit-test
[ "mate" ] [ "mate" step5 "" like ] unit-test
-: resource-lines resource-path file-lines ;
+: resource-lines resource-path utf8 file-lines ;
[ { } ] [
"extra/porter-stemmer/test/voc.txt" resource-lines
! Copyright (c) 2008 Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license.
USING: ascii io.files kernel math math.functions namespaces
- project-euler.common sequences sequences.lib splitting ;
+ project-euler.common sequences sequences.lib splitting io.encodings.ascii ;
IN: project-euler.042
! http://projecteuler.net/index.php?section=problems&id=42
: source-042 ( -- seq )
"extra/project-euler/042/words.txt" resource-path
- file-contents [ quotable? ] subset "," split ;
+ ascii file-contents [ quotable? ] subset "," split ;
: (triangle-upto) ( limit n -- )
2dup nth-triangle > [
! Copyright (c) 2007 Samuel Tardieu, Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license.
-USING: io.files math.parser namespaces project-euler.common sequences splitting ;
+USING: io.files math.parser namespaces project-euler.common
+io.encodings.ascii sequences splitting ;
IN: project-euler.067
! http://projecteuler.net/index.php?section=problems&id=67
: source-067 ( -- seq )
"extra/project-euler/067/triangle.txt" resource-path
- file-lines [ " " split [ string>number ] map ] map ;
+ ascii file-lines [ " " split [ string>number ] map ] map ;
PRIVATE>
! Copyright (c) 2008 Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license.
-USING: assocs hashtables io.files kernel math math.parser namespaces sequences ;
+USING: assocs hashtables io.files kernel math math.parser namespaces
+io.encodings.ascii sequences ;
IN: project-euler.079
! http://projecteuler.net/index.php?section=problems&id=79
<PRIVATE
: source-079 ( -- seq )
- "extra/project-euler/079/keylog.txt" resource-path file-lines ;
+ "extra/project-euler/079/keylog.txt" resource-path ascii file-lines ;
: >edges ( seq -- seq )
[
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
USING: io io.files io.streams.lines io.streams.plain io.streams.duplex
- listener ;
+ listener io.encodings.utf8 ;
: tty-listener ( tty -- )
- [ <file-reader> ] [ <file-writer> ] bi <duplex-stream>
+ [ utf8 <file-reader> ] [ utf8 <file-writer> ] bi <duplex-stream>
[ listener ] with-stream ;
! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-USING: rss io kernel io.files tools.test ;
+USING: rss io kernel io.files tools.test io.encodings.utf8 ;
: load-news-file ( filename -- feed )
#! Load an news syndication file and process it, returning
#! it as an feed tuple.
- <file-reader> read-feed ;
+ utf8 <file-reader> read-feed ;
[ T{
feed
USING: combinators io io.files io.streams.duplex
io.streams.string kernel math math.parser continuations
namespaces pack prettyprint sequences strings system
-hexdump tools.interpreter ;
+hexdump tools.interpreter io.encodings.binary ;
IN: tar
: zero-checksum 256 ;
! Normal file
: typeflag-0
- tar-header-name tar-path+ <file-writer>
+ tar-header-name tar-path+ binary <file-writer>
[ read-data-blocks ] keep dispose ;
! Hard link
] when* ;
: parse-tar ( path -- obj )
- [
+ binary [
"tar-test" resource-path base-dir set
global [ nl nl nl "Starting to parse .tar..." print flush ] bind
global [ "Expanding to: " write base-dir get . flush ] bind
inspector debugger io io.styles io.streams.lines hashtables
sorting prettyprint source-files arrays combinators strings
system math.parser help.markup help.topics help.syntax
-help.stylesheet memoize ;
+help.stylesheet memoize io.encodings.utf8 ;
IN: tools.browser
MEMO: (vocab-file-contents) ( path -- lines )
?resource-path dup exists?
- [ file-lines ] [ drop f ] if ;
+ [ utf8 file-lines ] [ drop f ] if ;
: vocab-file-contents ( vocab name -- seq )
vocab-path+ dup [ (vocab-file-contents) ] when ;
: set-vocab-file-contents ( seq vocab name -- )
dupd vocab-path+ [
?resource-path
- [ [ print ] each ] with-file-writer
+ utf8 [ [ print ] each ] with-file-writer
] [
"The " swap vocab-name
" vocabulary was not loaded from the file system"
] H{ } make-assoc print-plist ;
: create-app-plist ( vocab bundle-name -- )
- dup "Contents/Info.plist" path+ <file-writer>
- [ print-app-plist ] with-stream ;
+ dup "Contents/Info.plist" path+
+ utf8 [ print-app-plist ] with-file-writer ;
: create-app-dir ( vocab bundle-name -- vm )
dup "Frameworks" copy-bundle-dir
! See http://factorcode.org/license.txt for BSD license.
USING: io.files io words alien kernel math.parser alien.syntax
io.launcher system assocs arrays sequences namespaces qualified
-system math windows.kernel32 generator.fixup ;
+system math windows.kernel32 generator.fixup io.encodings.ascii ;
IN: tools.disassembler
: in-file "gdb-in.txt" resource-path ;
word-xt code-format - 2array make-disassemble-cmd ;
M: pair make-disassemble-cmd
- in-file [
+ in-file ascii [
"attach " write
current-process-handle number>string print
"disassemble " write
out-file +stdout+ set
[ "gdb" , "-x" , in-file , "-batch" , ] { } make +arguments+ set
] { } make-assoc run-process drop
- out-file file-lines ;
+ out-file ascii file-lines ;
: tabs>spaces ( str -- str' )
{ { CHAR: \t CHAR: \s } } substitute ;
: open-face ( font style -- face )
ttf-name ttf-path
- dup file-contents >byte-array malloc-byte-array
+ dup malloc-file-contents
swap file-length
(open-face) ;
USING: unicode.categories kernel math combinators splitting
sequences math.parser io.files io assocs arrays namespaces
combinators.lib assocs.lib math.ranges unicode.normalize
-unicode.syntax unicode.data compiler.units alien.syntax ;
+unicode.syntax unicode.data compiler.units alien.syntax io.encodings.ascii ;
IN: unicode.breaks
C-ENUM: Any L V T Extend Control CR LF graphemes ;
concat >set ;
: other-extend-lines ( -- lines )
- "extra/unicode/PropList.txt" resource-path file-lines ;
+ "extra/unicode/PropList.txt" resource-path ascii file-lines ;
VALUE: other-extend
USING: assocs math kernel sequences io.files hashtables
quotations splitting arrays math.parser combinators.lib hash2
-byte-arrays words namespaces words compiler.units parser ;
+byte-arrays words namespaces words compiler.units parser io.encodings.ascii ;
IN: unicode.data
<<
! Loading data from UnicodeData.txt
: data ( filename -- data )
- file-lines [ ";" split ] map ;
+ ascii file-lines [ ";" split ] map ;
: load-data ( -- data )
"extra/unicode/UnicodeData.txt" resource-path data ;
USING: calendar html io io.files kernel math math.parser
http.server.responders http.server.templating namespaces parser
sequences strings assocs hashtables debugger http.mime sorting
-html.elements logging ;
+html.elements logging io.encodings.binary ;
IN: webapps.file
[
dupd
file-response
- <file-reader> stdio get stream-copy
+ binary <file-reader> stdio get stream-copy
] serve-file-hook set-global
: serve-static ( filename mime-type -- )
! Copyright (C) 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: io.files namespaces webapps.file http.server.responders
-xmode.code2html kernel html sequences ;
+xmode.code2html kernel html sequences io.encodings.utf8 ;
IN: webapps.source
! This responder is a potential security problem. Make sure you
: source-responder ( path mime-type -- )
drop
serving-html
- [ dup <file-reader> htmlize-stream ] with-html-stream ;
+ [ dup utf8 <file-reader> htmlize-stream ] with-html-stream ;
global [
! Serve up our own source code
USING: io io.streams.string io.files kernel math namespaces
prettyprint sequences arrays generic strings vectors
xml.char-classes xml.data xml.errors xml.tokenize xml.writer
-xml.utilities state-parser assocs ascii ;
+xml.utilities state-parser assocs ascii io.encodings.utf8 ;
IN: xml
! -- Overall parser with data tree
<string-reader> read-xml ;
: file>xml ( filename -- xml )
- <file-reader> read-xml ;
+ ! Autodetect encoding!
+ utf8 <file-reader> read-xml ;
: xml-reprint ( string -- )
string>xml print-xml ;
USING: xmode.loader xmode.utilities xmode.rules namespaces
strings splitting assocs sequences kernel io.files xml memoize
-words globs combinators ;
+words globs combinators io.encodings.utf8 ;
IN: xmode.catalog
TUPLE: mode file file-name-glob first-line-glob ;
: load-catalog ( -- modes )
"extra/xmode/modes/catalog" resource-path
- <file-reader> read-xml parse-modes-tag ;
+ file>xml parse-modes-tag ;
: modes ( -- assoc )
\ modes get-global [
MEMO: (load-mode) ( name -- rule-sets )
modes at mode-file
"extra/xmode/modes/" swap append
- resource-path <file-reader> parse-mode ;
+ resource-path utf8 <file-reader> parse-mode ;
SYMBOL: rule-sets
USING: xmode.tokens xmode.marker xmode.catalog kernel html html.elements io
- io.files sequences words ;
+ io.files sequences words io.encodings.utf8 ;
IN: xmode.code2html
: htmlize-tokens ( tokens -- )
: default-stylesheet ( -- )
<style>
"extra/xmode/code2html/stylesheet.css"
- resource-path file-contents write
+ resource-path utf8 file-contents write
</style> ;
: htmlize-stream ( path stream -- )
</html> ;
: htmlize-file ( path -- )
- dup <file-reader> over ".html" append <file-writer>
+ dup utf8 <file-reader> over ".html" append utf8 <file-writer>
[ htmlize-stream ] with-stream ;
"Official Foo Fighters"
"http://www.foofighters.com/"
"Official site with news, tour dates, discography, store, community, and more."
-} ] [ "extra/yahoo/test-results.xml" resource-path <file-reader> read-xml parse-yahoo first ] unit-test
+} ] [ "extra/yahoo/test-results.xml" resource-path file>xml parse-yahoo first ] unit-test
[ "http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=Factor-search&query=hi&results=1" ] [ "hi" 1 query ] unit-test