Commit 33d67b72 authored by Alejandro Mery's avatar Alejandro Mery
Browse files

script: implemented script_string_entry_append()

parent 05a2d8f7
...@@ -125,6 +125,7 @@ void script_entry_delete(struct script_entry *entry) ...@@ -125,6 +125,7 @@ void script_entry_delete(struct script_entry *entry)
assert(entry); assert(entry);
assert(entry->type == SCRIPT_VALUE_TYPE_SINGLE_WORD || assert(entry->type == SCRIPT_VALUE_TYPE_SINGLE_WORD ||
entry->type == SCRIPT_VALUE_TYPE_STRING ||
entry->type == SCRIPT_VALUE_TYPE_NULL); entry->type == SCRIPT_VALUE_TYPE_NULL);
if (!list_empty(&entry->entries)) if (!list_empty(&entry->entries))
...@@ -134,6 +135,9 @@ void script_entry_delete(struct script_entry *entry) ...@@ -134,6 +135,9 @@ void script_entry_delete(struct script_entry *entry)
case SCRIPT_VALUE_TYPE_SINGLE_WORD: case SCRIPT_VALUE_TYPE_SINGLE_WORD:
container = container_of(entry, struct script_single_entry, entry); container = container_of(entry, struct script_single_entry, entry);
break; break;
case SCRIPT_VALUE_TYPE_STRING:
container = container_of(entry, struct script_string_entry, entry);
break;
case SCRIPT_VALUE_TYPE_NULL: case SCRIPT_VALUE_TYPE_NULL:
container = container_of(entry, struct script_null_entry, entry); container = container_of(entry, struct script_null_entry, entry);
break; break;
...@@ -180,3 +184,26 @@ struct script_single_entry *script_single_entry_append(struct script *script, ...@@ -180,3 +184,26 @@ struct script_single_entry *script_single_entry_append(struct script *script,
return entry; 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;
}
...@@ -59,6 +59,14 @@ struct script_single_entry { ...@@ -59,6 +59,14 @@ struct script_single_entry {
uint32_t value; 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 */ /** create a new script tree */
struct script *script_new(void); struct script *script_new(void);
/** deletes a tree recursively */ /** deletes a tree recursively */
...@@ -80,5 +88,9 @@ struct script_null_entry *script_null_entry_append(struct script *script, ...@@ -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, struct script_single_entry *script_single_entry_append(struct script *script,
const char *name, const char *name,
uint32_t value); 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 #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment