00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <gimp-print/mxml.h>
00029 #include "config.h"
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 const char *
00040 stp_mxmlElementGetAttr(stp_mxml_node_t *node,
00041 const char *name)
00042 {
00043 int i;
00044 stp_mxml_attr_t *attr;
00045
00046
00047
00048
00049
00050
00051 if (!node || node->type != STP_MXML_ELEMENT || !name)
00052 return (NULL);
00053
00054
00055
00056
00057
00058 for (i = node->value.element.num_attrs, attr = node->value.element.attrs;
00059 i > 0;
00060 i --, attr ++)
00061 if (!strcmp(attr->name, name))
00062 return (attr->value);
00063
00064
00065
00066
00067
00068 return (NULL);
00069 }
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 void
00082 stp_mxmlElementSetAttr(stp_mxml_node_t *node,
00083 const char *name,
00084 const char *value)
00085 {
00086 int i;
00087 stp_mxml_attr_t *attr;
00088
00089
00090
00091
00092
00093
00094 if (!node || node->type != STP_MXML_ELEMENT || !name || !value)
00095 return;
00096
00097
00098
00099
00100
00101 for (i = node->value.element.num_attrs, attr = node->value.element.attrs;
00102 i > 0;
00103 i --, attr ++)
00104 if (!strcmp(attr->name, name))
00105 {
00106
00107
00108
00109
00110 free(attr->value);
00111
00112 attr->value = strdup(value);
00113
00114 return;
00115 }
00116
00117
00118
00119
00120
00121 if (node->value.element.num_attrs == 0)
00122 attr = malloc(sizeof(stp_mxml_attr_t));
00123 else
00124 attr = realloc(node->value.element.attrs,
00125 (node->value.element.num_attrs + 1) * sizeof(stp_mxml_attr_t));
00126
00127 if (!attr)
00128 {
00129 fprintf(stderr, "Unable to allocate memory for attribute '%s' in element %s!\n",
00130 name, node->value.element.name);
00131 return;
00132 }
00133
00134 node->value.element.attrs = attr;
00135 attr += node->value.element.num_attrs;
00136
00137 attr->name = strdup(name);
00138 attr->value = strdup(value);
00139
00140 if (!attr->name || !attr->value)
00141 {
00142 if (attr->name)
00143 free(attr->name);
00144
00145 if (attr->value)
00146 free(attr->value);
00147
00148 fprintf(stderr, "Unable to allocate memory for attribute '%s' in element %s!\n",
00149 name, node->value.element.name);
00150
00151 return;
00152 }
00153
00154 node->value.element.num_attrs ++;
00155 }
00156
00157
00158
00159
00160