summaryrefslogtreecommitdiffstats
path: root/src/u_alias.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/u_alias.c')
-rw-r--r--src/u_alias.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/u_alias.c b/src/u_alias.c
new file mode 100644
index 0000000..14ca75e
--- /dev/null
+++ b/src/u_alias.c
@@ -0,0 +1,63 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* u_alias.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stdint.h>
+#include <stddef.h>
+
+#include "d_define.h"
+#include "s_lalias.h"
+#include "s_struct.h"
+
+size_t
+ u_get_alias_value(char str[], const char name[], size_t dstsize, t_msh *msh)
+{
+ t_lalias *ptr;
+
+ if (str != NULL)
+ {
+ str[0] = C_NUL;
+ }
+ ptr = msh->alias;
+ while (ptr != NULL && ft_strncmp(ptr->name, name, ft_strlen(name) + 1) != 0)
+ {
+ ptr = ptr->next;
+ }
+ if (ptr == NULL)
+ {
+ return (0);
+ }
+ if (str != NULL)
+ {
+ ft_strlcpy(str, ptr->val, dstsize);
+ }
+ return (ptr->id);
+}
+
+void
+ u_set_alias_value(const char name[], const char value[], t_msh *msh)
+{
+ t_lalias *new;
+
+ if (u_get_alias_value(NULL, name, 0, msh) != 0)
+ {
+ s_lalias_rebind(&msh->alias, name, value);
+ }
+ else
+ {
+ if ((new = s_lalias_new(name, value)) == NULL)
+ {
+ return ;
+ }
+ s_lalias_add_front(&msh->alias, new);
+ }
+}