From 41fa14010d92dd6b107fc123bab9134e7c3f25f7 Mon Sep 17 00:00:00 2001 From: Aaron Schaefer Date: Sun, 30 Dec 2007 21:29:27 -0500 Subject: [PATCH] Move file-contents word to core/io/io.factor --- core/io/io.factor | 7 +++++-- extra/mad/api/api.factor | 34 +++++++++++++++------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/core/io/io.factor b/core/io/io.factor index 50393f96bb..9c5cf782e7 100755 --- a/core/io/io.factor +++ b/core/io/io.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2003, 2007 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. +USING: hashtables generic kernel math namespaces sequences strings + continuations assocs io.files io.styles sbufs ; IN: io -USING: hashtables generic kernel math namespaces -sequences strings continuations assocs io.styles sbufs ; GENERIC: stream-close ( stream -- ) GENERIC: set-timeout ( n stream -- ) @@ -90,3 +90,6 @@ SYMBOL: stdio : contents ( stream -- str ) 2048 [ stream-copy ] keep >string ; + +: file-contents ( path -- str ) + dup swap file-length [ stream-copy ] keep >string ; diff --git a/extra/mad/api/api.factor b/extra/mad/api/api.factor index e3178b95f9..d803fa64e0 100644 --- a/extra/mad/api/api.factor +++ b/extra/mad/api/api.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2007 Adam Wendt. ! See http://factorcode.org/license.txt for BSD license. -! -USING: alien alien.c-types byte-arrays io io.binary io.files kernel mad namespaces prettyprint sbufs sequences tools.interpreter vars ; +USING: alien alien.c-types byte-arrays io io.binary io.files kernel mad + namespaces prettyprint sbufs sequences tools.interpreter vars ; IN: mad.api VARS: buffer-start buffer-length output-callback-var ; @@ -16,27 +16,27 @@ VARS: buffer-start buffer-length output-callback-var ; { "void*" "mad_header*" } create-mad-callback-generic ; inline : create-filter-callback ( sequence -- alien ) - { "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline + { "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline : create-output-callback ( sequence -- alien ) - { "void*" "mad_header*" "mad_pcm*" } create-mad-callback-generic ; inline + { "void*" "mad_header*" "mad_pcm*" } create-mad-callback-generic ; inline : create-error-callback ( sequence -- alien ) - { "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline + { "void*" "mad_stream*" "mad_frame*" } create-mad-callback-generic ; inline : create-message-callback ( sequence -- alien ) - { "void*" "void*" "uint*" } create-mad-callback-generic ; inline + { "void*" "void*" "uint*" } create-mad-callback-generic ; inline : input ( buffer mad_stream -- mad_flow ) "input" print flush - nip ! mad_stream + nip ! mad_stream buffer-start get ! mad_stream start buffer-length get ! mad_stream start length dup 0 = ! mad-stream start length bool [ 3drop MAD_FLOW_STOP ] ! mad_flow - [ mad_stream_buffer ! - 0 buffer-length set ! - MAD_FLOW_CONTINUE ] if ; ! mad_flow + [ mad_stream_buffer ! + 0 buffer-length set ! + MAD_FLOW_CONTINUE ] if ; ! mad_flow : input-callback ( -- callback ) [ input ] create-input-callback ; @@ -46,11 +46,11 @@ VARS: buffer-start buffer-length output-callback-var ; : filter-callback ( -- callback ) [ "filter" print flush 3drop MAD_FLOW_CONTINUE ] create-filter-callback ; - -: write-sample ( sample -- ) - 4 >le write ; -: output ( data header pcm -- mad_flow ) +: write-sample ( sample -- ) + 4 >le write ; + +: output ( data header pcm -- mad_flow ) "output" . flush -rot 2drop output-callback-var> call [ MAD_FLOW_CONTINUE ] [ MAD_FLOW_STOP ] if ; @@ -80,11 +80,8 @@ VARS: buffer-start buffer-length output-callback-var ; : make-decoder ( -- decoder ) "mad_decoder" malloc-object ; -: file-contents ( path -- string ) - dup swap file-length [ stream-copy ] keep >byte-array ; - : malloc-file-contents ( path -- alien ) - file-contents malloc-byte-array ; + file-contents >byte-array malloc-byte-array ; : mad-run ( -- int ) make-decoder [ mad-init ] keep MAD_DECODER_MODE_SYNC mad_decoder_run ; @@ -98,4 +95,3 @@ VARS: buffer-start buffer-length output-callback-var ; : mad-test ( -- results ) [ output-stdout ] >output-callback-var "/home/adam/download/mp3/Misc/wutbf.mp3" decode-mp3 ; -