[packages] ezxml: clean patch headers and new ezxml_cut patch
[openwrt/svn-archive/archive.git] / libs / ezxml / patches / 300-ezxml_int.patch
1 --- a/ezxml.c
2 +++ b/ezxml.c
3 @@ -25,6 +25,7 @@
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <stdarg.h>
7 +#include <errno.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include <unistd.h>
11 @@ -72,6 +73,19 @@ ezxml_t ezxml_idx(ezxml_t xml, int idx)
12 return xml;
13 }
14
15 +int ezxml_int(ezxml_t xml, int default_value)
16 +{
17 + int ret;
18 +
19 + if(!xml)
20 + return default_value;
21 +
22 + errno = 0;
23 + ret = strtol(xml->txt, NULL, 10);
24 +
25 + return (errno == 0 ? ret : default_value);
26 +}
27 +
28 // returns the value of the requested tag attribute or NULL if not found
29 const char *ezxml_attr(ezxml_t xml, const char *attr)
30 {
31 @@ -89,6 +103,23 @@ const char *ezxml_attr(ezxml_t xml, cons
32 return (root->attr[i][j]) ? root->attr[i][j + 1] : NULL; // found default
33 }
34
35 +int ezxml_attr_int(ezxml_t xml, const char *attr, int default_value)
36 +{
37 + int ret;
38 + const char *val = NULL;
39 +
40 + if(!xml)
41 + return default_value;
42 +
43 + if((val = ezxml_attr(xml, attr)) == NULL)
44 + return default_value;
45 +
46 + errno = 0;
47 + ret = strtol(val, NULL, 10);
48 +
49 + return (errno == 0 ? ret : default_value);
50 +}
51 +
52 // same as ezxml_get but takes an already initialized va_list
53 ezxml_t ezxml_vget(ezxml_t xml, va_list ap)
54 {
55 @@ -926,6 +957,16 @@ ezxml_t ezxml_set_txt(ezxml_t xml, const
56 return xml;
57 }
58
59 +ezxml_t ezxml_set_int(ezxml_t xml, int data)
60 +{
61 + char *buf = NULL;
62 + if (! xml) return NULL;
63 +
64 + asprintf(&buf, "%d", data);
65 +
66 + return ezxml_set_flag(ezxml_set_txt(xml, buf), EZXML_TXTM);
67 +}
68 +
69 // Sets the given tag attribute or adds a new attribute if not found. A value
70 // of NULL will remove the specified attribute. Returns the tag given.
71 ezxml_t ezxml_set_attr(ezxml_t xml, const char *name, const char *value)
72 @@ -968,6 +1009,15 @@ ezxml_t ezxml_set_attr(ezxml_t xml, cons
73 return xml;
74 }
75
76 +ezxml_t ezxml_set_attr_int(ezxml_t xml, const char *name, int data)
77 +{
78 + char *buf = NULL;
79 + if (! xml) return NULL;
80 +
81 + asprintf(&buf, "%d", data);
82 + return ezxml_set_attr(ezxml_set_flag(xml, EZXML_DUP), name, buf);
83 +}
84 +
85 // sets a flag for the given tag and returns the tag
86 ezxml_t ezxml_set_flag(ezxml_t xml, short flag)
87 {
88 --- a/ezxml.h
89 +++ b/ezxml.h
90 @@ -95,9 +95,13 @@ ezxml_t ezxml_idx(ezxml_t xml, int idx);
91 // returns the given tag's character content or empty string if none
92 #define ezxml_txt(xml) ((xml) ? xml->txt : "")
93
94 +int ezxml_int(ezxml_t xml, int default_value);
95 +
96 // returns the value of the requested tag attribute, or NULL if not found
97 const char *ezxml_attr(ezxml_t xml, const char *attr);
98
99 +int ezxml_attr_int(ezxml_t xml, const char *attr, int default_value);
100 +
101 // Traverses the ezxml sturcture to retrieve a specific subtag. Takes a
102 // variable length list of tag names and indexes. The argument list must be
103 // terminated by either an index of -1 or an empty string tag name. Example:
104 @@ -137,6 +141,9 @@ ezxml_t ezxml_add_child(ezxml_t xml, con
105 // sets the character content for the given tag and returns the tag
106 ezxml_t ezxml_set_txt(ezxml_t xml, const char *txt);
107
108 +// set int value
109 +ezxml_t ezxml_set_int(ezxml_t xml, int data);
110 +
111 // wrapper for ezxml_set_txt() that strdup()s txt
112 #define ezxml_set_txt_d(xml, txt) \
113 ezxml_set_flag(ezxml_set_txt(xml, strdup(txt)), EZXML_TXTM)
114 @@ -144,6 +151,9 @@ ezxml_t ezxml_set_txt(ezxml_t xml, const
115 // Sets the given tag attribute or adds a new attribute if not found. A value
116 // of NULL will remove the specified attribute. Returns the tag given.
117 ezxml_t ezxml_set_attr(ezxml_t xml, const char *name, const char *value);
118 +
119 +// set int value for an attr
120 +ezxml_t ezxml_set_attr_int(ezxml_t xml, const char *name, int data);
121
122 // Wrapper for ezxml_set_attr() that strdup()s name/value. Value cannot be NULL
123 #define ezxml_set_attr_d(xml, name, value) \