this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add vim into build, add extra APIs into CoreServices (#314) - sadly vim doesn't run yet

+388 -1
+1
src/CMakeLists.txt
··· 206 206 add_subdirectory(external/nano) 207 207 add_subdirectory(external/man) 208 208 add_subdirectory(external/bc) 209 + add_subdirectory(external/vim) 209 210 add_subdirectory(external/zip/zip/zip30) 210 211 add_subdirectory(external/zip/unzip/unzip-5.52) 211 212 add_subdirectory(tools)
+2 -1
src/CoreServices/CMakeLists.txt
··· 40 40 OpenTransport.cpp 41 41 Timer.cpp 42 42 CoreServicesPriv.cpp 43 - #../external/libcxx/src/dso_handle.c 43 + TextCommon.cpp 44 + TextEncodingConverter.cpp 44 45 ) 45 46 46 47 if (WITH_COREAUDIO)
+2
src/CoreServices/CoreServices.h
··· 23 23 #include <CoreServices/ToolUtils.h> 24 24 #include <CoreServices/UniChar.h> 25 25 #include <CoreServices/UnicodeUtilities.h> 26 + #include <CoreServices/TextCommon.h> 27 + #include <CoreServices/TextEncodingConverter.h> 26 28 27 29 #endif 28 30
+31
src/CoreServices/TextCommon.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2017 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include "TextCommon.h" 21 + 22 + TextEncoding CreateTextEncoding(TextEncodingBase encodingBase, TextEncodingVariant encodingVariant, TextEncodingFormat encodingFormat) 23 + { 24 + TextEncoding rv = encodingBase & 0xff; 25 + rv |= (encodingVariant << 8) & 0xff00; 26 + rv |= (encodingFormat << 16) & 0xff0000; 27 + return rv; 28 + } 29 + 30 + 31 +
+75
src/CoreServices/TextCommon.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2017 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef _TEXTCOMMON_H 21 + #define _TEXTCOMMON_H 22 + #include <MacTypes.h> 23 + 24 + #ifdef __cplusplus 25 + extern "C" { 26 + #endif 27 + 28 + typedef UInt8* TextPtr; 29 + typedef const UInt8* ConstTextPtr; 30 + 31 + enum { 32 + kTextEncodingUnicodeDefault = 0x100 33 + }; 34 + 35 + enum { 36 + kTextEncodingDefaultVariant = 0 37 + }; 38 + 39 + enum { 40 + kTextEncodingDefaultFormat = 0, 41 + kUnicodeUTF16Format = 0, 42 + kUnicodeUTF7Format = 1, 43 + kUnicodeUTF8Format = 2, 44 + kUnicodeUTF32Format = 3, 45 + kUnicodeUTF16BEFormat = 4, 46 + kUnicodeUTF16LEFormat = 5, 47 + kUnicodeUTF32BEFormat = 6, 48 + kUnicodeUTF32LEFormat = 7, 49 + kUnicodeSCSUFormat = 8, 50 + kUnicode16BitFormat = 0, 51 + kUnicode32BitFormat = 3, 52 + }; 53 + 54 + enum { 55 + kUnicodeNoSubset = 0, 56 + kUnicodeNormalizationFormD = 5, 57 + kUnicodeNormalizationFormC = 3, 58 + kUnicodeCanonicalCompVariant = kUnicodeNormalizationFormC, 59 + kUnicodeHFSPlusDecompVariant = 8, 60 + kUnicodeHFSPlusCompVariant = 9, 61 + }; 62 + 63 + typedef UInt32 TextEncoding; 64 + typedef UInt32 TextEncodingBase; 65 + typedef UInt32 TextEncodingFormat; 66 + typedef UInt32 TextEncodingVariant; 67 + 68 + TextEncoding CreateTextEncoding(TextEncodingBase encodingBase, TextEncodingVariant encodingVariant, TextEncodingFormat encodingFormat); 69 + 70 + #ifdef __cplusplus 71 + } 72 + #endif 73 + 74 + #endif 75 +
+233
src/CoreServices/TextEncodingConverter.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2017 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include "TextEncodingConverter.h" 21 + #include <unicode/ucnv.h> 22 + #include <unicode/normalizer2.h> 23 + #include "MacErrors.h" 24 + 25 + struct OpaqueTECObjectRef 26 + { 27 + UConverter* inputConverter; 28 + UConverter* outputConverter; 29 + const UNormalizer2* normalizer; 30 + UChar buffer[64]; 31 + size_t bufferUsed; 32 + }; 33 + 34 + static UConverter* createConverter(TextEncodingBase base, TextEncodingFormat format) 35 + { 36 + switch (base) 37 + { 38 + case kTextEncodingUnicodeDefault: 39 + { 40 + const char* enc; 41 + UErrorCode error = U_ZERO_ERROR; 42 + 43 + switch (format) 44 + { 45 + case kUnicodeUTF16Format: 46 + enc = "UTF-16"; 47 + break; 48 + case kUnicodeUTF7Format: 49 + enc = "UTF-7"; 50 + break; 51 + case kUnicodeUTF8Format: 52 + enc = "UTF-8"; 53 + break; 54 + case kUnicodeUTF32Format: 55 + enc = "UTF-32"; 56 + break; 57 + case kUnicodeUTF16BEFormat: 58 + enc = "UTF-16BE"; 59 + break; 60 + case kUnicodeUTF16LEFormat: 61 + enc = "UTF-16LE"; 62 + break; 63 + case kUnicodeUTF32BEFormat: 64 + enc = "UTF-32BE"; 65 + break; 66 + case kUnicodeUTF32LEFormat: 67 + enc = "UTF-32LE"; 68 + break; 69 + default: 70 + return NULL; 71 + } 72 + 73 + return ucnv_open(enc, &error); 74 + } 75 + default: 76 + return NULL; 77 + } 78 + } 79 + 80 + OSStatus TECCreateConverter(TECObjectRef *newEncodingConverter, TextEncoding inputEncoding, TextEncoding outputEncoding) 81 + { 82 + TextEncodingFormat format; 83 + TextEncodingBase base; 84 + TextEncodingVariant variant; 85 + OpaqueTECObjectRef* obj = new OpaqueTECObjectRef; 86 + 87 + obj->inputConverter = obj->outputConverter = NULL; 88 + obj->normalizer = NULL; 89 + obj->bufferUsed = 0; 90 + 91 + format = (inputEncoding >> 16) & 0xff; 92 + base = (inputEncoding >> 0) & 0xff; 93 + variant = (inputEncoding >> 8) & 0xff; 94 + 95 + obj->inputConverter = createConverter(base, format); 96 + if (!obj->inputConverter) 97 + { 98 + TECDisposeConverter(obj); 99 + *newEncodingConverter = NULL; 100 + return unimpErr; 101 + } 102 + 103 + format = (outputEncoding >> 16) & 0xff; 104 + base = (outputEncoding >> 0) & 0xff; 105 + variant = (outputEncoding >> 8) & 0xff; 106 + 107 + obj->outputConverter = createConverter(base, format); 108 + if (!obj->outputConverter) 109 + { 110 + TECDisposeConverter(obj); 111 + *newEncodingConverter = NULL; 112 + return unimpErr; 113 + } 114 + 115 + if (base == kTextEncodingUnicodeDefault) 116 + { 117 + switch (variant) 118 + { 119 + case kUnicodeNoSubset: 120 + break; 121 + case kUnicodeNormalizationFormD: 122 + { 123 + UErrorCode error = U_ZERO_ERROR; 124 + obj->normalizer = unorm2_getNFDInstance(&error); 125 + break; 126 + } 127 + case kUnicodeNormalizationFormC: 128 + { 129 + UErrorCode error = U_ZERO_ERROR; 130 + obj->normalizer = unorm2_getNFCInstance(&error); 131 + break; 132 + } 133 + case kUnicodeHFSPlusDecompVariant: 134 + case kUnicodeHFSPlusCompVariant: 135 + { 136 + UErrorCode error = U_ZERO_ERROR; 137 + obj->normalizer = unorm2_getNFKDInstance(&error); 138 + break; 139 + } 140 + } 141 + } 142 + 143 + *newEncodingConverter = obj; 144 + return noErr; 145 + } 146 + 147 + OSStatus TECConvertText(TECObjectRef encodingConverter, ConstTextPtr inputBuffer, 148 + ByteCount inputBufferLength, ByteCount *actualInputLength, 149 + TextPtr outputBuffer, ByteCount outputBufferLength, ByteCount *actualOutputLength) 150 + { 151 + if (actualInputLength != NULL) 152 + *actualInputLength = 0; 153 + *actualOutputLength = 0; 154 + 155 + while (outputBufferLength > 0) 156 + { 157 + if (encodingConverter->bufferUsed > 0) 158 + { 159 + // flush buffer 160 + UErrorCode error = U_ZERO_ERROR; 161 + char* target = (char*) outputBuffer; 162 + const UChar* source = encodingConverter->buffer; 163 + ByteCount inputUsed; 164 + 165 + 166 + ucnv_fromUnicode(encodingConverter->outputConverter, 167 + &target, target + outputBufferLength, 168 + &source, source + encodingConverter->bufferUsed, 169 + NULL, false, &error); 170 + 171 + if (error != U_ZERO_ERROR && error != U_BUFFER_OVERFLOW_ERROR) 172 + return paramErr; 173 + 174 + *actualOutputLength = target - ((char*)outputBuffer); 175 + 176 + inputUsed = source - encodingConverter->buffer; 177 + if (inputUsed < encodingConverter->bufferUsed) 178 + { 179 + memmove(encodingConverter->buffer, 180 + encodingConverter->buffer + inputUsed, 181 + encodingConverter->bufferUsed - inputUsed); 182 + } 183 + encodingConverter->bufferUsed -= inputUsed; 184 + outputBuffer += *actualOutputLength; 185 + outputBufferLength -= *actualOutputLength; 186 + 187 + if (error == U_BUFFER_OVERFLOW_ERROR) 188 + break; 189 + } 190 + 191 + if (inputBufferLength <= 0) 192 + break; 193 + 194 + // Consume input 195 + { 196 + UChar* target = encodingConverter->buffer + encodingConverter->bufferUsed; 197 + const char* source = (const char*) inputBuffer; 198 + UErrorCode error = U_ZERO_ERROR; 199 + 200 + ucnv_toUnicode(encodingConverter->inputConverter, 201 + &target, encodingConverter->buffer + (sizeof(encodingConverter->buffer) / sizeof(encodingConverter->buffer[0])), 202 + &source, source + inputBufferLength, 203 + NULL, false, &error); 204 + 205 + if (error != U_ZERO_ERROR && error != U_BUFFER_OVERFLOW_ERROR) 206 + return paramErr; 207 + 208 + encodingConverter->bufferUsed += target - (encodingConverter->buffer + encodingConverter->bufferUsed); 209 + *actualInputLength += source - ((const char*)inputBuffer); 210 + inputBufferLength -= source - ((const char*)inputBuffer); 211 + inputBuffer = (ConstTextPtr) source; 212 + } 213 + 214 + // TODO: normalize 215 + // Normalization may cause the data to no longer fit into our internal buffer :-/ 216 + } 217 + 218 + return noErr; 219 + } 220 + 221 + OSStatus TECFlushText(TECObjectRef encodingConverter, TextPtr outputBuffer, ByteCount outputBufferLength, ByteCount *actualOutputLength) 222 + { 223 + return TECConvertText(encodingConverter, NULL, 0, NULL, outputBuffer, outputBufferLength, actualOutputLength); 224 + } 225 + 226 + OSStatus TECDisposeConverter(TECObjectRef conv) 227 + { 228 + ucnv_close(conv->inputConverter); 229 + ucnv_close(conv->outputConverter); 230 + delete conv; 231 + return noErr; 232 + } 233 +
+44
src/CoreServices/TextEncodingConverter.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2017 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef _TEXTENCODINGCONVERTER_H 21 + #define _TEXTENCODINGCONVERTER_H 22 + #include <MacTypes.h> 23 + #include "TextCommon.h" 24 + 25 + #ifdef __cplusplus 26 + extern "C" { 27 + #endif 28 + 29 + typedef struct OpaqueTECObjectRef* TECObjectRef; 30 + 31 + OSStatus TECCreateConverter(TECObjectRef *newEncodingConverter, TextEncoding inputEncoding, TextEncoding outputEncoding); 32 + 33 + OSStatus TECConvertText(TECObjectRef encodingConverter, ConstTextPtr inputBuffer, ByteCount inputBufferLength, ByteCount *actualInputLength, TextPtr outputBuffer, ByteCount outputBufferLength, ByteCount *actualOutputLength); 34 + 35 + OSStatus TECFlushText(TECObjectRef encodingConverter, TextPtr outputBuffer, ByteCount outputBufferLength, ByteCount *actualOutputLength); 36 + 37 + OSStatus TECDisposeConverter(TECObjectRef newEncodingConverter); 38 + 39 + #ifdef __cplusplus 40 + } 41 + #endif 42 + 43 + #endif 44 +