Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -585,10 +585,18 @@ AS_IF([test x"$atomic_ops" != x"none"], [ AC_DEFINE(OF_HAVE_ATOMIC_OPS, 1, [Whether we have atomic operations]) AC_SUBST(ATOMIC_H, "atomic.h") ]) AC_MSG_RESULT($atomic_ops) + +AC_ARG_ENABLE(files, + AS_HELP_STRING([--disable-files], [disable file support])) +AS_IF([test x"$enable_files" != x"no"], [ + AC_DEFINE(OF_HAVE_FILES, 1, [Whether we have files]) + AC_SUBST(USE_SRCS_FILES, '${SRCS_FILES}') + AC_SUBST(OFZIP, ofzip) +]) AC_CHECK_FUNCS([sysconf gmtime_r localtime_r nanosleep lstat]) AC_CHECK_HEADERS([pwd.h grp.h]) AC_CHECK_FUNC(chmod, [ Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -45,8 +45,9 @@ TESTPLUGIN = @TESTPLUGIN@ TESTS = @TESTS@ TESTS_LIBS = @TESTS_LIBS@ TEST_LAUNCHER = @TEST_LAUNCHER@ USE_INCLUDES_THREADS = @USE_INCLUDES_THREADS@ +USE_SRCS_FILES = @USE_SRCS_FILES@ USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@ USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@ USE_SRCS_THREADS = @USE_SRCS_THREADS@ Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -22,11 +22,10 @@ OFDate.m \ OFDeflateStream.m \ OFDeflate64Stream.m \ OFDictionary.m \ OFEnumerator.m \ - OFFile.m \ OFIntrospection.m \ OFList.m \ OFMapTable.m \ OFMD5Hash.m \ OFMessagePackExtension.m \ @@ -66,19 +65,21 @@ OFXMLElement+Serialization.m \ OFXMLElementBuilder.m \ OFXMLNode.m \ OFXMLParser.m \ OFXMLProcessingInstructions.m \ - OFZIPArchive.m \ - OFZIPArchiveEntry.m \ base64.m \ of_asprintf.m \ of_strptime.m \ unicode.m \ + ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} +SRCS_FILES = OFFile.m \ + OFZIPArchive.m \ + OFZIPArchiveEntry.m SRCS_PLUGINS = OFPlugin.m SRCS_SOCKETS = OFHTTPClient.m \ OFHTTPRequest.m \ OFHTTPResponse.m \ OFHTTPServer.m \ Index: src/OFDataArray.h ================================================================== --- src/OFDataArray.h +++ src/OFDataArray.h @@ -77,18 +77,20 @@ * @return A new autoreleased OFDataArray */ + (instancetype)dataArrayWithItemSize: (size_t)itemSize capacity: (size_t)capacity; +#ifdef OF_HAVE_FILES /*! * @brief Creates a new OFDataArary with an item size of 1, containing the data * of the specified file. * * @param path The path of the file * @return A new autoreleased OFDataArray */ + (instancetype)dataArrayWithContentsOfFile: (OFString*)path; +#endif /*! * @brief Creates a new OFDataArray with an item size of 1, containing the data * of the specified URL. * @@ -143,18 +145,20 @@ * @return An initialized OFDataArray */ - initWithItemSize: (size_t)itemSize capacity: (size_t)capacity; +#ifdef OF_HAVE_FILES /*! * @brief Initializes an already allocated OFDataArray with an item size of 1, * containing the data of the specified file. * * @param path The path of the file * @return An initialized OFDataArray */ - initWithContentsOfFile: (OFString*)path; +#endif /*! * @brief Initializes an already allocated OFDataArray with an item size of 1, * containing the data of the specified URL. * @@ -304,16 +308,18 @@ * * @return A string containing the data in Base64 encoding */ - (OFString*)stringByBase64Encoding; +#ifdef OF_HAVE_FILES /*! * @brief Writes the OFDataArray into the specified file. * * @param path The path of the file to write to */ - (void)writeToFile: (OFString*)path; +#endif @end /*! * @brief A class for storing arbitrary big data in an array. * Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -20,11 +20,13 @@ #include #include #import "OFDataArray.h" #import "OFString.h" -#import "OFFile.h" +#ifdef OF_HAVE_FILES +# import "OFFile.h" +#endif #import "OFURL.h" #ifdef OF_HAVE_SOCKETS # import "OFHTTPClient.h" # import "OFHTTPRequest.h" # import "OFHTTPResponse.h" @@ -75,14 +77,16 @@ { return [[[self alloc] initWithItemSize: itemSize capacity: capacity] autorelease]; } +#ifdef OF_HAVE_FILES + (instancetype)dataArrayWithContentsOfFile: (OFString*)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } +#endif + (instancetype)dataArrayWithContentsOfURL: (OFURL*)URL { return [[[self alloc] initWithContentsOfURL: URL] autorelease]; } @@ -144,10 +148,11 @@ } return self; } +#ifdef OF_HAVE_FILES - initWithContentsOfFile: (OFString*)path { @try { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; @@ -181,10 +186,11 @@ @throw e; } return self; } +#endif - initWithContentsOfURL: (OFURL*)URL { void *pool; #ifdef OF_HAVE_SOCKETS @@ -200,13 +206,17 @@ [self release]; pool = objc_autoreleasePoolPush(); if ([[URL scheme] isEqual: @"file"]) { +#ifdef OF_HAVE_FILES self = [[c alloc] initWithContentsOfFile: [URL path]]; objc_autoreleasePoolPop(pool); return self; +#else + @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; +#endif } #ifdef OF_HAVE_SOCKETS client = [OFHTTPClient client]; request = [OFHTTPRequest requestWithURL: URL]; @@ -597,10 +607,11 @@ - (OFString*)stringByBase64Encoding { return of_base64_encode(_items, _count * _itemSize); } +#ifdef OF_HAVE_FILES - (void)writeToFile: (OFString*)path { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"wb"]; @@ -609,10 +620,11 @@ length: _count * _itemSize]; } @finally { [file release]; } } +#endif - (OFXMLElement*)XMLElementBySerializing { void *pool; OFXMLElement *element; Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -169,10 +169,11 @@ { return (id)[[OFMutableString_UTF8 alloc] initWithFormat: format arguments: arguments]; } +#ifdef OF_HAVE_FILES - initWithContentsOfFile: (OFString*)path { return (id)[[OFMutableString_UTF8 alloc] initWithContentsOfFile: path]; } @@ -181,10 +182,11 @@ { return (id)[[OFMutableString_UTF8 alloc] initWithContentsOfFile: path encoding: encoding]; } +#endif - initWithContentsOfURL: (OFURL*)URL { return (id)[[OFMutableString_UTF8 alloc] initWithContentsOfURL: URL]; } Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -270,10 +270,11 @@ * @param format A string used as format to initialize the OFString * @return A new autoreleased OFString */ + (instancetype)stringWithFormat: (OFConstantString*)format, ...; +#ifdef OF_HAVE_FILES /*! * @brief Creates a new OFString with the contents of the specified UTF-8 * encoded file. * * @param path The path to the file @@ -289,10 +290,11 @@ * @param encoding The encoding of the file * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfFile: (OFString*)path encoding: (of_string_encoding_t)encoding; +#endif /*! * @brief Creates a new OFString with the contents of the specified URL. * * If the URL's scheme is file, it tries UTF-8 encoding. @@ -512,10 +514,11 @@ * @return An initialized OFString */ - initWithFormat: (OFConstantString*)format arguments: (va_list)arguments; +#ifdef OF_HAVE_FILES /*! * @brief Initializes an already allocated OFString with the contents of the * specified file in the specified encoding. * * @param path The path to the file @@ -531,10 +534,11 @@ * @param encoding The encoding of the file * @return An initialized OFString */ - initWithContentsOfFile: (OFString*)path encoding: (of_string_encoding_t)encoding; +#endif /*! * @brief Initializes an already allocated OFString with the contents of the * specified URL. * @@ -1027,10 +1031,11 @@ * @return The string in UTF-32 encoding with the specified byte order */ - (const of_char32_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder OF_RETURNS_INNER_POINTER; +#ifdef OF_HAVE_FILES /*! * @brief Writes the string into the specified file using UTF-8 encoding. * * @param path The path of the file to write to */ @@ -1043,10 +1048,11 @@ * @param path The path of the file to write to * @param encoding The encoding to use to write the string into the file */ - (void)writeToFile: (OFString*)path encoding: (of_string_encoding_t)encoding; +#endif #ifdef OF_HAVE_BLOCKS /*! * Enumerates all lines in the receiver using the specified block. * Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -25,11 +25,13 @@ #import "OFString.h" #import "OFString_UTF8.h" #import "OFString_UTF8+Private.h" #import "OFArray.h" #import "OFDictionary.h" -#import "OFFile.h" +#ifdef OF_HAVE_FILES +# import "OFFile.h" +#endif #import "OFURL.h" #ifdef OF_HAVE_SOCKETS # import "OFHTTPClient.h" # import "OFHTTPRequest.h" # import "OFHTTPResponse.h" @@ -409,10 +411,11 @@ { return (id)[[OFString_UTF8 alloc] initWithFormat: format arguments: arguments]; } +#ifdef OF_HAVE_FILES - initWithContentsOfFile: (OFString*)path { return (id)[[OFString_UTF8 alloc] initWithContentsOfFile: path]; } @@ -420,10 +423,11 @@ encoding: (of_string_encoding_t)encoding { return (id)[[OFString_UTF8 alloc] initWithContentsOfFile: path encoding: encoding]; } +#endif - initWithContentsOfURL: (OFURL*)URL { return (id)[[OFString_UTF8 alloc] initWithContentsOfURL: URL]; } @@ -599,10 +603,11 @@ va_end(arguments); return ret; } +#ifdef OF_HAVE_FILES + (instancetype)stringWithContentsOfFile: (OFString*)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } @@ -610,10 +615,11 @@ encoding: (of_string_encoding_t)encoding { return [[[self alloc] initWithContentsOfFile: path encoding: encoding] autorelease]; } +#endif + (instancetype)stringWithContentsOfURL: (OFURL*)URL { return [[[self alloc] initWithContentsOfURL: URL] autorelease]; } @@ -784,10 +790,11 @@ arguments: (va_list)arguments { OF_INVALID_INIT_METHOD } +#ifdef OF_HAVE_FILES - initWithContentsOfFile: (OFString*)path { return [self initWithContentsOfFile: path encoding: OF_STRING_ENCODING_UTF_8]; } @@ -831,10 +838,11 @@ length: (size_t)st.st_size]; [self freeMemory: tmp]; return self; } +#endif - initWithContentsOfURL: (OFURL*)URL { return [self initWithContentsOfURL: URL encoding: OF_STRING_ENCODING_AUTODETECT]; @@ -858,17 +866,21 @@ [self release]; pool = objc_autoreleasePoolPush(); if ([[URL scheme] isEqual: @"file"]) { +#ifdef OF_HAVE_FILES if (encoding == OF_STRING_ENCODING_AUTODETECT) encoding = OF_STRING_ENCODING_UTF_8; self = [[c alloc] initWithContentsOfFile: [URL path] encoding: encoding]; objc_autoreleasePoolPop(pool); return self; +#else + @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; +#endif } #ifdef OF_HAVE_SOCKETS client = [OFHTTPClient client]; request = [OFHTTPRequest requestWithURL: URL]; @@ -2423,10 +2435,11 @@ } return ret; } +#ifdef OF_HAVE_FILES - (void)writeToFile: (OFString*)path { return [self writeToFile: path encoding: OF_STRING_ENCODING_UTF_8]; } @@ -2442,10 +2455,11 @@ [file writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } +#endif #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { void *pool = objc_autoreleasePoolPush(); Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -105,18 +105,20 @@ * @param string The string to parse * @return A new autoreleased OFXMLElement with the contents of the string */ + (instancetype)elementWithXMLString: (OFString*)string; +#ifdef OF_HAVE_FILES /*! * @brief Parses the specified file and returns an OFXMLElement for it. * * @param path The path to the file * @return A new autoreleased OFXMLElement with the contents of the specified * file */ + (instancetype)elementWithFile: (OFString*)path; +#endif /*! * @brief Initializes an already allocated OFXMLElement with the specified name. * * @param name The name for the element @@ -179,18 +181,20 @@ * @param string The string to parse * @return An initialized OFXMLElement with the contents of the string */ - initWithXMLString: (OFString*)string; +#ifdef OF_HAVE_FILES /*! * @brief Parses the specified file and initializes an already allocated * OFXMLElement with it. * * @param path The path to the file * @return An initialized OFXMLElement with the contents of the specified file */ - initWithFile: (OFString*)path; +#endif /*! * @brief Sets the name of the element. * * @param name The new name Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -117,14 +117,16 @@ + (instancetype)elementWithXMLString: (OFString*)string { return [[[self alloc] initWithXMLString: string] autorelease]; } +#ifdef OF_HAVE_FILES + (instancetype)elementWithFile: (OFString*)path { return [[[self alloc] initWithFile: path] autorelease]; } +#endif - init { OF_INVALID_INIT_METHOD } @@ -234,10 +236,11 @@ objc_autoreleasePoolPop(pool); return self; } +#ifdef OF_HAVE_FILES - initWithFile: (OFString*)path { void *pool; OFXMLParser *parser; OFXMLElementBuilder *builder; @@ -264,10 +267,11 @@ objc_autoreleasePoolPop(pool); return self; } +#endif - initWithSerialization: (OFXMLElement*)element { self = [super init]; Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -230,16 +230,18 @@ * * @param stream The stream to parse */ - (void)parseStream: (OFStream*)stream; +#ifdef OF_HAVE_FILES /*! * @brief Parses the specified file. * * @param path The path to the file to parse */ - (void)parseFile: (OFString*)path; +#endif /*! * @brief Returns the current line number. * * @return The current line number Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -25,11 +25,13 @@ #import "OFArray.h" #import "OFDictionary.h" #import "OFDataArray.h" #import "OFXMLAttribute.h" #import "OFStream.h" -#import "OFFile.h" +#ifdef OF_HAVE_FILES +# import "OFFile.h" +#endif #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFMalformedXMLException.h" #import "OFUnboundPrefixException.h" @@ -294,10 +296,11 @@ } @finally { [self freeMemory: buffer]; } } +#ifdef OF_HAVE_FILES - (void)parseFile: (OFString*)path { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; @@ -305,10 +308,11 @@ [self parseStream: file]; } @finally { [file release]; } } +#endif /* * The following methods handle the different states of the parser. They are * looked up in +[initialize] and put in a lookup table to speed things up. * One dispatch for every character would be way too slow! Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -45,13 +45,15 @@ #import "OFURL.h" #import "OFStream.h" #import "OFStdIOStream.h" #import "OFDeflateStream.h" -#import "OFFile.h" -#import "OFZIPArchive.h" -#import "OFZIPArchiveEntry.h" +#ifdef OF_HAVE_FILES +# import "OFFile.h" +# import "OFZIPArchive.h" +# import "OFZIPArchiveEntry.h" +#endif #ifdef OF_HAVE_SOCKETS # import "OFStreamSocket.h" # import "OFTCPSocket.h" # import "OFTLSSocket.h" # import "OFStreamObserver.h" Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -4,10 +4,11 @@ #undef OF_HAVE_ASPRINTF #undef OF_HAVE_ATOMIC_OPS #undef OF_HAVE_CHMOD #undef OF_HAVE_CHOWN #undef OF_HAVE_COMPILER_TLS +#undef OF_HAVE_FILES #undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR #undef OF_HAVE_GCC_ATOMIC_OPS #undef OF_HAVE_LINK #undef OF_HAVE_MAX_ALIGN_T #undef OF_HAVE_OSATOMIC Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -9,28 +9,29 @@ OFDataArrayTests.m \ OFDateTests.m \ OFDictionaryTests.m \ OFJSONTests.m \ OFListTests.m \ - OFMD5HashTests.m \ OFNumberTests.m \ OFObjectTests.m \ - OFSerializationTests.m \ OFSet.m \ - OFSHA1HashTests.m \ OFStreamTests.m \ OFStringTests.m \ OFURLTests.m \ OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ ${PROPERTIESTESTS_M} \ TestsAppDelegate.m \ + ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} \ ${OFHTTPCLIENTTESTS_M} +SRCS_FILES = OFMD5HashTests.m \ + OFSerializationTests.m \ + OFSHA1HashTests.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFTCPSocketTests.m SRCS_THREADS = OFThreadTests.m IOS_USER ?= mobile Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -171,10 +171,11 @@ (is = [OFString stringWithUTF32String: ucstr]) && [is isEqual: @"fööbär🀺"] && (is = [OFString stringWithUTF32String: sucstr]) && [is isEqual: @"fööbär🀺"]) +#ifdef OF_HAVE_FILES TEST(@"+[stringWithContentsOfFile:encoding]", (is = [OFString stringWithContentsOfFile: @"testfile.txt" encoding: OF_STRING_ENCODING_ISO_8859_1]) && [is isEqual: @"testäöü"]) @@ -181,10 +182,11 @@ TEST(@"+[stringWithContentsOfURL:encoding]", (is = [OFString stringWithContentsOfURL: [OFURL URLWithString: @"file://testfile.txt"] encoding: OF_STRING_ENCODING_ISO_8859_1]) && [is isEqual: @"testäöü"]) +#endif TEST(@"-[appendUTFString:length:]", R([s[0] appendUTF8String: "foo\xEF\xBB\xBF" "barqux" + 3 length: 6]) && [s[0] isEqual: @"foobar"]) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -289,20 +289,22 @@ #endif } - (void)applicationDidFinishLaunching { -#ifdef __wii__ +#if defined(__wii__) && defined(OF_HAVE_FILES) [OFFile changeCurrentDirectoryPath: @"/apps/objfw-tests"]; #endif [self objectTests]; #ifdef OF_HAVE_BLOCKS [self blockTests]; #endif +#ifdef OF_HAVE_FILES [self MD5HashTests]; [self SHA1HashTests]; +#endif [self stringTests]; [self dataArrayTests]; [self arrayTests]; [self dictionaryTests]; [self listTests]; @@ -321,11 +323,13 @@ [self HTTPClientTests]; #endif [self XMLParserTests]; [self XMLNodeTests]; [self XMLElementBuilderTests]; +#ifdef OF_HAVE_FILES [self serializationTests]; +#endif [self JSONTests]; #ifdef OF_HAVE_PLUGINS [self pluginTests]; #endif [self forwardingTests]; Index: utils/Makefile ================================================================== --- utils/Makefile +++ utils/Makefile @@ -1,8 +1,8 @@ include ../extra.mk -PROG = ofzip +PROG = ${OFZIP} SRCS = OFZIP.m ${PROG}: ${LIBOBJFW_DEP} include ../buildsys.mk