Commit 05a2d8f7 authored by Alejandro Mery's avatar Alejandro Mery
Browse files

script: implement script_single_entry_append()

parent fa39a095
......@@ -19,6 +19,8 @@
#include "sunxi-tools.h"
#include <stdint.h>
#include "script.h"
#endif
......@@ -18,6 +18,7 @@
#include "sunxi-tools.h"
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
......@@ -123,12 +124,16 @@ void script_entry_delete(struct script_entry *entry)
void *container;
assert(entry);
assert(entry->type == SCRIPT_VALUE_TYPE_NULL);
assert(entry->type == SCRIPT_VALUE_TYPE_SINGLE_WORD ||
entry->type == SCRIPT_VALUE_TYPE_NULL);
if (!list_empty(&entry->entries))
list_remove(&entry->entries);
switch(entry->type) {
case SCRIPT_VALUE_TYPE_SINGLE_WORD:
container = container_of(entry, struct script_single_entry, entry);
break;
case SCRIPT_VALUE_TYPE_NULL:
container = container_of(entry, struct script_null_entry, entry);
break;
......@@ -155,3 +160,23 @@ struct script_null_entry *script_null_entry_append(struct script *script,
return entry;
}
struct script_single_entry *script_single_entry_append(struct script *script,
const char *name,
uint32_t value)
{
struct script_single_entry *entry;
assert(script);
assert(!list_empty(&script->sections));
assert(name && *name);
if ((entry = malloc(sizeof(*entry)))) {
entry->value = value;
script_entry_append(script, &entry->entry,
SCRIPT_VALUE_TYPE_SINGLE_WORD, name);
}
return entry;
}
......@@ -52,6 +52,13 @@ struct script_null_entry {
struct script_entry entry;
};
/** entry with 32b value */
struct script_single_entry {
struct script_entry entry;
uint32_t value;
};
/** create a new script tree */
struct script *script_new(void);
/** deletes a tree recursively */
......@@ -69,5 +76,9 @@ void script_entry_delete(struct script_entry *entry);
/** create a new empty/null entry appended to the last section of a tree */
struct script_null_entry *script_null_entry_append(struct script *script,
const char *name);
/** create a new single word entry appended to the last section of a tree */
struct script_single_entry *script_single_entry_append(struct script *script,
const char *name,
uint32_t value);
#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