Index: src/OFConstantString.h ================================================================== --- src/OFConstantString.h +++ src/OFConstantString.h @@ -13,11 +13,14 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#import "OFString.h" +#ifndef OBJFW_OF_CONSTANT_STRING_H +#define OBJFW_OF_CONSTANT_STRING_H + +#include "OFString.h" OF_ASSUME_NONNULL_BEGIN #if !defined(OF_CONSTANT_STRING_M) && \ defined(OF_APPLE_RUNTIME) && !defined(__OBJC2__) @@ -28,10 +31,11 @@ # ifdef __cplusplus } # endif #endif +#ifdef __OBJC__ /*! * @class OFConstantString OFConstantString.h ObjFW/OFConstantString.h * * @brief A class for storing constant strings using the `@""` literal. */ @@ -40,7 +44,10 @@ { char *_cString; unsigned int _cStringLength; } @end +#endif OF_ASSUME_NONNULL_END + +#endif Index: src/OFMutableString.h ================================================================== --- src/OFMutableString.h +++ src/OFMutableString.h @@ -13,14 +13,18 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#import "OFString.h" +#ifndef OBJFW_OF_MUTABLE_STRING_H +#define OBJFW_OF_MUTABLE_STRING_H + +#include "OFString.h" OF_ASSUME_NONNULL_BEGIN +#ifdef __OBJC__ /*! * @class OFMutableString OFString.h ObjFW/OFString.h * * @brief A class for storing and modifying strings. */ @@ -210,7 +214,10 @@ /*! * @brief Converts the mutable string to an immutable string. */ - (void)makeImmutable; @end +#endif OF_ASSUME_NONNULL_END + +#endif Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -13,10 +13,13 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ +#ifndef OBJFW_OF_OBJECT_H +#define OBJFW_OF_OBJECT_H + #include "objfw-defs.h" #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif @@ -27,12 +30,12 @@ #include #include #include #include -#import "macros.h" -#import "block.h" +#include "macros.h" +#include "block.h" /* * Some versions of MinGW require to be included before * . Do this here to make sure this is always done in the correct * order, even if another header includes just . @@ -275,10 +278,11 @@ return false; return true; } +#ifdef __OBJC__ @class OFMethodSignature; @class OFString; @class OFThread; /*! @@ -288,15 +292,15 @@ */ @protocol OFObject /*! * @brief The class of the object. */ -#ifndef __cplusplus +# ifndef __cplusplus @property (readonly, nonatomic) Class class; -#else +# else @property (readonly, nonatomic, getter=class) Class class_; -#endif +# endif /*! * @brief The superclass of the object. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) Class superclass; @@ -490,37 +494,39 @@ * * @return Whether a weak reference to this object has been retained */ - (bool)retainWeakReference; @end +#endif /*! * @class OFObject OFObject.h ObjFW/OFObject.h * * @brief The root class for all other classes inside ObjFW. */ +#ifdef __OBJC__ OF_ROOT_CLASS @interface OFObject { @private -#ifndef __clang_analyzer__ +# ifndef __clang_analyzer__ Class _isa; -#else +# else Class _isa __attribute__((__unused__)); -#endif +# endif } -#ifdef OF_HAVE_CLASS_PROPERTIES -# ifndef __cplusplus +# ifdef OF_HAVE_CLASS_PROPERTIES +# ifndef __cplusplus @property (class, readonly, nonatomic) Class class; -# else +# else @property (class, readonly, nonatomic, getter=class) Class class_; -# endif +# endif @property (class, readonly, nonatomic) OFString *className; @property (class, readonly, nullable, nonatomic) Class superclass; @property (class, readonly, nonatomic) OFString *description; -#endif +# endif /*! * @brief The name of the object's class. */ @property (readonly, nonatomic) OFString *className; @@ -935,11 +941,11 @@ withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 afterDelay: (of_time_interval_t)delay; -#ifdef OF_HAVE_THREADS +# ifdef OF_HAVE_THREADS /*! * @brief Performs the specified selector on the specified thread. * * @param selector The selector to perform * @param thread The thread on which to perform the selector @@ -1193,11 +1199,11 @@ withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 afterDelay: (of_time_interval_t)delay; -#endif +# endif /*! * @brief This method is called when @ref resolveClassMethod: or * @ref resolveInstanceMethod: returned false. It should return a target * to which the message should be forwarded. @@ -1218,11 +1224,15 @@ * * @param selector The selector not understood by the receiver */ - (void)doesNotRecognizeSelector: (SEL)selector OF_NO_RETURN; @end +#else +typedef void OFObject; +#endif +#ifdef __OBJC__ /*! * @protocol OFCopying OFObject.h ObjFW/OFObject.h * * @brief A protocol for the creation of copies. */ @@ -1270,10 +1280,11 @@ * @param object An object to compare the object to * @return The result of the comparison */ - (of_comparison_result_t)compare: (id )object; @end +#endif #ifdef __cplusplus extern "C" { #endif #ifdef OF_APPLE_RUNTIME @@ -1288,7 +1299,11 @@ } #endif OF_ASSUME_NONNULL_END -#import "OFObject+KeyValueCoding.h" -#import "OFObject+Serialization.h" +#ifdef __OBJC__ +# import "OFObject+KeyValueCoding.h" +# import "OFObject+Serialization.h" +#endif + +#endif Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -12,19 +12,22 @@ * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ + +#ifndef OBJFW_OF_STRING_H +#define OBJFW_OF_STRING_H #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif -#import "objfw-defs.h" +#include "objfw-defs.h" #ifdef OF_HAVE_SYS_TYPES_H # include #endif @@ -32,20 +35,27 @@ #include #ifdef OF_HAVE_INTTYPES_H # include #endif -#import "OFObject.h" -#import "OFSerialization.h" -#import "OFJSONRepresentation.h" -#import "OFMessagePackRepresentation.h" +#include "OFObject.h" +#ifdef __OBJC__ +# import "OFSerialization.h" +# import "OFJSONRepresentation.h" +# import "OFMessagePackRepresentation.h" +#endif OF_ASSUME_NONNULL_BEGIN /*! @file */ +#ifdef __OBJC__ @class OFConstantString; +@class OFString; +#else +typedef void OFString; +#endif #if defined(__cplusplus) && __cplusplus >= 201103L typedef char16_t of_char16_t; typedef char32_t of_char32_t; #else @@ -108,10 +118,11 @@ * enumeration */ typedef void (^of_string_line_enumeration_block_t)(OFString *line, bool *stop); #endif +#ifdef __OBJC__ @class OFArray OF_GENERIC(ObjectType); @class OFCharacterSet; @class OFURL; /*! @@ -262,11 +273,11 @@ /*! * @brief The string with leading and trailing whitespaces deleted. */ @property (readonly, nonatomic) OFString *stringByDeletingEnclosingWhitespaces; -#ifdef OF_HAVE_UNICODE_TABLES +# ifdef OF_HAVE_UNICODE_TABLES /*! * @brief The string in Unicode Normalization Form D (NFD). */ @property (readonly, nonatomic) OFString *decomposedStringWithCanonicalMapping; @@ -273,11 +284,11 @@ /*! * @brief The string in Unicode Normalization Form KD (NFKD). */ @property (readonly, nonatomic) OFString *decomposedStringWithCompatibilityMapping; -#endif +# endif /*! * @brief Creates a new OFString. * * @return A new, autoreleased OFString @@ -489,11 +500,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 +# 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 @@ -509,13 +520,13 @@ * @param encoding The encoding of the file * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (of_string_encoding_t)encoding; -#endif +# endif -#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS) +# if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS) /*! * @brief Creates a new OFString with the contents of the specified URL. * * If the URL's scheme is file, it tries UTF-8 encoding. * @@ -536,11 +547,11 @@ * @param encoding The encoding to assume * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding; -#endif +# endif /*! * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * @@ -763,11 +774,11 @@ * @return An initialized OFString */ - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments; -#ifdef OF_HAVE_FILES +# 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 @@ -783,11 +794,11 @@ * @param encoding The encoding of the file * @return An initialized OFString */ - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (of_string_encoding_t)encoding; -#endif +# endif /*! * @brief Initializes an already allocated OFString with the contents of the * specified URL. * @@ -1168,11 +1179,11 @@ * @param encoding The encoding to use for the returned OFData * @return The string as OFData with the specified encoding */ - (OFData *)dataWithEncoding: (of_string_encoding_t)encoding; -#ifdef OF_HAVE_FILES +# 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 */ @@ -1185,11 +1196,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 +# endif /*! * @brief Writes the string to the specified URL using UTF-8 encoding. * * @param URL The URL to write to @@ -1203,19 +1214,20 @@ * @param encoding The encoding to use to write the string to the URL */ - (void)writeToURL: (OFURL *)URL encoding: (of_string_encoding_t)encoding; -#ifdef OF_HAVE_BLOCKS +# ifdef OF_HAVE_BLOCKS /*! * Enumerates all lines in the receiver using the specified block. * * @brief block The block to call for each line */ - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block; -#endif +# endif @end +#endif #ifdef __cplusplus extern "C" { #endif extern of_string_encoding_t of_string_parse_encoding(OFString *); @@ -1228,24 +1240,26 @@ } #endif OF_ASSUME_NONNULL_END -#import "OFConstantString.h" -#import "OFMutableString.h" -#import "OFString+CryptoHashing.h" -#import "OFString+JSONValue.h" -#ifdef OF_HAVE_FILES -# import "OFString+PathAdditions.h" -#endif -#import "OFString+PropertyListValue.h" -#import "OFString+Serialization.h" -#import "OFString+URLEncoding.h" -#import "OFString+XMLEscaping.h" -#import "OFString+XMLUnescaping.h" - -#if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) +#include "OFConstantString.h" +#include "OFMutableString.h" +#ifdef __OBJC__ +# import "OFString+CryptoHashing.h" +# import "OFString+JSONValue.h" +# ifdef OF_HAVE_FILES +# import "OFString+PathAdditions.h" +# endif +# import "OFString+PropertyListValue.h" +# import "OFString+Serialization.h" +# import "OFString+URLEncoding.h" +# import "OFString+XMLEscaping.h" +# import "OFString+XMLUnescaping.h" +#endif + +#if defined(__OBJC__) && !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* * Very *ugly* hack required for string boxing literals to work. * * This hack is needed in order to work with `@class NSString` from Apple's * objc/NSString.h - which is included when using modules - as @@ -1256,6 +1270,8 @@ * * TODO: Submit a patch for Clang that makes the boxing classes configurable! */ @interface NSString: OFString @end +#endif + #endif Index: src/block.h ================================================================== --- src/block.h +++ src/block.h @@ -13,11 +13,14 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#import "macros.h" +#ifndef OBJFW_BLOCK_H +#define OBJFW_BLOCK_H + +#include "macros.h" OF_ASSUME_NONNULL_BEGIN typedef struct of_block_literal_t { #ifdef __OBJC__ @@ -68,5 +71,7 @@ #ifndef Block_release # define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) #endif OF_ASSUME_NONNULL_END + +#endif Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -12,10 +12,13 @@ * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ + +#ifndef OBJFW_MACROS_H +#define OBJFW_MACROS_H #include "objfw-defs.h" #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS @@ -35,19 +38,19 @@ #include "platform.h" #ifdef OF_OBJFW_RUNTIME # ifdef OF_COMPILING_OBJFW -# import "ObjFWRT.h" +# include "ObjFWRT.h" # else -# import +# include # endif #endif #ifdef OF_APPLE_RUNTIME -# import -# import -# import +# include +# include +# include #endif #if defined(__GNUC__) # define restrict __restrict__ #elif __STDC_VERSION__ < 199901L @@ -886,5 +889,7 @@ gettimeofday(&tv, NULL); srand((unsigned)(tv.tv_sec ^ tv.tv_usec)); return (((uint32_t)(rand()) << 16) | ((uint32_t)(rand()) & 0xFFFF)); #endif } + +#endif