PERFORCE change 122185 for review
Andrew Turner
andrew at FreeBSD.org
Sat Jun 23 05:39:08 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=122185
Change 122185 by andrew at andrew_hermies on 2007/06/23 05:38:41
Add facund_object_xml_string to get an XML string containing the data to send to the front end
Affected files ...
.. //depot/projects/soc2007/andrew-update/lib/facund_object.c#4 edit
.. //depot/projects/soc2007/andrew-update/lib/facund_object.h#3 edit
.. //depot/projects/soc2007/andrew-update/lib/facund_private.h#5 edit
Differences ...
==== //depot/projects/soc2007/andrew-update/lib/facund_object.c#4 (text+ko) ====
@@ -33,6 +33,8 @@
#include "facund_object.h"
#include "facund_private.h"
+static const char *obj_names[] = { "bool", "int", "unsigned int", "string",
+ "array" };
static struct facund_object *facund_object_new(void);
/* Internal function to create an empty facund_object */
@@ -313,6 +315,9 @@
free(obj->obj_array);
}
+ if (obj->obj_xml_string != NULL)
+ free(obj->obj_xml_string);
+
free(obj);
}
@@ -386,6 +391,64 @@
return obj->obj_error;
}
+const char *
+facund_object_xml_string(struct facund_object *obj __unused)
+{
+ if (obj == NULL)
+ return NULL;
+
+ if (obj->obj_xml_string == NULL) {
+ char *data;
+
+ assert(obj->obj_assigned == 1);
+
+ data = NULL;
+ switch (obj->obj_type) {
+ case FACUND_BOOL:
+ asprintf(&data, "%s",
+ (facund_object_get_bool(obj) ? "true" : "false"));
+ break;
+ case FACUND_INT:
+ asprintf(&data, "%d", facund_object_get_int(obj));
+ break;
+ case FACUND_UINT:
+ asprintf(&data, "%u", facund_object_get_uint(obj));
+ break;
+ case FACUND_STRING:
+ data = strdup(facund_object_get_string(obj));
+ break;
+ case FACUND_ARRAY: {
+ size_t pos;
+
+ for (pos = 0; pos < obj->obj_array_count; pos++) {
+ struct facund_object *curobj;
+ const char *tmpdata;
+ char *olddata;
+
+ curobj = __DECONST(struct facund_object *,
+ facund_object_get_array_item(obj, pos));
+ tmpdata = facund_object_xml_string(curobj);
+
+ /* Append the new data to the end of the data */
+ olddata = data;
+ asprintf(&data, "%s%s", data, tmpdata);
+ free(olddata);
+ }
+
+ break;
+ }
+ }
+ if (data != NULL) {
+ asprintf(&obj->obj_xml_string,
+ "<data type=\"%s\">%s</data>",
+ obj_names[obj->obj_type], data);
+ free(data);
+ }
+ }
+
+ return obj->obj_xml_string;
+}
+
/*
* Debugging function to print the type and contents of an object
* If the object is an array it will also recurse into the array
@@ -393,8 +456,6 @@
void
facund_object_print(struct facund_object *obj)
{
- static const char *obj_names[] = { "bool", "int", "unsigned int",
- "string", "array" };
unsigned int depth;
if (obj == NULL) {
==== //depot/projects/soc2007/andrew-update/lib/facund_object.h#3 (text+ko) ====
@@ -79,6 +79,7 @@
const char *);
enum facund_object_error facund_object_get_error(struct facund_object*);
+const char *facund_object_xml_string(struct facund_object *);
void facund_object_print(struct facund_object *);
#endif /*FACUND_TYPE_H */
==== //depot/projects/soc2007/andrew-update/lib/facund_private.h#5 (text+ko) ====
@@ -48,6 +48,8 @@
struct facund_object **obj_array;/* Used in array type */
size_t obj_array_count;
+ char *obj_xml_string;
+
/* Used for indenting arrays */
unsigned int obj_depth;
};
More information about the p4-projects
mailing list