4 #include <rpm/rpmstring.h>
10 rpmtd td = xmalloc(sizeof(*td));
15 rpmtd rpmtdFree(rpmtd td)
17 /* permit free on NULL td */
19 /* XXX should we free data too - a flag maybe? */
25 void rpmtdReset(rpmtd td)
29 memset(td, 0, sizeof(*td));
33 void rpmtdFreeData(rpmtd td)
43 rpm_count_t rpmtdCount(rpmtd td)
49 rpmTag rpmtdTag(rpmtd td)
55 rpmTagType rpmtdType(rpmtd td)
61 int rpmtdInit(rpmtd td)
65 /* XXX check that this is an array type? */
70 int rpmtdNext(rpmtd td)
76 if (td->ix < td->count) {
85 uint16_t * rpmtdGetUint16(rpmtd td)
91 if (td->type == RPM_INT16_TYPE) {
92 int ix = (td->ix >= 0 ? td->ix : 0);
93 res = (uint16_t *) td->data + ix;
98 uint32_t * rpmtdGetUint32(rpmtd td)
100 uint32_t *res = NULL;
104 if (td->type == RPM_INT32_TYPE) {
105 int ix = (td->ix >= 0 ? td->ix : 0);
106 res = (uint32_t *) td->data + ix;
110 const char * rpmtdGetString(rpmtd td)
112 const char *str = NULL;
116 if (td->type == RPM_STRING_TYPE) {
117 str = (const char *) td->data;
118 } else if (td->type == RPM_STRING_ARRAY_TYPE ||
119 td->type == RPM_I18NSTRING_TYPE) {
120 /* XXX TODO: check for array bounds */
121 int ix = (td->ix >= 0 ? td->ix : 0);
122 str = *((const char**) td->data + ix);
127 char *rpmtdToString(rpmtd td)
132 case RPM_STRING_TYPE:
133 case RPM_I18NSTRING_TYPE:
134 case RPM_STRING_ARRAY_TYPE: {
135 const char *s = rpmtdGetString(td);
141 case RPM_INT16_TYPE: {
142 uint16_t *num = rpmtdGetUint16(td);
144 rasprintf(&res, "%hd", *num);
148 case RPM_INT32_TYPE: {
149 uint32_t *num = rpmtdGetUint32(td);
151 rasprintf(&res, "%d", *num);
156 /* XXX TODO: convert to hex presentation */
164 int rpmtdFromArgv(rpmtd td, rpmTag tag, ARGV_t argv)
166 int count = argvCount(argv);
167 rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
169 if (type != RPM_STRING_ARRAY_TYPE || count < 1)
181 int rpmtdFromArgi(rpmtd td, rpmTag tag, ARGI_t argi)
183 int count = argiCount(argi);
184 rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
185 rpmTagReturnType retype = rpmTagGetType(tag) & RPM_MASK_RETURN_TYPE;
187 if (type != RPM_INT32_TYPE || retype != RPM_ARRAY_RETURN_TYPE || count < 1)
195 td->data = argiData(argi);