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

script: implement script_single_entry_append()

parent fa39a095
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "sunxi-tools.h" #include "sunxi-tools.h"
#include <stdint.h>
#include "script.h" #include "script.h"
#endif #endif
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "sunxi-tools.h" #include "sunxi-tools.h"
#include <assert.h> #include <assert.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -123,12 +124,16 @@ void script_entry_delete(struct script_entry *entry) ...@@ -123,12 +124,16 @@ void script_entry_delete(struct script_entry *entry)
void *container; void *container;
assert(entry); 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)) if (!list_empty(&entry->entries))
list_remove(&entry->entries); list_remove(&entry->entries);
switch(entry->type) { switch(entry->type) {
case SCRIPT_VALUE_TYPE_SINGLE_WORD:
container = container_of(entry, struct script_single_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;
...@@ -155,3 +160,23 @@ struct script_null_entry *script_null_entry_append(struct script *script, ...@@ -155,3 +160,23 @@ struct script_null_entry *script_null_entry_append(struct script *script,
return entry; 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 { ...@@ -52,6 +52,13 @@ struct script_null_entry {
struct script_entry 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 */ /** create a new script tree */
struct script *script_new(void); struct script *script_new(void);
/** deletes a tree recursively */ /** deletes a tree recursively */
...@@ -69,5 +76,9 @@ void script_entry_delete(struct script_entry *entry); ...@@ -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 */ /** 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, struct script_null_entry *script_null_entry_append(struct script *script,
const char *name); 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 #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