script: implemented script_string_entry_append()

This commit is contained in:
Alejandro Mery 2012-05-04 14:49:32 +02:00
parent 05a2d8f70a
commit 33d67b7288
2 changed files with 39 additions and 0 deletions

View File

@ -125,6 +125,7 @@ void script_entry_delete(struct script_entry *entry)
assert(entry);
assert(entry->type == SCRIPT_VALUE_TYPE_SINGLE_WORD ||
entry->type == SCRIPT_VALUE_TYPE_STRING ||
entry->type == SCRIPT_VALUE_TYPE_NULL);
if (!list_empty(&entry->entries))
@ -134,6 +135,9 @@ void script_entry_delete(struct script_entry *entry)
case SCRIPT_VALUE_TYPE_SINGLE_WORD:
container = container_of(entry, struct script_single_entry, entry);
break;
case SCRIPT_VALUE_TYPE_STRING:
container = container_of(entry, struct script_string_entry, entry);
break;
case SCRIPT_VALUE_TYPE_NULL:
container = container_of(entry, struct script_null_entry, entry);
break;
@ -180,3 +184,26 @@ struct script_single_entry *script_single_entry_append(struct script *script,
return entry;
}
struct script_string_entry *script_string_entry_append(struct script *script,
const char *name,
size_t l, const char *s)
{
struct script_string_entry *entry;
assert(script);
assert(!list_empty(&script->sections));
assert(name && *name);
assert(s);
if ((entry = malloc(sizeof(*entry)+l+1))) {
entry->l = l;
memcpy(entry->string, s, l);
entry->string[l] = '\0';
script_entry_append(script, &entry->entry,
SCRIPT_VALUE_TYPE_STRING, name);
}
return entry;
}

View File

@ -59,6 +59,14 @@ struct script_single_entry {
uint32_t value;
};
/** entry with string value */
struct script_string_entry {
struct script_entry entry;
size_t l;
char string[];
};
/** create a new script tree */
struct script *script_new(void);
/** deletes a tree recursively */
@ -80,5 +88,9 @@ struct script_null_entry *script_null_entry_append(struct script *script,
struct script_single_entry *script_single_entry_append(struct script *script,
const char *name,
uint32_t value);
/** create a new string entry appended to the last section of a tree */
struct script_string_entry *script_string_entry_append(struct script *script,
const char *name,
size_t l, const char *s);
#endif