[xiph-commits] r12731 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sun Mar 11 12:39:38 PDT 2007


Author: xiphmont
Date: 2007-03-11 12:39:34 -0700 (Sun, 11 Mar 2007)
New Revision: 12731

Modified:
   trunk/sushivision/dimension.c
   trunk/sushivision/internal.h
   trunk/sushivision/main.c
   trunk/sushivision/mapping.c
   trunk/sushivision/mapping.h
   trunk/sushivision/panel-2d.c
   trunk/sushivision/panel.c
   trunk/sushivision/slice.c
   trunk/sushivision/slider.c
   trunk/sushivision/xml.c
   trunk/sushivision/xml.h
Log:
More xml use pattern retooling
finish implementing load for 2d panels.



Modified: trunk/sushivision/dimension.c
===================================================================
--- trunk/sushivision/dimension.c	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/dimension.c	2007-03-11 19:39:34 UTC (rev 12731)
@@ -56,7 +56,6 @@
   if(lo>hi){ // == must be 1 to match scale gen code when width is 0
     pneg = -1;
   }else{
-
     pneg = 1;
   }
   
@@ -771,13 +770,13 @@
 		    sushiv_instance_undo_t *u,
 		    xmlNodePtr dn,
 		    int warn){
-  
+
   // check name 
   xmlCheckPropS(dn,"name",d->name,"Dimension %d name mismatch in save file.",d->number,&warn);
- 
+  
   // check type
   xmlCheckMap(dn,"type",typemap, d->type, "Dimension %d type mismatch in save file.",d->number,&warn);
-
+  
   // load vals
   xmlGetPropF(dn,"low-bracket", &u->dim_vals[0][d->number]);
   xmlGetPropF(dn,"value", &u->dim_vals[1][d->number]);

Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/internal.h	2007-03-11 19:39:34 UTC (rev 12731)
@@ -27,16 +27,6 @@
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include "sushivision.h"
-#include "mapping.h"
-#include "slice.h"
-#include "spinner.h"
-#include "slider.h"
-#include "scale.h"
-#include "plot.h"
-#include "dimension.h"
-#include "objective.h"
-#include "panel-1d.h"
-#include "panel-2d.h"
 
 // used to glue numeric settings to semantic labels for menus/save files
 typedef struct propmap {
@@ -48,6 +38,16 @@
   void (*callback)(sushiv_panel_t *, GtkWidget *);
 } propmap;
 
+#include "mapping.h"
+#include "slice.h"
+#include "spinner.h"
+#include "slider.h"
+#include "scale.h"
+#include "plot.h"
+#include "dimension.h"
+#include "objective.h"
+#include "panel-1d.h"
+#include "panel-2d.h"
 #include "xml.h"
 #include "gtksucks.h"
 
@@ -60,7 +60,7 @@
 // for now we use a master undo type which leaves one or two fields
 // unused for a given panel.
 typedef struct sushiv_panel_undo {
-  u_int32_t *mappings;
+  int *mappings;
   double *scale_vals[3];
   
   int x_d;
@@ -70,11 +70,11 @@
   int box_active;
 
   int grid_mode;
-  unsigned char cross_mode;
-  unsigned char legend_mode;
-  unsigned char bg_mode;
-  unsigned char text_mode;
-  unsigned char menu_cursamp;
+  int cross_mode;
+  int legend_mode;
+  int bg_mode;
+  int text_mode;
+  int menu_cursamp;
   int oversample_n;
   int oversample_d;
 

Modified: trunk/sushivision/main.c
===================================================================
--- trunk/sushivision/main.c	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/main.c	2007-03-11 19:39:34 UTC (rev 12731)
@@ -349,9 +349,9 @@
   // piggyback off undo (as it already goes through the trouble of
   // doing correct unrolling, which can be tricky)
 
-  // if this instance has an undo stack, pop it all.
+  // if this instance has an undo stack, pop it all, then log current state into it
   s->private->undo_level=0;
-  _sushiv_undo_pop(s);
+  _sushiv_undo_log(s);
 
   sushiv_instance_undo_t *u = s->private->undo_stack[s->private->undo_level];
 
@@ -360,33 +360,33 @@
     sushiv_dimension_t *d = s->dimension_list[i];
     if(d){
       xmlNodePtr dn = xmlGetChildI(in,"dimension","number",d->number);
-      if(dn){ 
-	warn |= _load_dimension(d,u,dn,warn);
-	xmlFreeNode(dn);
-      }else{
+      if(!dn){
 	first_load_warning(&warn);
 	fprintf(stderr,"Could not find data for dimension \"%s\" in save file.\n",
 		d->name);
+      }else{
+	warn |= _load_dimension(d,u,dn,warn);
+	xmlFreeNode(dn);
       }
     }
   }
-
+  
   // load panels
   for(i=0;i<s->panels;i++){
     sushiv_panel_t *p = s->panel_list[i];
     if(p){
       xmlNodePtr pn = xmlGetChildI(in,"panel","number",p->number);
-      if(pn){ 
-	warn |= _load_panel(p,u->panels+i,pn,warn);
-	xmlFreeNode(pn);
-      }else{
+      if(!pn){ 
 	first_load_warning(&warn);
 	fprintf(stderr,"Could not find data for panel \"%s\" in save file.\n",
 		p->name);
+      }else{
+	warn |= _load_panel(p,u->panels+i,pn,warn);
+	xmlFreeNode(pn);
       }
     }
   }
-
+  
   // if any elements are unclaimed, warn 
   xmlNodePtr node = in->xmlChildrenNode;
   while(node){
@@ -404,7 +404,9 @@
   }
   
   // effect the loaded values
+  _sushiv_undo_suspend(s);
   _sushiv_undo_restore(s);
+  _sushiv_undo_resume(s);
 
   return warn;
 }
@@ -473,14 +475,14 @@
     sushiv_instance_t *s = instance_list[i];
     if(s){
       xmlNodePtr in = xmlGetChildI(root,"instance","number",s->number);
-      if(in){ 
-	warn |= load_instance(s,in,warn);
-	xmlFreeNode(in);
-      }else{
+      if(!in){ 
 	first_load_warning(&warn);
 	fprintf(stderr,"Could not find data for instance \"%s\" in save file.\n",
 		s->name);
       }
+      // load even if no node; need to set fallbacks
+      warn |= load_instance(s,in,warn);
+      if(in)xmlFreeNode(in);
     }
   }
 
@@ -489,7 +491,8 @@
   
   while(node){
     if (node->type == XML_ELEMENT_NODE) {
-      char *name = xmlGetPropS(node, "name");
+      char *name = NULL;
+      xmlGetPropS(node, "name", &name);
       first_load_warning(&warn);
       if(name){
 	fprintf(stderr,"Save file contains data for nonexistant object \"%s\".\n",

Modified: trunk/sushivision/mapping.c
===================================================================
--- trunk/sushivision/mapping.c	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/mapping.c	2007-03-11 19:39:34 UTC (rev 12731)
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
-#include "mapping.h"
+#include "internal.h"
 
 // val is .16; lcolor has pigment added in the range [0,mul]
 static void scalloped_colorwheel(int val, int mul, lcolor *r){
@@ -309,18 +309,18 @@
   inactive_mix
 };
 
-static char *mapnames[]={
-  "smooth colorwheel",
-  "scalloped colorwheel",
-  "grayscale",
-  "red",
-  "green",
-  "blue",
-  "red overlay",
-  "green overlay",
-  "blue overlay",
-  "inactive",
-0
+static propmap *mapnames[]={
+  &(propmap){"smooth colorwheel",0,    NULL, NULL, NULL},
+  &(propmap){"scalloped colorwheel",1, NULL, NULL, NULL},
+  &(propmap){"grayscale",2,            NULL, NULL, NULL},
+  &(propmap){"red",3,                  NULL, NULL, NULL},
+  &(propmap){"green",4,                NULL, NULL, NULL},
+  &(propmap){"blue",5,                 NULL, NULL, NULL},
+  &(propmap){"red overlay",6,          NULL, NULL, NULL},
+  &(propmap){"green overlay",7,        NULL, NULL, NULL},
+  &(propmap){"blue overlay",8,         NULL, NULL, NULL},
+  &(propmap){"inactive",9,             NULL, NULL, NULL},
+  NULL
 };
 
 int num_mappings(){
@@ -330,9 +330,13 @@
 }
 
 char *mapping_name(int i){
-  return mapnames[i];
+  return mapnames[i]->left;
 }
 
+propmap **mapping_map(){
+  return mapnames;
+}
+
 void mapping_setup(mapping *m, float lo, float hi, int funcnum){
   m->low = lo;
   m->high = hi;
@@ -421,18 +425,18 @@
   inactive_mix
 };
 
-static char *solidnames[]={
-  "black",
-  "red",
-  "green",
-  "blue",
-  "yellow",
-  "cyan",
-  "purple",
-  "gray",
-  "white",
-  "inactive",
-  0
+static propmap *solidnames[]={
+  &(propmap){"black",0,     NULL,NULL,NULL},
+  &(propmap){"red",1,       NULL,NULL,NULL},
+  &(propmap){"green",2,     NULL,NULL,NULL},
+  &(propmap){"blue",3,      NULL,NULL,NULL},
+  &(propmap){"yellow",4,    NULL,NULL,NULL},
+  &(propmap){"cyan",5,      NULL,NULL,NULL},
+  &(propmap){"purple",6,    NULL,NULL,NULL},
+  &(propmap){"gray",7,      NULL,NULL,NULL},
+  &(propmap){"white",8,     NULL,NULL,NULL},
+  &(propmap){"inactive",9,  NULL,NULL,NULL},
+  NULL
 };
 
 int num_solids(){
@@ -442,9 +446,13 @@
 }
 
 char *solid_name(int i){
-  return solidnames[i];
+  return solidnames[i]->left;
 }
 
+propmap **solid_map(){
+  return solidnames;
+}
+
 void solid_setup(mapping *m, float lo, float hi, int funcnum){
   m->low = lo;
   m->high = hi;

Modified: trunk/sushivision/mapping.h
===================================================================
--- trunk/sushivision/mapping.h	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/mapping.h	2007-03-11 19:39:34 UTC (rev 12731)
@@ -72,3 +72,7 @@
 extern char *solid_name(int i);
 extern void solid_setup(mapping *m, float lo, float hi, int funcnum);
 extern void solid_set_func(mapping *m, int funcnum);
+
+extern propmap **mapping_map();
+extern propmap **solid_map();
+

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/panel-2d.c	2007-03-11 19:39:34 UTC (rev 12731)
@@ -1839,7 +1839,6 @@
 
 static int _save_panel2d(sushiv_panel_t *p, xmlNodePtr pn){  
   sushiv_panel2d_t *p2 = p->subtype->p2;
-  char buffer[80];
   int ret=0,i;
 
   xmlNodePtr n;
@@ -1847,63 +1846,90 @@
   xmlNewProp(pn, (xmlChar *)"type", (xmlChar *)"2d");
 
   // box
-  xmlNodePtr boxn = xmlNewChild(pn, NULL, (xmlChar *) "box", NULL);
   if(p->private->oldbox_active){
-    xmlNewProp(boxn, (xmlChar *)"active",(xmlChar *)"yes");
-    snprintf(buffer,sizeof(buffer),"%.20g",p2->oldbox[0]);
-    xmlNewProp(boxn, (xmlChar *)"x1", (xmlChar *)buffer);
-    snprintf(buffer,sizeof(buffer),"%.20g",p2->oldbox[1]);
-    xmlNewProp(boxn, (xmlChar *)"x2", (xmlChar *)buffer);
-    snprintf(buffer,sizeof(buffer),"%.20g",p2->oldbox[2]);
-    xmlNewProp(boxn, (xmlChar *)"y1", (xmlChar *)buffer);
-    snprintf(buffer,sizeof(buffer),"%.20g",p2->oldbox[3]);
-    xmlNewProp(boxn, (xmlChar *)"y2", (xmlChar *)buffer);
-  }else
-    xmlNewProp(boxn, (xmlChar *)"active",(xmlChar *)"no");
+    xmlNodePtr boxn = xmlNewChild(pn, NULL, (xmlChar *) "box", NULL);
+    xmlNewPropF(boxn, "x1", p2->oldbox[0]);
+    xmlNewPropF(boxn, "x2", p2->oldbox[1]);
+    xmlNewPropF(boxn, "y1", p2->oldbox[2]);
+    xmlNewPropF(boxn, "y2", p2->oldbox[3]);
+  }
 
   // objective map settings
   for(i=0;i<p->objectives;i++){
     sushiv_objective_t *o = p->objective_list[i].o;
-
     xmlNodePtr on = xmlNewChild(pn, NULL, (xmlChar *) "objective", NULL);
-    snprintf(buffer,sizeof(buffer),"%d",i);
-    xmlNewProp(on, (xmlChar *)"position", (xmlChar *)buffer);
-    snprintf(buffer,sizeof(buffer),"%d",o->number);
-    xmlNewProp(on, (xmlChar *)"number", (xmlChar *)buffer);
-    xmlNewProp(on, (xmlChar *)"name", (xmlChar *)o->name);
-    xmlNewProp(on, (xmlChar *)"type", (xmlChar *)o->output_types);
+    xmlNewPropI(on, "position", i);
+    xmlNewPropI(on, "number", o->number);
+    xmlNewPropS(on, "name", o->name);
+    xmlNewPropS(on, "type", o->output_types);
     
     // right now Y is the only type; the below is Y-specific
     n = xmlNewChild(on, NULL, (xmlChar *) "mapping", NULL);
-    xmlNewProp(n, (xmlChar *)"type", (xmlChar *)mapping_name(p2->mappings[i].mapnum));
+    xmlNewPropS(n, "type", mapping_name(p2->mappings[i].mapnum));
     n = xmlNewChild(on, NULL, (xmlChar *) "y-scale", NULL);
-    snprintf(buffer,sizeof(buffer),"%.20g",slider_get_value(p2->range_scales[i],0));
-    xmlNewProp(n, (xmlChar *)"low-bracket", (xmlChar *)buffer);
-    snprintf(buffer,sizeof(buffer),"%.20g",slider_get_value(p2->range_scales[i],1));
-    xmlNewProp(n, (xmlChar *)"alpha", (xmlChar *)buffer);
-    snprintf(buffer,sizeof(buffer),"%.20g",slider_get_value(p2->range_scales[i],2));
-    xmlNewProp(n, (xmlChar *)"high-bracket", (xmlChar *)buffer);
+    xmlNewPropF(n, "low-bracket", slider_get_value(p2->range_scales[i],0));
+    xmlNewPropF(n, "alpha", slider_get_value(p2->range_scales[i],1));
+    xmlNewPropF(n, "high-bracket", slider_get_value(p2->range_scales[i],2));
   }
 
   // x/y dim selection
-  n = xmlNewChild(pn, NULL, (xmlChar *) "selected-x", NULL);
-  snprintf(buffer,sizeof(buffer),"%d",p2->x_dnum);
-  xmlNewProp(n, (xmlChar *)"pos", (xmlChar *)buffer);
-  n = xmlNewChild(pn, NULL, (xmlChar *) "selected-y", NULL);
-  snprintf(buffer,sizeof(buffer),"%d",p2->y_dnum);
-  xmlNewProp(n, (xmlChar *)"pos", (xmlChar *)buffer);
+  n = xmlNewChild(pn, NULL, (xmlChar *) "axes", NULL);
+  xmlNewPropI(n, "xpos", p2->x_dnum);
+  xmlNewPropI(n, "ypos", p2->y_dnum);
 
   return ret;
 }
 
-int _load_panel_2d(sushiv_panel_t *d,
+int _load_panel2d(sushiv_panel_t *p,
 		   sushiv_panel_undo_t *u,
 		   xmlNodePtr pn,
 		   int warn){
+  int i;
+
+  // check type
+  xmlCheckPropS(pn,"type","2d", "Panel %d type mismatch in save file.",p->number,&warn);
   
-  // check type
+  // box
+  u->box_active = 0;
+  xmlGetChildPropFPreserve(pn, "box", "x1", &u->box[0]);
+  xmlGetChildPropFPreserve(pn, "box", "x2", &u->box[1]);
+  xmlGetChildPropFPreserve(pn, "box", "y1", &u->box[2]);
+  xmlGetChildPropFPreserve(pn, "box", "y2", &u->box[3]);
 
+  xmlNodePtr n = xmlGetChildS(pn, "box", NULL, NULL);
+  if(n){
+    u->box_active = 1;
+    xmlFree(n);
+  }
+  
+  // objective map settings
+  for(i=0;i<p->objectives;i++){
+    sushiv_objective_t *o = p->objective_list[i].o;
+    xmlNodePtr on = xmlGetChildI(pn, "objective", "position", i);
+    if(!on){
+      first_load_warning(&warn);
+      fprintf(stderr,"No save data found for panel %d objective \"%s\".\n",p->number, o->name);
+    }else{
+      // check name, type
+      xmlCheckPropS(on,"name",o->name, "Objectve position %d name mismatch in save file.",i,&warn);
+      xmlCheckPropS(on,"type",o->output_types, "Objectve position %d type mismatch in save file.",i,&warn);
+      
+      // right now Y is the only type; the below is Y-specific
+      // load maptype, values
+      xmlGetChildMap(on, "mapping", "type", mapping_map(), &u->mappings[i],
+		     "Panel %d objective unknown mapping setting", p->number, &warn);
+      xmlGetChildPropFPreserve(on, "y-scale", "low-bracket", &u->scale_vals[0][i]);
+      xmlGetChildPropFPreserve(on, "y-scale", "alpha", &u->scale_vals[1][i]);
+      xmlGetChildPropF(on, "y-scale", "high-bracket", &u->scale_vals[2][i]);
 
+      xmlFreeNode(on);
+    }
+  }
+
+  // x/y dim selection
+  xmlGetChildPropIPreserve(pn, "axes", "xpos", &u->x_d);
+  xmlGetChildPropI(pn, "axes", "ypos", &u->y_d);
+
   return warn;
 }
 
@@ -1950,6 +1976,7 @@
   p->private->undo_log = panel2d_undo_log;
   p->private->undo_restore = panel2d_undo_restore;
   p->private->save_action = _save_panel2d;
+  p->private->load_action = _load_panel2d;
 
   /* set up helper data structures for rendering */
 

Modified: trunk/sushivision/panel.c
===================================================================
--- trunk/sushivision/panel.c	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/panel.c	2007-03-11 19:39:34 UTC (rev 12731)
@@ -952,39 +952,38 @@
   xmlCheckPropS(pn,"name",p->name,"Panel %d name mismatch in save file.",p->number,&warn);
 
   // background
-  u->bg_mode = xmlGetChildMap(pn, "background", "color", bgmap, p->private->bg_type,
-			      "Panel %d unknown background setting", p->number, &warn);
+  xmlGetChildMap(pn, "background", "color", bgmap, &u->bg_mode,
+		 "Panel %d unknown background setting", p->number, &warn);
   // grid
-  u->grid_mode = xmlGetChildMap(pn, "grid", "mode", gridmap, PLOT(p->private->graph)->grid_mode,
-				"Panel %d unknown grid mode setting", p->number, &warn);
+  xmlGetChildMap(pn, "grid", "mode", gridmap, &u->grid_mode,
+		 "Panel %d unknown grid mode setting", p->number, &warn);
   // crosshairs
-  u->cross_mode = xmlGetChildMap(pn, "crosshairs", "active", crossmap, PLOT(p->private->graph)->cross_active,
-				"Panel %d unknown crosshair setting", p->number, &warn);
+  xmlGetChildMap(pn, "crosshairs", "active", crossmap, &u->cross_mode,
+		 "Panel %d unknown crosshair setting", p->number, &warn);
   // legend
-  u->legend_mode = xmlGetChildMap(pn, "legend", "mode", legendmap, PLOT(p->private->graph)->legend_active,
-				"Panel %d unknown legend setting", p->number, &warn);
+  xmlGetChildMap(pn, "legend", "mode", legendmap, &u->legend_mode,
+		 "Panel %d unknown legend setting", p->number, &warn);
   // text
-  u->text_mode = xmlGetChildMap(pn, "text", "color", textmap, PLOT(p->private->graph)->bg_inv,
-				"Panel %d unknown text color setting", p->number, &warn);
+  xmlGetChildMap(pn, "text", "color", textmap, &u->text_mode,
+		 "Panel %d unknown text color setting", p->number, &warn);
   // resample
-  char *prop = xmlGetChildPropS(pn, "sampling", "ratio");
-  if(!prop){
-    u->oversample_n = p->private->def_oversample_n;
-    u->oversample_d = p->private->def_oversample_d;
-  }else{
+  char *prop = NULL;
+  xmlGetChildPropS(pn, "sampling", "ratio", &prop);
+  if(prop){
     int res = sscanf(prop,"%d:%d", &u->oversample_n, &u->oversample_d);
     if(res<2){
       fprintf(stderr,"Unable to parse sample setting (%s) for panel %d.\n",prop,p->number);
       u->oversample_n = p->private->def_oversample_n;
       u->oversample_d = p->private->def_oversample_d;
     }
+    if(u->oversample_d == 0) u->oversample_d = 1;
     xmlFree(prop);
   }
-
+  
   // subtype 
   if(p->private->load_action)
     warn = p->private->load_action(p, u, pn, warn);
-
+  
   // any unparsed elements? 
   xmlNodePtr n = pn->xmlChildrenNode;
   
@@ -995,6 +994,6 @@
     }
     n = n->next; 
   }
-  
+
   return warn;
 }

Modified: trunk/sushivision/slice.c
===================================================================
--- trunk/sushivision/slice.c	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/slice.c	2007-03-11 19:39:34 UTC (rev 12731)
@@ -23,9 +23,7 @@
 #include <math.h>
 #include <string.h>
 #include <gdk/gdkkeysyms.h>
-#include "mapping.h"
-#include "slice.h"
-#include "slider.h"
+#include "internal.h"
 
 static void draw_and_expose(GtkWidget *widget){
   Slice *s=SLICE(widget);

Modified: trunk/sushivision/slider.c
===================================================================
--- trunk/sushivision/slider.c	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/slider.c	2007-03-11 19:39:34 UTC (rev 12731)
@@ -25,9 +25,7 @@
 #include <string.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
-#include "mapping.h"
-#include "slice.h"
-#include "slider.h"
+#include "internal.h"
 
 static double val_to_pixel(Slider *s, double val);
 
@@ -115,6 +113,7 @@
 }
 
 void slider_draw_background(Slider *s){
+  slider_realize(s);
   int i;
   GtkWidget *parent=gtk_widget_get_parent(s->slices[0]);
   GdkColor *text = &s->slices[0]->style->text[0];
@@ -312,6 +311,8 @@
 }
 
 void slider_draw(Slider *s){
+  slider_realize(s);
+
   int i;
   cairo_t *c;
   //int w=s->w;

Modified: trunk/sushivision/xml.c
===================================================================
--- trunk/sushivision/xml.c	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/xml.c	2007-03-11 19:39:34 UTC (rev 12731)
@@ -28,8 +28,8 @@
 
 /* a few helpers to make specific libxml2 call patterns more concise */
 
-xmlNodePtr xmlGetChildS(xmlNodePtr n, char *name,char *prop, char *val){
-  xmlNodePtr child = n->xmlChildrenNode;
+xmlNodePtr xmlGetChildSPreserve(xmlNodePtr n, char *name,char *prop, char *val){
+  xmlNodePtr child = (n?n->xmlChildrenNode:NULL);
   while(child){
     // is this the child we want?
     if (child->type == XML_ELEMENT_NODE && !xmlStrcmp(child->name, (const xmlChar *)name)) {
@@ -39,9 +39,6 @@
 	if (!prop || !xmlStrcmp(test, (const xmlChar *)val)) {
 	  if(test)
 	    xmlFree(test);
-	  // this is what we want 
-	  // remove it from the tree
-	  xmlUnlinkNode(child);
 
 	  // return it
 	  return child;
@@ -55,12 +52,29 @@
   return NULL;
 }
 
+xmlNodePtr xmlGetChildS(xmlNodePtr n, char *name,char *prop, char *val){
+  xmlNodePtr child = (n?xmlGetChildSPreserve(n,name,prop,val):NULL);
+  if(child){
+    // this is what we want 
+    // remove it from the tree
+    xmlUnlinkNode(child);
+  }
+
+  return child;
+}
+
 xmlNodePtr xmlGetChildI(xmlNodePtr n, char *name,char *prop, int val){
   char buffer[80];
   snprintf(buffer,sizeof(buffer),"%d",val);
   return xmlGetChildS(n, name, prop, buffer);
 }
 
+xmlNodePtr xmlGetChildIPreserve(xmlNodePtr n, char *name,char *prop, int val){
+  char buffer[80];
+  snprintf(buffer,sizeof(buffer),"%d",val);
+  return xmlGetChildSPreserve(n, name, prop, buffer);
+}
+
 void xmlNewMapProp(xmlNodePtr n, char *name, propmap **map, int val){
   propmap *m = *map++;
   while(m){
@@ -89,12 +103,13 @@
     xmlNewProp(n, (xmlChar *) name, (xmlChar *)val);
 }
 
-char *xmlGetPropS(xmlNodePtr n, char *name){
-  return (char *)xmlGetProp(n, (xmlChar *)name);
+void xmlGetPropS(xmlNodePtr n, char *name, char **value){
+  char *ret = (char *)(n?xmlGetProp(n, (xmlChar *)name):NULL);
+  if(ret) *value=ret;
 }
 
 void xmlGetPropF(xmlNodePtr n, char *name, double *val){
-  xmlChar *v = xmlGetProp(n, (xmlChar *)name);
+  xmlChar *v = (n?xmlGetProp(n, (xmlChar *)name):NULL);
   if(v){
     *val = atof((char *)v);
     xmlFree(v);
@@ -102,7 +117,8 @@
 }
 
 void xmlCheckPropS(xmlNodePtr n, char *prop, char *val, char *msg, int num, int *warn){
-  char *testval = xmlGetPropS(n, prop);
+  char *testval = NULL;
+  xmlGetPropS(n, prop, &testval);
   if(testval){
     if(strcmp(val,testval)){
       first_load_warning(warn);
@@ -119,7 +135,8 @@
 
 void xmlCheckMap(xmlNodePtr n, char *prop, propmap **map, int val, char *msg, int num, int *warn){
   char *name = NULL;
-  char *testname = xmlGetPropS(n, prop);
+  char *testname = NULL;
+  xmlGetPropS(n, prop, &testname);
   
   // look up our desired value
   propmap *m = *map++;
@@ -153,62 +170,97 @@
   }
 }
 
-static int xmlGetMapVal(xmlNodePtr n, char *key, propmap **map){
-  char *valname = (char *)xmlGetProp(n, (xmlChar *)key);
-  if(!valname) return -1;
+static void xmlGetMapVal(xmlNodePtr n, char *key, propmap **map, int *out){
+  char *valname = (char *)(n?xmlGetProp(n, (xmlChar *)key):NULL);
+  if(!valname) return;
   
   propmap *m = *map++;
   while(m){
     if(!strcmp(m->left,valname)){
       xmlFree(valname);
-      return m->value;
+      *out = m->value;
+      return;
     }
     m = *map++;
   }
   xmlFree(valname);
-  return -1;
 }
 
-int xmlGetChildMap(xmlNodePtr in, char *prop, char *key, propmap **map, int default_val, 
-		   char *msg, int num, int *warn){
-  xmlNodePtr n = xmlGetChildS(in, prop, NULL, NULL);
-  if(!n)return default_val;
+void xmlGetChildMap(xmlNodePtr in, char *prop, char *key, propmap **map, int *out,
+		    char *msg, int num, int *warn){
+  xmlNodePtr n = (in?xmlGetChildS(in, prop, NULL, NULL):NULL);
+  if(!n)return;
 
   char *val = (char *)xmlGetProp(n, (xmlChar *)key);
   if(!val){
     xmlFreeNode(n);
-    return default_val;
+    return;
   }
 
-  int ret = xmlGetMapVal(n,key,map);
+  int ret = -1;
+  xmlGetMapVal(n,key,map,&ret);
   if(ret == -1){
     if(msg){
       first_load_warning(warn);
       fprintf(stderr,msg,num);
       fprintf(stderr," (%s).\n", val);
     }
-    ret = default_val;
-  }
+  }else
+    *out = ret;
 
   xmlFree(val);
   xmlFreeNode(n);
-  return ret;
 }
 
-char *xmlGetChildPropS(xmlNodePtr in, char *prop, char *key){
+void xmlGetChildPropS(xmlNodePtr in, char *prop, char *key, char **out){
+  xmlNodePtr n = (in?xmlGetChildS(in, prop, NULL, NULL):NULL);
+  if(!n)return;
+  char *val = (char *)xmlGetProp(n, (xmlChar *)key);
+  xmlFreeNode(n);
+  if(val) *out = val;
+}
 
-  xmlNodePtr n = xmlGetChildS(in, prop, NULL, NULL);
-  if(!n)return NULL;
+void xmlGetChildPropSPreserve(xmlNodePtr in, char *prop, char *key, char **out){
+  xmlNodePtr n = (in?xmlGetChildSPreserve(in, prop, NULL, NULL):NULL);
+  if(!n)return;
+  char *val = (char *)xmlGetProp(n, (xmlChar *)key);
+  if(val) *out = val;
+}
 
+void xmlGetChildPropF(xmlNodePtr in, char *prop, char *key, double *out){
+  xmlNodePtr n = (in?xmlGetChildS(in, prop, NULL, NULL):NULL);
+  if(!n)return;
   char *val = (char *)xmlGetProp(n, (xmlChar *)key);
-  if(!val){
-    xmlFreeNode(n);
-    return NULL;
-  }
-  return val;
+  xmlFreeNode(n);
+  if(val) *out = atof(val);
+  xmlFree(val);
 }
   
+void xmlGetChildPropFPreserve(xmlNodePtr in, char *prop, char *key, double *out){
+  xmlNodePtr n = (in?xmlGetChildSPreserve(in, prop, NULL, NULL):NULL);
+  if(!n)return;
+  char *val = (char *)xmlGetProp(n, (xmlChar *)key);
+  if(val) *out = atof(val);
+  xmlFree(val);
+}
 
+void xmlGetChildPropI(xmlNodePtr in, char *prop, char *key, int *out){
+  xmlNodePtr n = (in?xmlGetChildS(in, prop, NULL, NULL):NULL);
+  if(!n)return;
+  char *val = (char *)xmlGetProp(n, (xmlChar *)key);
+  xmlFreeNode(n);
+  if(val) *out = atoi(val);
+  xmlFree(val);
+}
+
+void xmlGetChildPropIPreserve(xmlNodePtr in, char *prop, char *key, int *out){
+  xmlNodePtr n = (in?xmlGetChildSPreserve(in, prop, NULL, NULL):NULL);
+  if(!n)return;
+  char *val = (char *)xmlGetProp(n, (xmlChar *)key);
+  if(val) *out = atoi(val);
+  xmlFree(val);
+}
+  
 /* convenience helpers for wielding property maps */
 int propmap_pos(propmap **map, int val){
   int i=0;

Modified: trunk/sushivision/xml.h
===================================================================
--- trunk/sushivision/xml.h	2007-03-11 14:29:07 UTC (rev 12730)
+++ trunk/sushivision/xml.h	2007-03-11 19:39:34 UTC (rev 12731)
@@ -25,13 +25,20 @@
 extern void xmlNewPropF(xmlNodePtr n, char *name, double val);
 extern void xmlNewPropI(xmlNodePtr n, char *name, int val);
 extern void xmlNewPropS(xmlNodePtr n, char *name, char *val);
-extern char *xmlGetPropS(xmlNodePtr n, char *name);
-extern void xmlGetPropF(xmlNodePtr n, char *name, double *val);
+
 extern void xmlCheckPropS(xmlNodePtr n, char *prop, char *val, char *msg, int num, int *warn);
 extern void xmlCheckMap(xmlNodePtr n, char *prop, propmap **map, int val, char *msg, int num, int *warn);
-extern int xmlGetChildMap(xmlNodePtr in, char *prop, char *key, propmap **map, int defaultval, 
+
+extern void xmlGetPropS(xmlNodePtr n, char *name, char **out);
+extern void xmlGetPropF(xmlNodePtr n, char *name, double *out);
+extern void xmlGetChildMap(xmlNodePtr in, char *prop, char *key, propmap **map, int *out,
 			  char *msg, int num, int *warn);
-extern char *xmlGetChildPropS(xmlNodePtr in, char *prop, char *key);
+extern void xmlGetChildPropS(xmlNodePtr in, char *prop, char *key, char **out);
+extern void xmlGetChildPropSPreserve(xmlNodePtr in, char *prop, char *key, char **out);
+extern void xmlGetChildPropF(xmlNodePtr in, char *prop, char *key, double *out);
+extern void xmlGetChildPropFPreserve(xmlNodePtr in, char *prop, char *key, double *out);
+extern void xmlGetChildPropI(xmlNodePtr in, char *prop, char *key, int *out);
+extern void xmlGetChildPropIPreserve(xmlNodePtr in, char *prop, char *key, int *out);
 
 extern int propmap_pos(propmap **map, int val);
 extern int propmap_last(propmap **map);



More information about the commits mailing list