script: implemented script_string_entry_append()
This commit is contained in:
parent
05a2d8f70a
commit
33d67b7288
27
script.c
27
script.c
@ -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;
|
||||
}
|
||||
|
||||
12
script.h
12
script.h
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user