[mapserver-commits] r13048 - sandbox/sdlime/rfc-77

svn at osgeo.org svn at osgeo.org
Sun Feb 5 23:43:29 EST 2012


Author: sdlime
Date: 2012-02-05 20:43:29 -0800 (Sun, 05 Feb 2012)
New Revision: 13048

Modified:
   sandbox/sdlime/rfc-77/mapfile.c
   sandbox/sdlime/rfc-77/maputil.c
Log:
Created static evalTextExpression() function for use in a couple of places in msShapeGetAnnotation().

Modified: sandbox/sdlime/rfc-77/mapfile.c
===================================================================
--- sandbox/sdlime/rfc-77/mapfile.c	2012-02-05 22:21:13 UTC (rev 13047)
+++ sandbox/sdlime/rfc-77/mapfile.c	2012-02-06 04:43:29 UTC (rev 13048)
@@ -1683,9 +1683,9 @@
     msFree(label->bindings[i].item);
 
   freeExpression(&(label->expression));
-  freeExpression(&(label->text)); // NEXT! writeLabel()
+  freeExpression(&(label->text)); // RFC TODO: writeLabel()
 
-  /* RFC 77 TODO: free book keeping vars */
+  /* free book keeping vars associated with the label cache */
   msFree(label->annotext);
   if(label->annopoly) {
     msFreeShape(label->annopoly);

Modified: sandbox/sdlime/rfc-77/maputil.c
===================================================================
--- sandbox/sdlime/rfc-77/maputil.c	2012-02-05 22:21:13 UTC (rev 13047)
+++ sandbox/sdlime/rfc-77/maputil.c	2012-02-06 04:43:29 UTC (rev 13048)
@@ -579,8 +579,63 @@
   return(-1); /* no match */
 }
 
+static char *evalTextExpression(expressionObj *expr, shapeObj *shape) {
+  char *result=NULL;
+
+  if(!expr->string) return result; /* nothing to do */
+
+  switch(expr->type) {
+  case(MS_STRING):
+    {
+      char *target=NULL;
+      tokenListNodeObjPtr node=NULL;
+      tokenListNodeObjPtr nextNode=NULL;
+
+      result = msStrdup(expr->string);
+
+      node = expr->tokens;
+      if(node) {
+        while(node != NULL) {
+          nextNode = node->next;
+          if(node->token == MS_TOKEN_BINDING_DOUBLE || node->token == MS_TOKEN_BINDING_INTEGER || node->token == MS_TOKEN_BINDING_STRING || node->token == MS_TOKEN_BINDING_TIME) {
+            target = (char *) msSmallMalloc(strlen(node->tokenval.bindval.item) + 3);
+            sprintf(target, "[%s]", node->tokenval.bindval.item);
+            result = msReplaceSubstring(result, target, shape->values[node->tokenval.bindval.index]);
+            msFree(target);
+          }
+          node = nextNode;
+        }
+      }
+    }
+    break;
+  case(MS_EXPRESSION):
+    {
+      int status;
+      parseObj p;
+
+      p.shape = shape;
+      p.expr = expr;
+      p.expr->curtoken = p.expr->tokens; /* reset */
+      p.type = MS_PARSE_TYPE_STRING;
+
+      status = yyparse(&p);
+
+      if (status != 0) {
+        msSetError(MS_PARSEERR, "Failed to process text expression: %s", "evalTextExpression", expr->string);
+        return NULL;
+      }
+
+      result = p.result.strval;        
+      break;
+    }
+  default:
+    break;
+  }
+
+  return result;
+}
+
 int msShapeGetAnnotation(layerObj *layer, shapeObj *shape) {
-  char *tmpstr;
   int i, j;
 
   /* RFC 77 TODO: check and throw some errors here... */
@@ -592,64 +647,19 @@
     /* RFC 77 TODO: will evaluate label scale limits here... */
     /* RFC 77 TODO: will evaluate label expressions here... */
 
-    tmpstr = NULL; /* initialize */
-    if(layer->class[i]->text.string) { /* RFC 77 TODO: will check for a label text value first, then class text and finally try labelitem */
-      switch(layer->class[i]->text.type) {
-      case(MS_STRING):
-        {
-          char *target=NULL;
-          tokenListNodeObjPtr node=NULL;
-          tokenListNodeObjPtr nextNode=NULL;
+    msFree(layer->class[i]->labels[j]->annotext);
+    layer->class[i]->labels[j]->annotext = NULL;
 
-          tmpstr = msStrdup(layer->class[i]->text.string);
-
-          node = layer->class[i]->text.tokens;
-          if(node) {
-            while(node != NULL) {
-              nextNode = node->next;
-              if(node->token == MS_TOKEN_BINDING_DOUBLE || node->token == MS_TOKEN_BINDING_INTEGER || node->token == MS_TOKEN_BINDING_STRING || node->token == MS_TOKEN_BINDING_TIME) {
-                target = (char *) msSmallMalloc(strlen(node->tokenval.bindval.item) + 3);
-                sprintf(target, "[%s]", node->tokenval.bindval.item);
-                tmpstr = msReplaceSubstring(tmpstr, target, shape->values[node->tokenval.bindval.index]);
-                msFree(target);
-	      }
-              node = nextNode;
-            }
-	  }
-        }
-        break;
-      case(MS_EXPRESSION):
-        {
-          int status;
-          parseObj p;
-
-          p.shape = shape;
-          p.expr = &(layer->class[i]->text);
-          p.expr->curtoken = p.expr->tokens; /* reset */
-          p.type = MS_PARSE_TYPE_STRING;
-
-          status = yyparse(&p);
-
-          if (status != 0) {
-	    msSetError(MS_PARSEERR, "Failed to process text expression: %s", "msShapeGetAnnotation", layer->class[j]->text.string);
-	    return MS_FAILURE;
-          }
-
-          tmpstr = p.result.strval;        
-          break;
-        }
-      default:
-        break;
-      }
+    if(layer->class[i]->labels[j]->text.string) { /* RFC 77 TODO: will check for a label text value first, then class text and finally try labelitem */      
+      layer->class[i]->labels[j]->annotext = evalTextExpression(&(layer->class[i]->labels[j]->text), shape);
+    } if(layer->class[i]->text.string) {
+      layer->class[i]->labels[j]->annotext = evalTextExpression(&(layer->class[i]->text), shape);
     } else {
       if (shape->values && layer->labelitemindex >= 0)
-        tmpstr = msStrdup(shape->values[layer->labelitemindex]);
+        layer->class[i]->labels[j]->annotext = msStrdup(shape->values[layer->labelitemindex]);
       else
-	tmpstr = msStrdup(shape->text); /* last resort but common with iniline features */
+	layer->class[i]->labels[j]->annotext = msStrdup(shape->text); /* last resort but common with iniline features */
     }
-
-    msFree(layer->class[i]->labels[j]->annotext);
-    layer->class[i]->labels[j]->annotext = tmpstr;
   }
 
   return MS_SUCCESS;



More information about the mapserver-commits mailing list