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