diff --git a/basis/core-foundation/arrays/arrays-docs.factor b/basis/core-foundation/arrays/arrays-docs.factor new file mode 100644 index 0000000000..36d14a8660 --- /dev/null +++ b/basis/core-foundation/arrays/arrays-docs.factor @@ -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: +{ $values { "seq" "a sequence of " { $link alien } " instances" } { "alien" "a " { $snippet "CFArray" } } } +{ $description "Creates a Core Foundation array from a Factor array." } ; + diff --git a/basis/core-foundation/arrays/arrays.factor b/basis/core-foundation/arrays/arrays.factor new file mode 100644 index 0000000000..3708059f2b --- /dev/null +++ b/basis/core-foundation/arrays/arrays.factor @@ -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 ; + +: ( seq -- alien ) + [ f swap length f CFArrayCreateMutable ] keep + [ length ] keep + [ [ dupd ] dip CFArraySetValueAtIndex ] 2each ; diff --git a/basis/core-foundation/arrays/tags.txt b/basis/core-foundation/arrays/tags.txt new file mode 100644 index 0000000000..2320bdd648 --- /dev/null +++ b/basis/core-foundation/arrays/tags.txt @@ -0,0 +1,2 @@ +unportable +bindings diff --git a/basis/core-foundation/bundles/bundles-docs.factor b/basis/core-foundation/bundles/bundles-docs.factor new file mode 100644 index 0000000000..baa1b4d5df --- /dev/null +++ b/basis/core-foundation/bundles/bundles-docs.factor @@ -0,0 +1,11 @@ +USING: help.syntax help.markup ; +IN: core-foundation.bundles + +HELP: +{ $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." } ; + diff --git a/basis/core-foundation/bundles/bundles.factor b/basis/core-foundation/bundles/bundles.factor new file mode 100644 index 0000000000..790f1766c3 --- /dev/null +++ b/basis/core-foundation/bundles/bundles.factor @@ -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 ) ; + +: ( string -- bundle ) + t [ + f swap CFBundleCreate + ] keep CFRelease ; + +: load-framework ( name -- ) + dup [ + CFBundleLoadExecutable drop + ] [ + "Cannot load bundle named " prepend throw + ] ?if ; diff --git a/basis/core-foundation/bundles/tags.txt b/basis/core-foundation/bundles/tags.txt new file mode 100644 index 0000000000..2320bdd648 --- /dev/null +++ b/basis/core-foundation/bundles/tags.txt @@ -0,0 +1,2 @@ +unportable +bindings diff --git a/basis/core-foundation/core-foundation-docs.factor b/basis/core-foundation/core-foundation-docs.factor index d577c523cf..c1783cb92b 100644 --- a/basis/core-foundation/core-foundation-docs.factor +++ b/basis/core-foundation/core-foundation-docs.factor @@ -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: -{ $values { "seq" "a sequence of " { $link alien } " instances" } { "alien" "a " { $snippet "CFArray" } } } -{ $description "Creates a Core Foundation array from a Factor array." } ; - -HELP: -{ $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: -{ $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: -{ $values { "string" "a URL string" } { "url" "a " { $snippet "CFURL" } } } -{ $description "Creates a new " { $snippet "CFURL" } "." } ; - -HELP: -{ $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 } -{ $subsection CF>string } -"Arrays:" -{ $subsection } -{ $subsection CF>array } -{ $subsection CF>string-array } -"URLs:" -{ $subsection } -{ $subsection } -"Frameworks:" -{ $subsection load-framework } -"Memory management:" -{ $subsection &CFRelease } -{ $subsection |CFRelease } ; - -ABOUT: "core-foundation" diff --git a/basis/core-foundation/core-foundation.factor b/basis/core-foundation/core-foundation.factor index 40dd4710a1..0f64c0666f 100644 --- a/basis/core-foundation/core-foundation.factor +++ b/basis/core-foundation/core-foundation.factor @@ -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 ; - -: ( seq -- alien ) - [ f swap length f CFArrayCreateMutable ] keep - [ length ] keep - [ [ dupd ] dip CFArraySetValueAtIndex ] 2each ; - -: ( string -- alien ) - f swap utf8 string>alien kCFStringEncodingUTF8 CFStringCreateWithCString - [ "CFStringCreateWithCString failed" throw ] unless* ; - -: CF>string ( alien -- string ) - dup CFStringGetLength 4 * 1 + [ - dup length - kCFStringEncodingUTF8 - CFStringGetCString - [ "CFStringGetCString failed" throw ] unless - ] keep utf8 alien>string ; - -: CF>string-array ( alien -- seq ) - CF>array [ CF>string ] map ; - -: ( seq -- alien ) - [ ] map [ ] [ [ CFRelease ] each ] bi ; - -: ( string dir? -- url ) - [ f over kCFURLPOSIXPathStyle ] dip - CFURLCreateWithFileSystemPath swap CFRelease ; - -: ( string -- url ) - - [ f swap f CFURLCreateWithString ] keep - CFRelease ; - -: ( string -- bundle ) - t [ - f swap CFBundleCreate - ] keep CFRelease ; - -GENERIC: ( number -- alien ) - -M: integer - [ f kCFNumberLongLongType ] dip CFNumberCreate ; - -M: float - [ f kCFNumberDoubleType ] dip CFNumberCreate ; - -M: t - drop f kCFNumberIntType 1 CFNumberCreate ; - -M: f - drop f kCFNumberIntType 0 CFNumberCreate ; - -: ( 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 ; - -: ( fd callback -- handle ) - [ f swap ] [ t swap ] bi* f CFFileDescriptorCreate - [ "CFFileDescriptorCreate failed" throw ] unless* ; - -: load-framework ( name -- ) - dup [ - CFBundleLoadExecutable drop - ] [ - "Cannot load bundle named " prepend throw - ] ?if ; - TUPLE: CFRelease-destructor alien disposed ; M: CFRelease-destructor dispose* alien>> CFRelease ; diff --git a/basis/core-foundation/data/data.factor b/basis/core-foundation/data/data.factor new file mode 100644 index 0000000000..043fb905ad --- /dev/null +++ b/basis/core-foundation/data/data.factor @@ -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: ( number -- alien ) + +M: integer + [ f kCFNumberLongLongType ] dip CFNumberCreate ; + +M: float + [ f kCFNumberDoubleType ] dip CFNumberCreate ; + +M: t + drop f kCFNumberIntType 1 CFNumberCreate ; + +M: f + drop f kCFNumberIntType 0 CFNumberCreate ; + +: ( byte-array -- alien ) + [ f ] dip dup length CFDataCreate ; diff --git a/basis/core-foundation/data/tags.txt b/basis/core-foundation/data/tags.txt new file mode 100644 index 0000000000..2320bdd648 --- /dev/null +++ b/basis/core-foundation/data/tags.txt @@ -0,0 +1,2 @@ +unportable +bindings diff --git a/basis/core-foundation/file-descriptors/file-descriptors.factor b/basis/core-foundation/file-descriptors/file-descriptors.factor new file mode 100644 index 0000000000..29c4219678 --- /dev/null +++ b/basis/core-foundation/file-descriptors/file-descriptors.factor @@ -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 ; + +: ( fd callback -- handle ) + [ f swap ] [ t swap ] bi* f CFFileDescriptorCreate + [ "CFFileDescriptorCreate failed" throw ] unless* ; diff --git a/basis/core-foundation/file-descriptors/tags.txt b/basis/core-foundation/file-descriptors/tags.txt new file mode 100644 index 0000000000..2320bdd648 --- /dev/null +++ b/basis/core-foundation/file-descriptors/tags.txt @@ -0,0 +1,2 @@ +unportable +bindings diff --git a/basis/core-foundation/fsevents/fsevents.factor b/basis/core-foundation/fsevents/fsevents.factor index 67c2dcfa35..7ed040b455 100644 --- a/basis/core-foundation/fsevents/fsevents.factor +++ b/basis/core-foundation/fsevents/fsevents.factor @@ -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 diff --git a/basis/core-foundation/run-loop/run-loop.factor b/basis/core-foundation/run-loop/run-loop.factor index d254bf3adc..b7e565e70f 100644 --- a/basis/core-foundation/run-loop/run-loop.factor +++ b/basis/core-foundation/run-loop/run-loop.factor @@ -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 diff --git a/basis/core-foundation/strings/strings-docs.factor b/basis/core-foundation/strings/strings-docs.factor new file mode 100644 index 0000000000..4c12fb5d52 --- /dev/null +++ b/basis/core-foundation/strings/strings-docs.factor @@ -0,0 +1,14 @@ +USING: help.syntax help.markup strings ; +IN: core-foundation.strings + +HELP: +{ $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." } ; diff --git a/basis/core-foundation/strings/strings-tests.factor b/basis/core-foundation/strings/strings-tests.factor new file mode 100644 index 0000000000..39d5ee6ac0 --- /dev/null +++ b/basis/core-foundation/strings/strings-tests.factor @@ -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" CFRelease ] unit-test +[ "Hello" ] [ "Hello" [ CF>string ] [ CFRelease ] bi ] unit-test +[ "Hello\u003456" ] [ "Hello\u003456" [ CF>string ] [ CFRelease ] bi ] unit-test +[ "Hello\u013456" ] [ "Hello\u013456" [ CF>string ] [ CFRelease ] bi ] unit-test diff --git a/basis/core-foundation/strings/strings.factor b/basis/core-foundation/strings/strings.factor new file mode 100644 index 0000000000..2e6180c897 --- /dev/null +++ b/basis/core-foundation/strings/strings.factor @@ -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 +) ; + +: ( string -- alien ) + f swap utf8 string>alien kCFStringEncodingUTF8 CFStringCreateWithCString + [ "CFStringCreateWithCString failed" throw ] unless* ; + +: CF>string ( alien -- string ) + dup CFStringGetLength 4 * 1 + [ + dup length + kCFStringEncodingUTF8 + CFStringGetCString + [ "CFStringGetCString failed" throw ] unless + ] keep utf8 alien>string ; + +: CF>string-array ( alien -- seq ) + CF>array [ CF>string ] map ; + +: ( seq -- alien ) + [ ] map [ ] [ [ CFRelease ] each ] bi ; diff --git a/basis/core-foundation/strings/tags.txt b/basis/core-foundation/strings/tags.txt new file mode 100644 index 0000000000..2320bdd648 --- /dev/null +++ b/basis/core-foundation/strings/tags.txt @@ -0,0 +1,2 @@ +unportable +bindings diff --git a/basis/core-foundation/urls/tags.txt b/basis/core-foundation/urls/tags.txt new file mode 100644 index 0000000000..2320bdd648 --- /dev/null +++ b/basis/core-foundation/urls/tags.txt @@ -0,0 +1,2 @@ +unportable +bindings diff --git a/basis/core-foundation/urls/urls-docs.factor b/basis/core-foundation/urls/urls-docs.factor new file mode 100644 index 0000000000..d017e70fa6 --- /dev/null +++ b/basis/core-foundation/urls/urls-docs.factor @@ -0,0 +1,10 @@ +USING: help.syntax help.markup ; +IN: core-foundation.urls + +HELP: +{ $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: +{ $values { "string" "a URL string" } { "url" "a " { $snippet "CFURL" } } } +{ $description "Creates a new " { $snippet "CFURL" } "." } ; diff --git a/basis/core-foundation/urls/urls.factor b/basis/core-foundation/urls/urls.factor new file mode 100644 index 0000000000..9f9d3a67cb --- /dev/null +++ b/basis/core-foundation/urls/urls.factor @@ -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 ) ; + +: ( string dir? -- url ) + [ f over kCFURLPOSIXPathStyle ] dip + CFURLCreateWithFileSystemPath swap CFRelease ; + +: ( string -- url ) + + [ f swap f CFURLCreateWithString ] keep + CFRelease ; diff --git a/basis/io/unix/multiplexers/run-loop/run-loop.factor b/basis/io/unix/multiplexers/run-loop/run-loop.factor index baaf910f37..593fe93ac4 100644 --- a/basis/io/unix/multiplexers/run-loop/run-loop.factor +++ b/basis/io/unix/multiplexers/run-loop/run-loop.factor @@ -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 ;