Commit 4d6b096c authored by Alejandro Mery's avatar Alejandro Mery
Browse files

script: renamed script_*_entry_append() to _new() and changed to receive the...

script: renamed script_*_entry_append() to _new() and changed to receive the section instead of the script
parent bdd5abdb
...@@ -92,22 +92,17 @@ void script_section_delete(struct script_section *section) ...@@ -92,22 +92,17 @@ void script_section_delete(struct script_section *section)
/* /*
*/ */
static inline void script_entry_append(struct script *script, static inline void script_entry_append(struct script_section *section,
struct script_entry *entry, struct script_entry *entry,
enum script_value_type type, enum script_value_type type,
const char *name) const char *name)
{ {
size_t l; size_t l;
struct script_section *section;
assert(script); assert(section);
assert(!list_empty(&script->sections));
assert(entry); assert(entry);
assert(name); assert(name);
section = container_of(list_last(&script->sections),
struct script_section, sections);
l = strlen(name); l = strlen(name);
if (l>31) /* truncate */ if (l>31) /* truncate */
l=31; l=31;
...@@ -152,51 +147,48 @@ void script_entry_delete(struct script_entry *entry) ...@@ -152,51 +147,48 @@ void script_entry_delete(struct script_entry *entry)
free(container); free(container);
} }
struct script_null_entry *script_null_entry_append(struct script *script, struct script_null_entry *script_null_entry_new(struct script_section *section,
const char *name) const char *name)
{ {
struct script_null_entry *entry; struct script_null_entry *entry;
assert(script); assert(section);
assert(!list_empty(&script->sections));
assert(name && *name); assert(name && *name);
if ((entry = malloc(sizeof(*entry)))) { if ((entry = malloc(sizeof(*entry)))) {
script_entry_append(script, &entry->entry, script_entry_append(section, &entry->entry,
SCRIPT_VALUE_TYPE_NULL, name); SCRIPT_VALUE_TYPE_NULL, name);
} }
return entry; return entry;
} }
struct script_single_entry *script_single_entry_append(struct script *script, struct script_single_entry *script_single_entry_new(struct script_section *section,
const char *name, const char *name,
uint32_t value) uint32_t value)
{ {
struct script_single_entry *entry; struct script_single_entry *entry;
assert(script); assert(section);
assert(!list_empty(&script->sections));
assert(name && *name); assert(name && *name);
if ((entry = malloc(sizeof(*entry)))) { if ((entry = malloc(sizeof(*entry)))) {
entry->value = value; entry->value = value;
script_entry_append(script, &entry->entry, script_entry_append(section, &entry->entry,
SCRIPT_VALUE_TYPE_SINGLE_WORD, name); SCRIPT_VALUE_TYPE_SINGLE_WORD, name);
} }
return entry; return entry;
} }
struct script_string_entry *script_string_entry_append(struct script *script, struct script_string_entry *script_string_entry_new(struct script_section *section,
const char *name, const char *name,
size_t l, const char *s) size_t l, const char *s)
{ {
struct script_string_entry *entry; struct script_string_entry *entry;
assert(script); assert(section);
assert(!list_empty(&script->sections));
assert(name); assert(name);
assert(s); assert(s);
...@@ -205,22 +197,21 @@ struct script_string_entry *script_string_entry_append(struct script *script, ...@@ -205,22 +197,21 @@ struct script_string_entry *script_string_entry_append(struct script *script,
memcpy(entry->string, s, l); memcpy(entry->string, s, l);
entry->string[l] = '\0'; entry->string[l] = '\0';
script_entry_append(script, &entry->entry, script_entry_append(section, &entry->entry,
SCRIPT_VALUE_TYPE_STRING, name); SCRIPT_VALUE_TYPE_STRING, name);
} }
return entry; return entry;
} }
struct script_gpio_entry *script_gpio_entry_append(struct script *script, struct script_gpio_entry *script_gpio_entry_new(struct script_section *section,
const char *name, const char *name,
unsigned port, unsigned num, unsigned port, unsigned num,
unsigned data[4]) unsigned data[4])
{ {
struct script_gpio_entry *entry; struct script_gpio_entry *entry;
assert(script); assert(section);
assert(!list_empty(&script->sections));
assert(name && *name); assert(name && *name);
if ((entry = malloc(sizeof(*entry)))) { if ((entry = malloc(sizeof(*entry)))) {
...@@ -229,7 +220,7 @@ struct script_gpio_entry *script_gpio_entry_append(struct script *script, ...@@ -229,7 +220,7 @@ struct script_gpio_entry *script_gpio_entry_append(struct script *script,
for (int i=0; i<4; i++) for (int i=0; i<4; i++)
entry->data[i] = data[i]; entry->data[i] = data[i];
script_entry_append(script, &entry->entry, script_entry_append(section, &entry->entry,
SCRIPT_VALUE_TYPE_GPIO, name); SCRIPT_VALUE_TYPE_GPIO, name);
} }
......
...@@ -89,21 +89,21 @@ void script_section_delete(struct script_section *section); ...@@ -89,21 +89,21 @@ void script_section_delete(struct script_section *section);
/** deletes an entry and removes it from the section */ /** deletes an entry and removes it from the section */
void script_entry_delete(struct script_entry *entry); 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 a section */
struct script_null_entry *script_null_entry_append(struct script *script, struct script_null_entry *script_null_entry_new(struct script_section *section,
const char *name); const char *name);
/** create a new single word entry appended to the last section of a tree */ /** create a new single word entry appended to a section */
struct script_single_entry *script_single_entry_append(struct script *script, struct script_single_entry *script_single_entry_new(struct script_section *section,
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 */ /** create a new string entry appended to a section */
struct script_string_entry *script_string_entry_append(struct script *script, struct script_string_entry *script_string_entry_new(struct script_section *section,
const char *name, const char *name,
size_t l, const char *s); size_t l, const char *s);
/** create a new GPIO entry appended to the last section of a tree */ /** create a new GPIO entry appended to a section */
struct script_gpio_entry *script_gpio_entry_append(struct script *script, struct script_gpio_entry *script_gpio_entry_new(struct script_section *script,
const char *name, const char *name,
unsigned port, unsigned num, unsigned port, unsigned num,
unsigned data[4]); unsigned data[4]);
#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