Permalink
Browse files

Fixes for Linux port

  • Loading branch information...
itfrombit committed Jul 9, 2009
1 parent 1f0aa00 commit 65f15a5900ee3d0c58a47a41da648424ab01865d
Showing with 84 additions and 4 deletions.
  1. +15 −2 Nukefile
  2. +15 −0 objc/JSON.h
  3. +45 −1 objc/JSON.m
  4. +9 −1 test/test_examples.nu
View
@@ -17,13 +17,26 @@
;; source files
(set @m_files (filelist "^objc/.*.m$"))
+(set SYSTEM ((NSString stringWithShellCommand:"uname") chomp))
+
+(case SYSTEM
+ ("Darwin"
+ (set @cflags "-g -std=gnu99")
+ (set @ldflags "-framework Foundation"))
+ ("Linux"
+ (set @arch (list "i386"))
+ (set gnustep_flags ((NSString stringWithShellCommand:"gnustep-config --objc-flags") chomp))
+ (set gnustep_libs ((NSString stringWithShellCommand:"gnustep-config --base-libs") chomp))
+ (set @cflags "-g -std=gnu99 -DLINUX -I/usr/local/include #{gnustep_flags}")
+ (set @ldflags "#{gnustep_libs}"))
+ (else nil))
+
+
;; framework description
(set @framework "NuJSON")
(set @framework_identifier "nu.programming.json")
(set @framework_creator_code "????")
-(set @cflags "-g -fobjc-gc -std=gnu99 -I Source")
-(set @ldflags "-framework Foundation")
(compilation-tasks)
(framework-tasks)
View
@@ -115,15 +115,30 @@ anything else not in the JSON specification.
JSON with linebreaks after each array value and dictionary key/value pair, indented two
spaces per nesting level.
*/
+#ifdef DARWIN
@property BOOL humanReadable;
+#else
+- (BOOL) humanReadable;
+- (void) setHumanReadable:(BOOL)humanReadable;
+#endif
/// Whether or not to sort the dictionary keys in the output
/** The default is to not sort the keys. */
+#ifdef DARWIN
@property BOOL sortKeys;
+#else
+- (BOOL) sortKeys;
+- (void) setSortKeys:(BOOL)sortKeys;
+#endif
/// The maximum depth the parser will go to
/** Defaults to 512. */
+#ifdef DARWIN
@property NSUInteger maxDepth;
+#else
+- (NSUInteger) maxDepth;
+- (void) setMaxDepth:(NSUInteger)maxDepth;
+#endif
/// Return JSON representation of an array or dictionary
- (NSString*)stringWithObject:(id)value error:(NSError**)error;
View
@@ -193,7 +193,14 @@ - (BOOL)appendArray:(NSArray*)fragment into:(NSMutableString*)json error:(NSErro
depth++;
BOOL addComma = NO;
+
+#ifdef DARWIN
for (id value in fragment) {
+#else
+ for (int i = 0; i < [fragment count]; i++) {
+ id value = [fragment objectAtIndex:i];
+#endif
+
if (addComma)
[json appendString:@","];
else
@@ -222,10 +229,15 @@ - (BOOL)appendDictionary:(NSDictionary*)fragment into:(NSMutableString*)json err
NSString *colon = [self humanReadable] ? @" : " : @":";
BOOL addComma = NO;
NSArray *keys = [fragment allKeys];
- if (self.sortKeys)
+ if ([self sortKeys])
keys = [keys sortedArrayUsingSelector:@selector(compare:)];
+#ifdef DARWIN
for (id value in keys) {
+#else
+ for (int i = 0; i < [keys count]; i++) {
+ id value = [keys objectAtIndex:i];
+#endif
if (addComma)
[json appendString:@","];
else
@@ -739,9 +751,41 @@ - (BOOL)scanIsAtEnd
return !*c;
}
+#ifdef DARWIN
@synthesize humanReadable;
@synthesize sortKeys;
@synthesize maxDepth;
+#else
+- (BOOL) humanReadable
+{
+ return humanReadable;
+}
+
+- (void) setHumanReadable:(BOOL) newHumanReadable
+{
+ humanReadable = newHumanReadable;
+}
+
+- (BOOL) sortKeys
+{
+ return sortKeys;
+}
+
+- (void) setSortKeys:(BOOL) newSortKeys
+{
+ sortKeys = newSortKeys;
+}
+
+- (NSUInteger) maxDepth
+{
+ return maxDepth;
+}
+
+- (void) setMaxDepth:(NSUInteger) newMaxDepth
+{
+ maxDepth = newMaxDepth;
+}
+#endif
@end
View
@@ -1,5 +1,13 @@
(load "NuJSON")
+
+(if (eq (uname) "Linux")
+ (then
+ (set NSASCIIStringEncoding 1)
+ (class NSString
+ (+ (id) stringWithContentsOfFile:(id)path encoding:(int)encoding error:(id)error is
+ (self stringWithContentsOfFile:path)))))
+
(class TestExamples is NuTestCase
(- testJsonOrg is
@@ -25,7 +33,7 @@
(assert_equal expected (((expected JSONRepresentation) JSONValue)))))
(- testRFC4627 is
- (set dir "Tests/rfc4627")
+ (set dir "test/rfc4627")
(set files ((NSFileManager defaultManager) enumeratorAtPath:dir))
(while (set file (files nextObject))
(unless ((file pathExtension) isEqualToString:"json")

0 comments on commit 65f15a5

Please sign in to comment.