From owner-p4-projects@FreeBSD.ORG Sat Jun 23 05:39:08 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 210EA16A46D; Sat, 23 Jun 2007 05:39:08 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id D31DC16A400 for ; Sat, 23 Jun 2007 05:39:07 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id C2AEF13C489 for ; Sat, 23 Jun 2007 05:39:07 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l5N5d7mY044907 for ; Sat, 23 Jun 2007 05:39:07 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l5N5d7T7044904 for perforce@freebsd.org; Sat, 23 Jun 2007 05:39:07 GMT (envelope-from andrew@freebsd.org) Date: Sat, 23 Jun 2007 05:39:07 GMT Message-Id: <200706230539.l5N5d7T7044904@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andrew@freebsd.org using -f From: Andrew Turner To: Perforce Change Reviews Cc: Subject: PERFORCE change 122185 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Jun 2007 05:39:08 -0000 http://perforce.freebsd.org/chv.cgi?CH=122185 Change 122185 by andrew@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, + "%s", + 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; };