62 #include <amxc/amxc.h>
63 #include <amxp/amxp.h>
73 const char* token,
bool* quotes,
bool* sb,
bool* cb) {
78 amxc_string_appendf(path_part,
"%s", token);
79 (*quotes) = !(*quotes);
82 amxc_string_appendf(path_part,
"%s", token);
84 amxc_var_add(cstring_t, path_parts, amxc_string_get(path_part, 0));
85 amxc_string_reset(path_part);
92 amxc_string_appendf(path_part,
"%s", token);
95 amxc_string_appendf(path_part,
"%s", token);
97 amxc_var_add(cstring_t, path_parts, amxc_string_get(path_part, 0));
98 amxc_string_reset(path_part);
104 amxc_string_appendf(path_part,
"%s", token);
107 amxc_string_appendf(path_part,
"%s", token);
108 amxc_var_add(cstring_t, path_parts, amxc_string_get(path_part, 0));
109 amxc_string_reset(path_part);
113 amxc_string_appendf(path_part,
"%s", token);
114 dot = !(*quotes) && !(*sb);
118 if(!(*quotes) && !(*sb)) {
119 amxc_var_add(cstring_t, path_parts, amxc_string_get(path_part, 0));
120 amxc_string_reset(path_part);
121 amxc_string_appendf(path_part,
"%s", token);
122 dot = !(*quotes) && !(*sb);
126 amxc_string_appendf(path_part,
"%s", token);
133 amxc_var_t* path_parts) {
137 amxc_string_t path_part;
139 amxc_var_set_type(path_parts, AMXC_VAR_ID_LIST);
141 amxc_string_init(&path_part, 0);
142 amxc_llist_for_each(it, all) {
143 amxc_string_t* part = amxc_string_from_llist_it(it);
144 const char* txt_part = amxc_string_get(part, 0);
145 if(amxc_string_text_length(part) == 1) {
147 amxc_var_add(cstring_t, path_parts, amxc_string_get(&path_part, 0));
148 amxc_string_reset(&path_part);
151 amxc_string_appendf(&path_part,
"%s", txt_part);
154 if(amxc_string_text_length(&path_part) > 0) {
155 amxc_var_add(cstring_t, path_parts, amxc_string_get(&path_part, 0));
157 amxc_string_clean(&path_part);
158 return AMXC_STRING_SPLIT_OK;
162 bool has_supported =
false;
163 bool has_search =
false;
164 bool has_ref_index =
false;
169 amxc_var_for_each(part, (&path->
parts)) {
170 const char* path_str = amxc_var_constcast(cstring_t, part);
173 path->
ref_index = labs(strtol(path_str, &endptr, 0));
174 when_true_status(((errno == ERANGE) && ((path->
ref_index == 0) || (path->
ref_index == ULONG_MAX))) ||
175 ((errno != 0) && (path->
ref_index == 0)),
178 when_true_status((endptr == path_str) || (*endptr !=
'\0'),
181 has_ref_index =
false;
184 switch(path_str[0]) {
186 if(strncmp(path_str,
"{i}", 3) != 0) {
190 has_supported =
true;
206 has_ref_index =
true;
211 if(path->
param != NULL) {
212 if((path->
param[0] ==
'{') && has_search) {
218 if(has_supported && !has_search) {
220 }
else if(!has_supported && has_search) {
222 }
else if(has_supported && has_search) {
234 amxc_llist_it_t* last = amxc_llist_get_last(&path->
parts.data.vl);
235 amxc_var_t* last_part = amxc_var_from_llist_it(last);
236 const char* name = amxc_var_constcast(cstring_t, last_part);
239 when_str_empty(name, exit);
240 length = strlen(name);
242 if(name[length - 1] !=
'.') {
243 path->
param = amxc_var_take(cstring_t, last_part);
245 if(path->
param[0] ==
'[') {
247 amxc_var_push(cstring_t, last_part, path->
param);
252 amxc_llist_it_take(last);
254 if(amxc_llist_is_empty(&path->
parts.data.vl)) {
255 amxc_var_set(cstring_t, last_part,
".");
256 amxc_llist_append(&path->
parts.data.vl, last);
258 amxc_var_delete(&last_part);
261 amxc_string_reset(&path->
path);
262 amxc_string_join_var(&path->
path, &path->
parts,
"");
270 amxc_string_split_builder_t fn) {
273 amxc_var_set_type(&path->
parts, AMXC_VAR_ID_LIST);
274 when_true_status(amxc_string_is_empty(&path->
path),
282 if(amxc_string_split(&path->
path,
285 &path->
reason) != AMXC_STRING_SPLIT_OK) {
287 amxc_var_clean(&path->
parts);
297 return (c ==
'.') ? 1 : 0;
301 if(!amxc_string_is_empty(&path->
path) && add_dot) {
302 if(path->
path.buffer[path->
path.last_used - 1] !=
'.') {
303 amxc_string_append(&path->
path,
".", 1);
310 if((path->
path.last_used > 0) &&
311 ( path->
path.buffer[path->
path.last_used - 1] ==
'*')) {
329 const char* object_path) {
332 when_null(path, exit);
334 amxc_var_init(&path->
parts);
335 amxc_var_set_type(&path->
parts, AMXC_VAR_ID_LIST);
337 amxc_string_init(&path->
path, 0);
341 if(object_path != NULL) {
342 when_failed(amxc_string_setf(&path->
path,
"%s", object_path), exit);
352 when_null(path, exit);
354 amxc_var_clean(&path->
parts);
355 amxc_string_clean(&path->
path);
366 const char* object_path) {
369 when_null(path, exit);
379 when_null(path, exit);
390 when_null(path, exit);
392 amxc_string_reset(&path->
path);
393 amxc_var_clean(&path->
parts);
405 const char* obj_path,
409 when_null(path, exit);
410 when_str_empty(obj_path, exit);
414 amxc_string_vsetf(&path->
path, obj_path, args);
426 const char* obj_path, ...) {
430 when_null(path, exit);
431 when_str_empty(obj_path, exit);
433 va_start(args, obj_path);
444 when_null(path, exit);
445 when_str_empty(extension, exit);
447 amxc_string_appendf(&path->
path,
"%s", extension);
459 when_null(path, exit);
460 when_str_empty(extension, exit);
462 amxc_string_prependf(&path->
path,
"%s", extension);
472 const char* obj_path = NULL;
474 when_null(path, exit)
475 when_true(amxc_string_is_empty(&path->
path), exit);
477 length = amxc_string_text_length(&path->
path);
478 obj_path = amxc_string_get(&path->
path, 0);
481 if(obj_path[length - 1] !=
'.') {
482 amxc_string_append(&path->
path,
".", 1);
488 obj_path = amxc_string_get(&path->
path, 0);
491 if(obj_path == NULL) {
498 return path == NULL ? NULL : path->
param;
502 amxc_string_t first_part;
504 amxc_var_t* path_part = NULL;
506 const char* path_str = NULL;
507 amxc_string_init(&first_part, 0);
509 when_null(path, exit);
510 when_true(amxc_llist_is_empty(&path->
parts.data.vl), exit);
512 path_part = amxc_var_from_llist_it(amxc_llist_get_first(&path->
parts.data.vl));
513 path_str = amxc_var_constcast(cstring_t, path_part);
514 length = strlen(path_str);
515 amxc_string_append(&first_part, path_str, length);
517 amxc_var_delete(&path_part);
521 amxc_string_reset(&path->
path);
522 amxc_string_join_var(&path->
path, &path->
parts,
"");
526 first = amxc_string_take_buffer(&first_part);
527 amxc_string_clean(&first_part);
532 amxc_string_t last_part;
534 amxc_var_t* path_part = NULL;
536 const char* path_str = NULL;
537 amxc_string_init(&last_part, 0);
539 when_null(path, exit);
540 when_true(amxc_llist_is_empty(&path->
parts.data.vl), exit);
542 path_part = amxc_var_from_llist_it(amxc_llist_get_last(&path->
parts.data.vl));
543 path_str = amxc_var_constcast(cstring_t, path_part);
544 length = strlen(path_str);
545 amxc_string_prepend(&last_part, path_str, length);
547 if(path_str[0] ==
'.') {
548 amxc_llist_it_t* prev = NULL;
550 amxc_var_delete(&path_part);
551 prev = amxc_llist_get_last(&path->
parts.data.vl);
553 prev = amxc_llist_it_get_previous(amxc_llist_get_last(&path->
parts.data.vl));
556 path_part = amxc_var_from_llist_it(prev);
557 path_str = amxc_var_constcast(cstring_t, path_part);
558 length = strlen(path_str);
559 amxc_string_prepend(&last_part, path_str, length);
564 amxc_var_delete(&path_part);
565 amxc_string_reset(&path->
path);
566 amxc_string_join_var(&path->
path, &path->
parts,
"");
571 last = amxc_string_take_buffer(&last_part);
572 amxc_string_clean(&last_part);
577 amxc_string_t fixed_part;
579 amxc_string_init(&fixed_part, 0);
581 when_null(path, exit);
583 amxc_var_for_each(path_part, (&path->
parts)) {
585 const char* path_str = amxc_var_constcast(cstring_t, path_part);
586 if((path_str[0] ==
'*') ||
587 (path_str[0] ==
'[') ||
588 (path_str[0] ==
'{') ||
589 (path_str[0] ==
'+') ||
590 (path_str[0] ==
'#')) {
593 length = strlen(path_str);
594 amxc_string_append(&fixed_part, path_str, length);
596 amxc_var_delete(&path_part);
601 amxc_string_reset(&path->
path);
602 amxc_string_join_var(&path->
path, &path->
parts,
"");
606 fixed = amxc_string_take_buffer(&fixed_part);
607 amxc_string_clean(&fixed_part);
612 amxc_string_t sup_path;
613 char* supported = NULL;
614 amxc_string_init(&sup_path, 0);
616 when_null(path, exit);
618 amxc_var_for_each(path_part, (&path->
parts)) {
620 const char* path_str = amxc_var_constcast(cstring_t, path_part);
621 if(path_str[0] ==
'{') {
624 if(isdigit(path_str[0])) {
627 length = strlen(path_str);
628 if((path_str[0] ==
'.') && (length == 1)) {
631 amxc_string_append(&sup_path, path_str, strlen(path_str));
635 supported = amxc_string_take_buffer(&sup_path);
636 amxc_string_clean(&sup_path);
641 amxc_string_t ref_part;
643 bool has_ref_index =
false;
644 amxc_string_init(&ref_part, 0);
646 when_null(path, exit);
648 amxc_var_for_each(path_part, (&path->
parts)) {
650 const char* path_str = amxc_var_constcast(cstring_t, path_part);
653 amxc_var_delete(&path_part);
655 has_ref_index =
false;
658 if(path_str[0] ==
'+') {
660 amxc_var_delete(&path_part);
664 if(path_str[0] ==
'#') {
666 amxc_var_delete(&path_part);
668 has_ref_index =
true;
671 length = strlen(path_str);
672 amxc_string_append(&ref_part, path_str, length);
674 amxc_var_delete(&path_part);
679 amxc_string_reset(&path->
path);
680 amxc_string_join_var(&path->
path, &path->
parts,
"");
684 ref = amxc_string_take_buffer(&ref_part);
685 amxc_string_clean(&ref_part);
691 when_null(path, exit);
700 amxc_string_t sup_path;
701 char* supported = NULL;
704 amxc_string_init(&sup_path, 0);
705 when_null(path, exit);
707 amxc_var_for_each(path_part, (&path->
parts)) {
709 const char* path_str = amxc_var_constcast(cstring_t, path_part);
710 if((path_str[0] ==
'*') || (path_str[0] ==
'[')) {
711 amxc_string_append(&sup_path,
"{i}.", 4);
714 length = strlen(path_str);
715 if((path_str[0] ==
'.') && (length == 1)) {
719 strtoll(path_str, &endptr, 0);
720 if((endptr == path_str) || (*endptr !=
'.')) {
721 amxc_string_append(&sup_path, path_str, strlen(path_str));
723 amxc_string_append(&sup_path,
"{i}.", 4);
728 supported = amxc_string_take_buffer(&sup_path);
729 amxc_string_clean(&sup_path);
736 when_null(path, exit);
737 when_true(amxc_var_type_of(&path->
parts) != AMXC_VAR_ID_LIST, exit);
739 amxc_var_for_each(path_part, (&path->
parts)) {
741 const char* path_str = amxc_var_constcast(cstring_t, path_part);
742 length = strlen(path_str);
743 if((path_str[0] ==
'.') && (length == 1)) {
754 bool is_instance =
false;
755 const amxc_llist_t* parts = NULL;
756 amxc_llist_it_t* part_it = NULL;
757 const char* part_txt = NULL;
760 when_null(path, exit);
761 when_true(amxc_var_type_of(&path->
parts) != AMXC_VAR_ID_LIST, exit);
763 parts = amxc_var_constcast(amxc_llist_t, &path->
parts);
764 part_it = amxc_llist_get_last(parts);
765 when_null(part_it, exit);
767 part_txt = amxc_var_constcast(cstring_t, amxc_var_from_llist_it(part_it));
768 if((part_txt != NULL) && (*part_txt ==
'.')) {
769 part_it = amxc_llist_it_get_previous(part_it);
770 when_null(part_it, exit);
771 part_txt = amxc_var_constcast(cstring_t, amxc_var_from_llist_it(part_it));
773 when_null(part_txt, exit);
775 strtoll(part_txt, &endptr, 0);
776 if((endptr == NULL) || (*endptr ==
'.')) {
779 if((part_txt[0] ==
'[') || (part_txt[0] ==
'*')) {
789 amxc_string_t param_path;
791 amxc_string_init(¶m_path, 0);
793 when_null(path, exit);
794 when_true(amxc_string_is_empty(&path->
path), exit);
795 when_str_empty(path->
param, exit);
797 amxc_string_setf(¶m_path,
"%s%s", amxc_string_get(&path->
path, 0), path->
param);
798 result = amxc_string_take_buffer(¶m_path);
801 amxc_string_clean(¶m_path);
Ambiorix Data Model API header file.
static amxd_status_t amxd_path_validate(amxd_path_t *path)
static void amxd_path_add_dot(amxd_path_t *path, bool add_dot)
amxd_status_t amxd_path_setf(amxd_path_t *path, bool add_dot, const char *obj_path,...)
static amxd_path_type_t amxd_path_is(amxd_path_t *path)
static amxc_string_split_status_t amxd_build_path_parts(amxc_llist_t *all, amxc_var_t *path_parts)
static amxd_status_t amxd_path_take_param(amxd_path_t *path)
static amxd_status_t amxd_path_split(amxd_path_t *path, amxc_string_split_builder_t fn)
static bool amxd_build_path_common(amxc_string_t *path_part, amxc_var_t *path_parts, const char *token, bool *quotes, bool *sb, bool *cb)
Ambiorix path API header file.
enum _amxd_path_type amxd_path_type_t
enum _amxd_status amxd_status_t
@ amxd_status_invalid_path
@ amxd_status_unknown_error
#define AMXD_OBJECT_TERMINATE
Path format flag - when set the object path is terminated with a dot.
void amxd_path_delete(amxd_path_t **path)
Frees an allocated amxd_path_t structure.
amxd_status_t amxd_path_init(amxd_path_t *path, const char *object_path)
Initializes an amxd_path_t structure.
char * amxd_path_build_supported_path(amxd_path_t *path)
Creates the supported path representation of the given path.
const char * amxd_path_get_param(amxd_path_t *path)
Gets the parameter name.
uint32_t amxd_path_get_depth(const amxd_path_t *const path)
Calculates the depth of the path.
char * amxd_path_get_first(amxd_path_t *path, bool remove)
Gets the first part of the path.
char * amxd_path_get_last(amxd_path_t *path, bool remove)
Gets the last part of the path.
char * amxd_path_get_reference_part(amxd_path_t *path, bool remove)
Returns the reference path.
bool amxd_path_is_instance_path(const amxd_path_t *const path)
Checks if the path is in the instantiated data model.
amxd_status_t amxd_path_append(amxd_path_t *path, const char *extension, bool add_dot)
Appends a parameter name or object name/index to the path.
amxd_status_t amxd_path_new(amxd_path_t **path, const char *object_path)
Allocates and initializes an amxd_path_t structure.
const char * amxd_path_get(amxd_path_t *path, int flags)
Returns the path stored in the amxd_path_t structure.
char * amxd_path_get_supported_path(amxd_path_t *path)
Translates the path into a path that can be used to fetch the object definition.
amxd_status_t amxd_path_prepend(amxd_path_t *path, const char *extension)
Prepends an object name/index to the path.
char * amxd_path_get_param_path(amxd_path_t *path)
Get the full parameter path from the provided amxd_path_t struct.
void amxd_path_clean(amxd_path_t *path)
Cleans an amxd_path_t structure.
uint32_t amxd_path_get_reference_index(amxd_path_t *path)
Returns the reference path index.
amxd_status_t amxd_path_vsetf(amxd_path_t *path, bool add_dot, const char *obj_path, va_list args)
Sets or replaces the path contained in the amxd_path_t structure.
void amxd_path_reset(amxd_path_t *path)
Resets the amxd_path_t structure.
char * amxd_path_get_fixed_part(amxd_path_t *path, bool remove)
Gets the fixed part of the path.
static amxd_status_t status