Split up core-foundation vocabulary since it was getting out of hand
parent
c6529dec56
commit
46a1089fd8
|
@ -0,0 +1,11 @@
|
|||
USING: help.syntax help.markup arrays alien ;
|
||||
IN: core-foundation.arrays
|
||||
|
||||
HELP: CF>array
|
||||
{ $values { "alien" "a " { $snippet "CFArray" } } { "array" "an array of " { $link alien } " instances" } }
|
||||
{ $description "Creates a Factor array from a Core Foundation array." } ;
|
||||
|
||||
HELP: <CFArray>
|
||||
{ $values { "seq" "a sequence of " { $link alien } " instances" } { "alien" "a " { $snippet "CFArray" } } }
|
||||
{ $description "Creates a Core Foundation array from a Factor array." } ;
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.syntax kernel sequences ;
|
||||
IN: core-foundation.arrays
|
||||
|
||||
TYPEDEF: void* CFArrayRef
|
||||
|
||||
FUNCTION: CFArrayRef CFArrayCreateMutable ( CFAllocatorRef allocator, CFIndex capacity, void* callbacks ) ;
|
||||
|
||||
FUNCTION: void* CFArrayGetValueAtIndex ( CFArrayRef array, CFIndex idx ) ;
|
||||
|
||||
FUNCTION: void CFArraySetValueAtIndex ( CFArrayRef array, CFIndex index, void* value ) ;
|
||||
|
||||
FUNCTION: CFIndex CFArrayGetCount ( CFArrayRef array ) ;
|
||||
|
||||
: CF>array ( alien -- array )
|
||||
dup CFArrayGetCount [ CFArrayGetValueAtIndex ] with map ;
|
||||
|
||||
: <CFArray> ( seq -- alien )
|
||||
[ f swap length f CFArrayCreateMutable ] keep
|
||||
[ length ] keep
|
||||
[ [ dupd ] dip CFArraySetValueAtIndex ] 2each ;
|
|
@ -0,0 +1,2 @@
|
|||
unportable
|
||||
bindings
|
|
@ -0,0 +1,11 @@
|
|||
USING: help.syntax help.markup ;
|
||||
IN: core-foundation.bundles
|
||||
|
||||
HELP: <CFBundle>
|
||||
{ $values { "string" "a pathname string" } { "bundle" "a " { $snippet "CFBundle" } } }
|
||||
{ $description "Creates a new " { $snippet "CFBundle" } "." } ;
|
||||
|
||||
HELP: load-framework
|
||||
{ $values { "name" "a pathname string" } }
|
||||
{ $description "Loads a Core Foundation framework." } ;
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.syntax kernel sequences core-foundation
|
||||
core-foundation.urls ;
|
||||
IN: core-foundation.bundles
|
||||
|
||||
TYPEDEF: void* CFBundleRef
|
||||
|
||||
FUNCTION: CFBundleRef CFBundleCreate ( CFAllocatorRef allocator, CFURLRef bundleURL ) ;
|
||||
|
||||
FUNCTION: Boolean CFBundleLoadExecutable ( CFBundleRef bundle ) ;
|
||||
|
||||
: <CFBundle> ( string -- bundle )
|
||||
t <CFFileSystemURL> [
|
||||
f swap CFBundleCreate
|
||||
] keep CFRelease ;
|
||||
|
||||
: load-framework ( name -- )
|
||||
dup <CFBundle> [
|
||||
CFBundleLoadExecutable drop
|
||||
] [
|
||||
"Cannot load bundle named " prepend throw
|
||||
] ?if ;
|
|
@ -0,0 +1,2 @@
|
|||
unportable
|
||||
bindings
|
|
@ -1,42 +1,6 @@
|
|||
USING: alien strings arrays help.markup help.syntax destructors ;
|
||||
IN: core-foundation
|
||||
|
||||
HELP: CF>array
|
||||
{ $values { "alien" "a " { $snippet "CFArray" } } { "array" "an array of " { $link alien } " instances" } }
|
||||
{ $description "Creates a Factor array from a Core Foundation array." } ;
|
||||
|
||||
HELP: <CFArray>
|
||||
{ $values { "seq" "a sequence of " { $link alien } " instances" } { "alien" "a " { $snippet "CFArray" } } }
|
||||
{ $description "Creates a Core Foundation array from a Factor array." } ;
|
||||
|
||||
HELP: <CFString>
|
||||
{ $values { "string" string } { "alien" "a " { $snippet "CFString" } } }
|
||||
{ $description "Creates a Core Foundation string from a Factor string." } ;
|
||||
|
||||
HELP: CF>string
|
||||
{ $values { "alien" "a " { $snippet "CFString" } } { "string" string } }
|
||||
{ $description "Creates a Factor string from a Core Foundation string." } ;
|
||||
|
||||
HELP: CF>string-array
|
||||
{ $values { "alien" "a " { $snippet "CFArray" } " of " { $snippet "CFString" } " instances" } { "seq" string } }
|
||||
{ $description "Creates an array of Factor strings from a " { $snippet "CFArray" } " of " { $snippet "CFString" } "s." } ;
|
||||
|
||||
HELP: <CFFileSystemURL>
|
||||
{ $values { "string" "a pathname string" } { "dir?" "a boolean indicating if the pathname is a directory" } { "url" "a " { $snippet "CFURL" } } }
|
||||
{ $description "Creates a new " { $snippet "CFURL" } " pointing to the given local pathname." } ;
|
||||
|
||||
HELP: <CFURL>
|
||||
{ $values { "string" "a URL string" } { "url" "a " { $snippet "CFURL" } } }
|
||||
{ $description "Creates a new " { $snippet "CFURL" } "." } ;
|
||||
|
||||
HELP: <CFBundle>
|
||||
{ $values { "string" "a pathname string" } { "bundle" "a " { $snippet "CFBundle" } } }
|
||||
{ $description "Creates a new " { $snippet "CFBundle" } "." } ;
|
||||
|
||||
HELP: load-framework
|
||||
{ $values { "name" "a pathname string" } }
|
||||
{ $description "Loads a Core Foundation framework." } ;
|
||||
|
||||
HELP: &CFRelease
|
||||
{ $values { "alien" "Pointer to a Core Foundation object" } }
|
||||
{ $description "Marks the given Core Foundation object for unconditional release via " { $link CFRelease } " at the end of the enclosing " { $link with-destructors } " scope." } ;
|
||||
|
@ -46,24 +10,3 @@ HELP: |CFRelease
|
|||
{ $description "Marks the given Core Foundation object for release via " { $link CFRelease } " in the event of an error at the end of the enclosing " { $link with-destructors } " scope." } ;
|
||||
|
||||
{ CFRelease |CFRelease &CFRelease } related-words
|
||||
|
||||
ARTICLE: "core-foundation" "Core foundation utilities"
|
||||
"The " { $vocab-link "core-foundation" } " vocabulary defines bindings for some frequently-used Core Foundation functions. It also provides some utility words."
|
||||
$nl
|
||||
"Strings:"
|
||||
{ $subsection <CFString> }
|
||||
{ $subsection CF>string }
|
||||
"Arrays:"
|
||||
{ $subsection <CFArray> }
|
||||
{ $subsection CF>array }
|
||||
{ $subsection CF>string-array }
|
||||
"URLs:"
|
||||
{ $subsection <CFFileSystemURL> }
|
||||
{ $subsection <CFURL> }
|
||||
"Frameworks:"
|
||||
{ $subsection load-framework }
|
||||
"Memory management:"
|
||||
{ $subsection &CFRelease }
|
||||
{ $subsection |CFRelease } ;
|
||||
|
||||
ABOUT: "core-foundation"
|
||||
|
|
|
@ -1,23 +1,13 @@
|
|||
! Copyright (C) 2006, 2008 Slava Pestov
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien alien.c-types alien.strings alien.syntax kernel
|
||||
math math.bitwise sequences io.encodings.utf8 destructors
|
||||
accessors combinators byte-arrays ;
|
||||
USING: alien.syntax destructors accessors kernel ;
|
||||
IN: core-foundation
|
||||
|
||||
TYPEDEF: void* CFAllocatorRef
|
||||
TYPEDEF: void* CFArrayRef
|
||||
TYPEDEF: void* CFDataRef
|
||||
TYPEDEF: void* CFDictionaryRef
|
||||
TYPEDEF: void* CFMutableDictionaryRef
|
||||
TYPEDEF: void* CFNumberRef
|
||||
TYPEDEF: void* CFBundleRef
|
||||
TYPEDEF: void* CFSetRef
|
||||
TYPEDEF: void* CFStringRef
|
||||
TYPEDEF: void* CFURLRef
|
||||
TYPEDEF: void* CFUUIDRef
|
||||
TYPEDEF: void* CFTypeRef
|
||||
TYPEDEF: void* CFFileDescriptorRef
|
||||
|
||||
TYPEDEF: void* CFAllocatorRef
|
||||
: kCFAllocatorDefault f ; inline
|
||||
|
||||
TYPEDEF: bool Boolean
|
||||
TYPEDEF: long CFIndex
|
||||
TYPEDEF: int SInt32
|
||||
|
@ -26,198 +16,11 @@ TYPEDEF: ulong CFTypeID
|
|||
TYPEDEF: UInt32 CFOptionFlags
|
||||
TYPEDEF: double CFTimeInterval
|
||||
TYPEDEF: double CFAbsoluteTime
|
||||
TYPEDEF: int CFFileDescriptorNativeDescriptor
|
||||
TYPEDEF: void* CFFileDescriptorCallBack
|
||||
|
||||
TYPEDEF: int CFNumberType
|
||||
: kCFNumberSInt8Type 1 ; inline
|
||||
: kCFNumberSInt16Type 2 ; inline
|
||||
: kCFNumberSInt32Type 3 ; inline
|
||||
: kCFNumberSInt64Type 4 ; inline
|
||||
: kCFNumberFloat32Type 5 ; inline
|
||||
: kCFNumberFloat64Type 6 ; inline
|
||||
: kCFNumberCharType 7 ; inline
|
||||
: kCFNumberShortType 8 ; inline
|
||||
: kCFNumberIntType 9 ; inline
|
||||
: kCFNumberLongType 10 ; inline
|
||||
: kCFNumberLongLongType 11 ; inline
|
||||
: kCFNumberFloatType 12 ; inline
|
||||
: kCFNumberDoubleType 13 ; inline
|
||||
: kCFNumberCFIndexType 14 ; inline
|
||||
: kCFNumberNSIntegerType 15 ; inline
|
||||
: kCFNumberCGFloatType 16 ; inline
|
||||
: kCFNumberMaxType 16 ; inline
|
||||
|
||||
TYPEDEF: int CFPropertyListMutabilityOptions
|
||||
: kCFPropertyListImmutable 0 ; inline
|
||||
: kCFPropertyListMutableContainers 1 ; inline
|
||||
: kCFPropertyListMutableContainersAndLeaves 2 ; inline
|
||||
|
||||
FUNCTION: CFArrayRef CFArrayCreateMutable ( CFAllocatorRef allocator, CFIndex capacity, void* callbacks ) ;
|
||||
|
||||
FUNCTION: void* CFArrayGetValueAtIndex ( CFArrayRef array, CFIndex idx ) ;
|
||||
|
||||
FUNCTION: void CFArraySetValueAtIndex ( CFArrayRef array, CFIndex index, void* value ) ;
|
||||
|
||||
FUNCTION: CFIndex CFArrayGetCount ( CFArrayRef array ) ;
|
||||
|
||||
: kCFURLPOSIXPathStyle 0 ; inline
|
||||
: kCFAllocatorDefault f ; inline
|
||||
|
||||
FUNCTION: CFURLRef CFURLCreateWithFileSystemPath ( CFAllocatorRef allocator, CFStringRef filePath, int pathStyle, Boolean isDirectory ) ;
|
||||
|
||||
FUNCTION: CFURLRef CFURLCreateWithString ( CFAllocatorRef allocator, CFStringRef string, CFURLRef base ) ;
|
||||
|
||||
FUNCTION: CFURLRef CFURLCopyFileSystemPath ( CFURLRef url, int pathStyle ) ;
|
||||
|
||||
TYPEDEF: int CFStringEncoding
|
||||
: kCFStringEncodingMacRoman HEX: 0 ;
|
||||
: kCFStringEncodingWindowsLatin1 HEX: 0500 ;
|
||||
: kCFStringEncodingISOLatin1 HEX: 0201 ;
|
||||
: kCFStringEncodingNextStepLatin HEX: 0B01 ;
|
||||
: kCFStringEncodingASCII HEX: 0600 ;
|
||||
: kCFStringEncodingUnicode HEX: 0100 ;
|
||||
: kCFStringEncodingUTF8 HEX: 08000100 ;
|
||||
: kCFStringEncodingNonLossyASCII HEX: 0BFF ;
|
||||
: kCFStringEncodingUTF16 HEX: 0100 ;
|
||||
: kCFStringEncodingUTF16BE HEX: 10000100 ;
|
||||
: kCFStringEncodingUTF16LE HEX: 14000100 ;
|
||||
: kCFStringEncodingUTF32 HEX: 0c000100 ;
|
||||
: kCFStringEncodingUTF32BE HEX: 18000100 ;
|
||||
: kCFStringEncodingUTF32LE HEX: 1c000100 ;
|
||||
|
||||
FUNCTION: CFStringRef CFStringCreateFromExternalRepresentation (
|
||||
CFAllocatorRef alloc,
|
||||
CFDataRef data,
|
||||
CFStringEncoding encoding
|
||||
) ;
|
||||
|
||||
FUNCTION: CFStringRef CFStringCreateWithBytes (
|
||||
CFAllocatorRef alloc,
|
||||
UInt8* bytes,
|
||||
CFIndex numBytes,
|
||||
CFStringEncoding encoding,
|
||||
Boolean isExternalRepresentation
|
||||
) ;
|
||||
|
||||
FUNCTION: CFIndex CFStringGetLength ( CFStringRef theString ) ;
|
||||
|
||||
FUNCTION: void CFStringGetCharacters ( void* theString, CFIndex start, CFIndex length, void* buffer ) ;
|
||||
|
||||
FUNCTION: Boolean CFStringGetCString (
|
||||
CFStringRef theString,
|
||||
char* buffer,
|
||||
CFIndex bufferSize,
|
||||
CFStringEncoding encoding
|
||||
) ;
|
||||
|
||||
FUNCTION: CFStringRef CFStringCreateWithCString (
|
||||
CFAllocatorRef alloc,
|
||||
char* cStr,
|
||||
CFStringEncoding encoding
|
||||
) ;
|
||||
|
||||
FUNCTION: CFNumberRef CFNumberCreate ( CFAllocatorRef allocator, CFNumberType theType, void* valuePtr ) ;
|
||||
|
||||
FUNCTION: CFDataRef CFDataCreate ( CFAllocatorRef allocator, uchar* bytes, CFIndex length ) ;
|
||||
|
||||
FUNCTION: CFBundleRef CFBundleCreate ( CFAllocatorRef allocator, CFURLRef bundleURL ) ;
|
||||
|
||||
FUNCTION: Boolean CFBundleLoadExecutable ( CFBundleRef bundle ) ;
|
||||
|
||||
FUNCTION: CFTypeRef CFRetain ( CFTypeRef cf ) ;
|
||||
|
||||
FUNCTION: void CFRelease ( CFTypeRef cf ) ;
|
||||
|
||||
FUNCTION: CFTypeID CFGetTypeID ( CFTypeRef cf ) ;
|
||||
|
||||
: CF>array ( alien -- array )
|
||||
dup CFArrayGetCount [ CFArrayGetValueAtIndex ] with map ;
|
||||
|
||||
: <CFArray> ( seq -- alien )
|
||||
[ f swap length f CFArrayCreateMutable ] keep
|
||||
[ length ] keep
|
||||
[ [ dupd ] dip CFArraySetValueAtIndex ] 2each ;
|
||||
|
||||
: <CFString> ( string -- alien )
|
||||
f swap utf8 string>alien kCFStringEncodingUTF8 CFStringCreateWithCString
|
||||
[ "CFStringCreateWithCString failed" throw ] unless* ;
|
||||
|
||||
: CF>string ( alien -- string )
|
||||
dup CFStringGetLength 4 * 1 + <byte-array> [
|
||||
dup length
|
||||
kCFStringEncodingUTF8
|
||||
CFStringGetCString
|
||||
[ "CFStringGetCString failed" throw ] unless
|
||||
] keep utf8 alien>string ;
|
||||
|
||||
: CF>string-array ( alien -- seq )
|
||||
CF>array [ CF>string ] map ;
|
||||
|
||||
: <CFStringArray> ( seq -- alien )
|
||||
[ <CFString> ] map [ <CFArray> ] [ [ CFRelease ] each ] bi ;
|
||||
|
||||
: <CFFileSystemURL> ( string dir? -- url )
|
||||
[ <CFString> f over kCFURLPOSIXPathStyle ] dip
|
||||
CFURLCreateWithFileSystemPath swap CFRelease ;
|
||||
|
||||
: <CFURL> ( string -- url )
|
||||
<CFString>
|
||||
[ f swap f CFURLCreateWithString ] keep
|
||||
CFRelease ;
|
||||
|
||||
: <CFBundle> ( string -- bundle )
|
||||
t <CFFileSystemURL> [
|
||||
f swap CFBundleCreate
|
||||
] keep CFRelease ;
|
||||
|
||||
GENERIC: <CFNumber> ( number -- alien )
|
||||
|
||||
M: integer <CFNumber>
|
||||
[ f kCFNumberLongLongType ] dip <longlong> CFNumberCreate ;
|
||||
|
||||
M: float <CFNumber>
|
||||
[ f kCFNumberDoubleType ] dip <double> CFNumberCreate ;
|
||||
|
||||
M: t <CFNumber>
|
||||
drop f kCFNumberIntType 1 <int> CFNumberCreate ;
|
||||
|
||||
M: f <CFNumber>
|
||||
drop f kCFNumberIntType 0 <int> CFNumberCreate ;
|
||||
|
||||
: <CFData> ( byte-array -- alien )
|
||||
[ f ] dip dup length CFDataCreate ;
|
||||
|
||||
FUNCTION: CFFileDescriptorRef CFFileDescriptorCreate (
|
||||
CFAllocatorRef allocator,
|
||||
CFFileDescriptorNativeDescriptor fd,
|
||||
Boolean closeOnInvalidate,
|
||||
CFFileDescriptorCallBack callout,
|
||||
CFFileDescriptorContext* context
|
||||
) ;
|
||||
|
||||
: kCFFileDescriptorReadCallBack 1 ; inline
|
||||
: kCFFileDescriptorWriteCallBack 2 ; inline
|
||||
|
||||
FUNCTION: void CFFileDescriptorEnableCallBacks (
|
||||
CFFileDescriptorRef f,
|
||||
CFOptionFlags callBackTypes
|
||||
) ;
|
||||
|
||||
: enable-all-callbacks ( fd -- )
|
||||
{ kCFFileDescriptorReadCallBack kCFFileDescriptorWriteCallBack } flags
|
||||
CFFileDescriptorEnableCallBacks ;
|
||||
|
||||
: <CFFileDescriptor> ( fd callback -- handle )
|
||||
[ f swap ] [ t swap ] bi* f CFFileDescriptorCreate
|
||||
[ "CFFileDescriptorCreate failed" throw ] unless* ;
|
||||
|
||||
: load-framework ( name -- )
|
||||
dup <CFBundle> [
|
||||
CFBundleLoadExecutable drop
|
||||
] [
|
||||
"Cannot load bundle named " prepend throw
|
||||
] ?if ;
|
||||
|
||||
TUPLE: CFRelease-destructor alien disposed ;
|
||||
|
||||
M: CFRelease-destructor dispose* alien>> CFRelease ;
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
! Copyright (C) 2008 Joe Groff.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.syntax alien.c-types sequences kernel math ;
|
||||
IN: core-foundation.data
|
||||
|
||||
TYPEDEF: void* CFDataRef
|
||||
TYPEDEF: void* CFDictionaryRef
|
||||
TYPEDEF: void* CFMutableDictionaryRef
|
||||
TYPEDEF: void* CFNumberRef
|
||||
TYPEDEF: void* CFSetRef
|
||||
TYPEDEF: void* CFUUIDRef
|
||||
|
||||
TYPEDEF: int CFNumberType
|
||||
: kCFNumberSInt8Type 1 ; inline
|
||||
: kCFNumberSInt16Type 2 ; inline
|
||||
: kCFNumberSInt32Type 3 ; inline
|
||||
: kCFNumberSInt64Type 4 ; inline
|
||||
: kCFNumberFloat32Type 5 ; inline
|
||||
: kCFNumberFloat64Type 6 ; inline
|
||||
: kCFNumberCharType 7 ; inline
|
||||
: kCFNumberShortType 8 ; inline
|
||||
: kCFNumberIntType 9 ; inline
|
||||
: kCFNumberLongType 10 ; inline
|
||||
: kCFNumberLongLongType 11 ; inline
|
||||
: kCFNumberFloatType 12 ; inline
|
||||
: kCFNumberDoubleType 13 ; inline
|
||||
: kCFNumberCFIndexType 14 ; inline
|
||||
: kCFNumberNSIntegerType 15 ; inline
|
||||
: kCFNumberCGFloatType 16 ; inline
|
||||
: kCFNumberMaxType 16 ; inline
|
||||
|
||||
TYPEDEF: int CFPropertyListMutabilityOptions
|
||||
: kCFPropertyListImmutable 0 ; inline
|
||||
: kCFPropertyListMutableContainers 1 ; inline
|
||||
: kCFPropertyListMutableContainersAndLeaves 2 ; inline
|
||||
|
||||
FUNCTION: CFNumberRef CFNumberCreate ( CFAllocatorRef allocator, CFNumberType theType, void* valuePtr ) ;
|
||||
|
||||
FUNCTION: CFDataRef CFDataCreate ( CFAllocatorRef allocator, uchar* bytes, CFIndex length ) ;
|
||||
|
||||
FUNCTION: CFTypeID CFGetTypeID ( CFTypeRef cf ) ;
|
||||
|
||||
GENERIC: <CFNumber> ( number -- alien )
|
||||
|
||||
M: integer <CFNumber>
|
||||
[ f kCFNumberLongLongType ] dip <longlong> CFNumberCreate ;
|
||||
|
||||
M: float <CFNumber>
|
||||
[ f kCFNumberDoubleType ] dip <double> CFNumberCreate ;
|
||||
|
||||
M: t <CFNumber>
|
||||
drop f kCFNumberIntType 1 <int> CFNumberCreate ;
|
||||
|
||||
M: f <CFNumber>
|
||||
drop f kCFNumberIntType 0 <int> CFNumberCreate ;
|
||||
|
||||
: <CFData> ( byte-array -- alien )
|
||||
[ f ] dip dup length CFDataCreate ;
|
|
@ -0,0 +1,2 @@
|
|||
unportable
|
||||
bindings
|
|
@ -0,0 +1,32 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.syntax kernel math.bitwise core-foundation ;
|
||||
IN: core-foundation.file-descriptors
|
||||
|
||||
TYPEDEF: void* CFFileDescriptorRef
|
||||
TYPEDEF: int CFFileDescriptorNativeDescriptor
|
||||
TYPEDEF: void* CFFileDescriptorCallBack
|
||||
|
||||
FUNCTION: CFFileDescriptorRef CFFileDescriptorCreate (
|
||||
CFAllocatorRef allocator,
|
||||
CFFileDescriptorNativeDescriptor fd,
|
||||
Boolean closeOnInvalidate,
|
||||
CFFileDescriptorCallBack callout,
|
||||
CFFileDescriptorContext* context
|
||||
) ;
|
||||
|
||||
: kCFFileDescriptorReadCallBack 1 ; inline
|
||||
: kCFFileDescriptorWriteCallBack 2 ; inline
|
||||
|
||||
FUNCTION: void CFFileDescriptorEnableCallBacks (
|
||||
CFFileDescriptorRef f,
|
||||
CFOptionFlags callBackTypes
|
||||
) ;
|
||||
|
||||
: enable-all-callbacks ( fd -- )
|
||||
{ kCFFileDescriptorReadCallBack kCFFileDescriptorWriteCallBack } flags
|
||||
CFFileDescriptorEnableCallBacks ;
|
||||
|
||||
: <CFFileDescriptor> ( fd callback -- handle )
|
||||
[ f swap ] [ t swap ] bi* f CFFileDescriptorCreate
|
||||
[ "CFFileDescriptorCreate failed" throw ] unless* ;
|
|
@ -0,0 +1,2 @@
|
|||
unportable
|
||||
bindings
|
|
@ -2,11 +2,10 @@
|
|||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien alien.c-types alien.strings alien.syntax kernel
|
||||
math sequences namespaces make assocs init accessors
|
||||
continuations combinators core-foundation
|
||||
core-foundation.run-loop io.encodings.utf8 destructors locals
|
||||
continuations combinators io.encodings.utf8 destructors locals
|
||||
arrays specialized-arrays.direct.alien
|
||||
specialized-arrays.direct.int specialized-arrays.direct.longlong
|
||||
;
|
||||
core-foundation core-foundation.run-loop core-foundation.strings ;
|
||||
IN: core-foundation.fsevents
|
||||
|
||||
: kFSEventStreamCreateFlagUseCFTypes 2 ; inline
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
! Copyright (C) 2008 Slava Pestov
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien alien.syntax core-foundation kernel namespaces ;
|
||||
USING: alien alien.syntax kernel namespaces
|
||||
core-foundation core-foundation.strings
|
||||
core-foundation.file-descriptors ;
|
||||
IN: core-foundation.run-loop
|
||||
|
||||
: kCFRunLoopRunFinished 1 ; inline
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
USING: help.syntax help.markup strings ;
|
||||
IN: core-foundation.strings
|
||||
|
||||
HELP: <CFString>
|
||||
{ $values { "string" string } { "alien" "a " { $snippet "CFString" } } }
|
||||
{ $description "Creates a Core Foundation string from a Factor string." } ;
|
||||
|
||||
HELP: CF>string
|
||||
{ $values { "alien" "a " { $snippet "CFString" } } { "string" string } }
|
||||
{ $description "Creates a Factor string from a Core Foundation string." } ;
|
||||
|
||||
HELP: CF>string-array
|
||||
{ $values { "alien" "a " { $snippet "CFArray" } " of " { $snippet "CFString" } " instances" } { "seq" string } }
|
||||
{ $description "Creates an array of Factor strings from a " { $snippet "CFArray" } " of " { $snippet "CFString" } "s." } ;
|
|
@ -0,0 +1,9 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: core-foundation.strings core-foundation tools.test kernel ;
|
||||
IN: core-foundation
|
||||
|
||||
[ ] [ "Hello" <CFString> CFRelease ] unit-test
|
||||
[ "Hello" ] [ "Hello" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
|
||||
[ "Hello\u003456" ] [ "Hello\u003456" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
|
||||
[ "Hello\u013456" ] [ "Hello\u013456" <CFString> [ CF>string ] [ CFRelease ] bi ] unit-test
|
|
@ -0,0 +1,66 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.syntax alien.strings kernel sequences byte-arrays
|
||||
io.encodings.utf8 math core-foundation core-foundation.arrays ;
|
||||
IN: core-foundation.strings
|
||||
|
||||
TYPEDEF: void* CFStringRef
|
||||
|
||||
TYPEDEF: int CFStringEncoding
|
||||
: kCFStringEncodingMacRoman HEX: 0 ;
|
||||
: kCFStringEncodingWindowsLatin1 HEX: 0500 ;
|
||||
: kCFStringEncodingISOLatin1 HEX: 0201 ;
|
||||
: kCFStringEncodingNextStepLatin HEX: 0B01 ;
|
||||
: kCFStringEncodingASCII HEX: 0600 ;
|
||||
: kCFStringEncodingUnicode HEX: 0100 ;
|
||||
: kCFStringEncodingUTF8 HEX: 08000100 ;
|
||||
: kCFStringEncodingNonLossyASCII HEX: 0BFF ;
|
||||
: kCFStringEncodingUTF16 HEX: 0100 ;
|
||||
: kCFStringEncodingUTF16BE HEX: 10000100 ;
|
||||
: kCFStringEncodingUTF16LE HEX: 14000100 ;
|
||||
: kCFStringEncodingUTF32 HEX: 0c000100 ;
|
||||
: kCFStringEncodingUTF32BE HEX: 18000100 ;
|
||||
: kCFStringEncodingUTF32LE HEX: 1c000100 ;
|
||||
|
||||
FUNCTION: CFStringRef CFStringCreateWithBytes (
|
||||
CFAllocatorRef alloc,
|
||||
UInt8* bytes,
|
||||
CFIndex numBytes,
|
||||
CFStringEncoding encoding,
|
||||
Boolean isExternalRepresentation
|
||||
) ;
|
||||
|
||||
FUNCTION: CFIndex CFStringGetLength ( CFStringRef theString ) ;
|
||||
|
||||
FUNCTION: void CFStringGetCharacters ( void* theString, CFIndex start, CFIndex length, void* buffer ) ;
|
||||
|
||||
FUNCTION: Boolean CFStringGetCString (
|
||||
CFStringRef theString,
|
||||
char* buffer,
|
||||
CFIndex bufferSize,
|
||||
CFStringEncoding encoding
|
||||
) ;
|
||||
|
||||
FUNCTION: CFStringRef CFStringCreateWithCString (
|
||||
CFAllocatorRef alloc,
|
||||
char* cStr,
|
||||
CFStringEncoding encoding
|
||||
) ;
|
||||
|
||||
: <CFString> ( string -- alien )
|
||||
f swap utf8 string>alien kCFStringEncodingUTF8 CFStringCreateWithCString
|
||||
[ "CFStringCreateWithCString failed" throw ] unless* ;
|
||||
|
||||
: CF>string ( alien -- string )
|
||||
dup CFStringGetLength 4 * 1 + <byte-array> [
|
||||
dup length
|
||||
kCFStringEncodingUTF8
|
||||
CFStringGetCString
|
||||
[ "CFStringGetCString failed" throw ] unless
|
||||
] keep utf8 alien>string ;
|
||||
|
||||
: CF>string-array ( alien -- seq )
|
||||
CF>array [ CF>string ] map ;
|
||||
|
||||
: <CFStringArray> ( seq -- alien )
|
||||
[ <CFString> ] map [ <CFArray> ] [ [ CFRelease ] each ] bi ;
|
|
@ -0,0 +1,2 @@
|
|||
unportable
|
||||
bindings
|
|
@ -0,0 +1,2 @@
|
|||
unportable
|
||||
bindings
|
|
@ -0,0 +1,10 @@
|
|||
USING: help.syntax help.markup ;
|
||||
IN: core-foundation.urls
|
||||
|
||||
HELP: <CFFileSystemURL>
|
||||
{ $values { "string" "a pathname string" } { "dir?" "a boolean indicating if the pathname is a directory" } { "url" "a " { $snippet "CFURL" } } }
|
||||
{ $description "Creates a new " { $snippet "CFURL" } " pointing to the given local pathname." } ;
|
||||
|
||||
HELP: <CFURL>
|
||||
{ $values { "string" "a URL string" } { "url" "a " { $snippet "CFURL" } } }
|
||||
{ $description "Creates a new " { $snippet "CFURL" } "." } ;
|
|
@ -0,0 +1,24 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: alien.syntax kernel core-foundation.strings
|
||||
core-foundation ;
|
||||
IN: core-foundation.urls
|
||||
|
||||
: kCFURLPOSIXPathStyle 0 ; inline
|
||||
|
||||
TYPEDEF: void* CFURLRef
|
||||
|
||||
FUNCTION: CFURLRef CFURLCreateWithFileSystemPath ( CFAllocatorRef allocator, CFStringRef filePath, int pathStyle, Boolean isDirectory ) ;
|
||||
|
||||
FUNCTION: CFURLRef CFURLCreateWithString ( CFAllocatorRef allocator, CFStringRef string, CFURLRef base ) ;
|
||||
|
||||
FUNCTION: CFURLRef CFURLCopyFileSystemPath ( CFURLRef url, int pathStyle ) ;
|
||||
|
||||
: <CFFileSystemURL> ( string dir? -- url )
|
||||
[ <CFString> f over kCFURLPOSIXPathStyle ] dip
|
||||
CFURLCreateWithFileSystemPath swap CFRelease ;
|
||||
|
||||
: <CFURL> ( string -- url )
|
||||
<CFString>
|
||||
[ f swap f CFURLCreateWithString ] keep
|
||||
CFRelease ;
|
|
@ -1,8 +1,9 @@
|
|||
! Copyright (C) 2008 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: kernel namespaces math accessors threads alien locals
|
||||
destructors combinators core-foundation core-foundation.run-loop
|
||||
io.unix.multiplexers io.unix.multiplexers.kqueue ;
|
||||
destructors combinators io.unix.multiplexers
|
||||
io.unix.multiplexers.kqueue core-foundation
|
||||
core-foundation.run-loop core-foundation.file-descriptors ;
|
||||
IN: io.unix.multiplexers.run-loop
|
||||
|
||||
TUPLE: run-loop-mx kqueue-mx fd source ;
|
||||
|
|
Loading…
Reference in New Issue