]> err.no Git - sope/blobdiff - sope-core/EOControl/EOQualifierParser.m
fixed a few warnings when compiling against GNUstep
[sope] / sope-core / EOControl / EOQualifierParser.m
index 25a84aa44b30035864bb435b62d244076b580862..1f803442961d8c6a28c0f67381eebddf502b294a 100644 (file)
@@ -1,24 +1,24 @@
 /*
-  Copyright (C) 2000-2004 SKYRIX Software AG
+  Copyright (C) 2000-2007 SKYRIX Software AG
+  Copyright (C) 2007      Helge Hess
 
-  This file is part of OpenGroupware.org.
+  This file is part of SOPE.
 
-  OGo is free software; you can redistribute it and/or modify it under
+  SOPE is free software; you can redistribute it and/or modify it under
   the terms of the GNU Lesser General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version.
 
-  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+  SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
   License for more details.
 
   You should have received a copy of the GNU Lesser General Public
-  License along with OGo; see the file COPYING.  If not, write to the
+  License along with SOPE; see the file COPYING.  If not, write to the
   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
   02111-1307, USA.
 */
-// $Id$
 
 #include <stdio.h>
 #include "EOQualifier.h"
@@ -43,13 +43,13 @@ typedef struct {
 } EOQPTokEntry;
 
 static EOQPTokEntry toks[] = {
-  { "NULL",  nil, 0 },
-  { "nil",   nil, 1 },
-  { "YES",   nil, 0 },
-  { "NO",    nil, 0 },
-  { "TRUE",  nil, 0 },
-  { "FALSE", nil, 0 },
-  { NULL,    nil, 0 }
+  { (const unsigned char *)"NULL",  nil, 0 },
+  { (const unsigned char *)"nil",   nil, 1 },
+  { (const unsigned char *)"YES",   nil, 0 },
+  { (const unsigned char *)"NO",    nil, 0 },
+  { (const unsigned char *)"TRUE",  nil, 0 },
+  { (const unsigned char *)"FALSE", nil, 0 },
+  { (const unsigned char *)NULL,    nil, 0 }
 };
 
 static inline void _setupLiterals(void) {
@@ -588,7 +588,8 @@ static EOQualifier *_parseKeyCompQualifier(id _ctx, const char *_buf,
   unsigned     pos        = 0;
   BOOL         valueIsKey = NO;
 
-  dict = [_ctx resultForFunction:@"parseKeyCompQualifier" atPos:(unsigned)_buf];
+  dict = [_ctx resultForFunction:@"parseKeyCompQualifier" 
+              atPos:(unsigned long)_buf];
   if (dict != nil) {
     if (qDebug)
       NSLog(@"_parseKeyCompQual return <%@> [cached] for <%s> ", dict, _buf);
@@ -656,7 +657,7 @@ static EOQualifier *_parseKeyCompQualifier(id _ctx, const char *_buf,
     [_ctx setResult:
             [NSDictionary dictionaryWithObjects:values forKeys:keys count:2]
           forFunction:@"parseKeyCompQualifier"
-          atPos:(unsigned)_buf];
+          atPos:(unsigned long)_buf];
     *_qualLen = pos;
   }
   return qual;
@@ -736,7 +737,7 @@ static NSString *_parseKey(id _ctx, const char *_buf, unsigned _bufLen,
     if (qDebug) NSLog(@"%s: _bufLen == 0 --> return nil", __PRETTY_FUNCTION__);
     return nil;
   }
-  dict = [_ctx resultForFunction:@"parseKey" atPos:(unsigned)_buf];
+  dict = [_ctx resultForFunction:@"parseKey" atPos:(unsigned long)_buf];
   if (dict != nil) {
     if (qDebug) {
       NSLog(@"%s: return <%@> [cached] for <%s> ", __PRETTY_FUNCTION__,
@@ -810,7 +811,7 @@ static NSString *_parseKey(id _ctx, const char *_buf, unsigned _bufLen,
     [_ctx setResult:
             [NSDictionary dictionaryWithObjects:values forKeys:keys count:2]
           forFunction:@"parseKey"
-          atPos:(unsigned)_buf];
+          atPos:(unsigned long)_buf];
     *_keyLen = pos;
   }
   return result;
@@ -833,7 +834,7 @@ static id _parseValue(id _ctx, const char *_buf, unsigned _bufLen,
     return nil;
   }
   
-  dict = [_ctx resultForFunction:@"parseValue" atPos:(unsigned)_buf];
+  dict = [_ctx resultForFunction:@"parseValue" atPos:(unsigned long)_buf];
   if (dict != nil) {
     if (qDebug) {
       NSLog(@"_parseKeyCompQualifier return <%@> [cached] for <%s> ",
@@ -945,20 +946,28 @@ static id _parseValue(id _ctx, const char *_buf, unsigned _bufLen,
        int rc;
        
        tok = toks[i].token;
-       toklen = strlen(tok);
+       toklen = strlen((const char *)tok);
        if ((_bufLen - pos) < toklen)
          /* remaining string not long enough */
          continue;
        
        rc = toks[i].scase 
-         ? strncmp(&(_buf[pos]),     tok, toklen)
-         : strncasecmp(&(_buf[pos]), tok, toklen);
+         ? strncmp(&(_buf[pos]),     (const char *)tok, toklen)
+         : strncasecmp(&(_buf[pos]), (const char *)tok, toklen);
        if (rc != 0)
          /* does not match */
          continue;
-       if (!(_buf[pos + toklen] == '\0' || isspace(_buf[pos + toklen])))
-         /* not at the string end or folloed by a space */
+       
+       if (!(_buf[pos + toklen] == '\0' || isspace(_buf[pos + toklen]) ||
+             _buf[pos + toklen] == ')')) {
+         /*
+           Not at the string end or followed by a space or a right 
+           parenthesis. The latter is required to correctly parse this:
+             (not (attribute = nil) and
+               attribute.className = 'com.webobjects.foundation.NSTimestamp')
+         */
          continue;
+       }
 
        /* wow, found the token */
        pos += toklen; /* skip it */
@@ -1028,12 +1037,12 @@ static id _parseValue(id _ctx, const char *_buf, unsigned _bufLen,
          
          //printf("POS: '%s'\n", &(_buf[pos]));
          pos++;
-         cs = &(_buf[pos]);
-         ce = index(cs, '\'');
-         cast = [NSString stringWithCString:cs length:(ce - cs)];
+         cs = (const unsigned char *)&(_buf[pos]);
+         ce = (const unsigned char *)index((const char *)cs, '\'');
+         cast = [NSString stringWithCString:(const char*)cs length:(ce - cs)];
          if (qDebug) {
-           NSLog(@"%s: parsed complex cast: '%@' to '%@'", __PRETTY_FUNCTION__,
-                 obj, cast);
+           NSLog(@"%s: parsed complex cast: '%@' to '%@'", 
+                 __PRETTY_FUNCTION__, obj, cast);
          }
          pos += (ce - cs);
          pos++; // skip '
@@ -1082,18 +1091,19 @@ static id _parseValue(id _ctx, const char *_buf, unsigned _bufLen,
   
   if (qDebug) {
     NSLog(@"%s: return <%@> for <%s> ", __PRETTY_FUNCTION__, 
-         obj?obj:@"<nil>", _buf);
+         obj != nil ? obj : (id)@"<nil>", _buf);
   }
   
   if (obj != nil) {
+    NSDictionary *d;
     id keys[2], values[2];
     
     keys[0] = @"length"; values[0] = [NSNumber numberWithUnsignedInt:pos];
     keys[1] = @"object"; values[1] = obj;
     
-    [_ctx setResult:
-            [NSDictionary dictionaryWithObjects:values forKeys:keys count:2]
-          forFunction:@"parseValue" atPos:(unsigned)_buf];
+    d = [[NSDictionary alloc] initWithObjects:values forKeys:keys count:2];
+    [_ctx setResult:d forFunction:@"parseValue" atPos:(unsigned long)_buf];
+    [d release];
     *_keyLen = pos;
   }
   return obj;