From 580ef2c4322c3182dc79c50c06d19ac9504badd4 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 14 Oct 2016 21:13:10 +0200 Subject: [PATCH] some new functions, sstr and str --- libftasm/includes/ftxattr.h | 3 +++ libftasm/includes/libft.h | 13 +++++++----- libftasm/src/sstr/ft_sstradd.c | 19 ++++++++++++++++++ libftasm/src/sstr/ft_sstrdup.c | 20 +++++++++++++++++++ libftasm/src/sstr/ft_sstrprint.c | 10 ++++++++++ .../ft_strlsort.c => sstr/ft_sstrsort.c} | 2 +- libftasm/src/str/ft_str3join.c | 14 +++++++++++++ libftasm/src/str/ft_strcat.c | 2 +- libftasm/src/strl/ft_strlprint.c | 10 ---------- 9 files changed, 76 insertions(+), 17 deletions(-) create mode 100644 libftasm/src/sstr/ft_sstradd.c create mode 100644 libftasm/src/sstr/ft_sstrdup.c create mode 100644 libftasm/src/sstr/ft_sstrprint.c rename libftasm/src/{strl/ft_strlsort.c => sstr/ft_sstrsort.c} (80%) create mode 100644 libftasm/src/str/ft_str3join.c delete mode 100644 libftasm/src/strl/ft_strlprint.c diff --git a/libftasm/includes/ftxattr.h b/libftasm/includes/ftxattr.h index f9f3804d..ff945002 100644 --- a/libftasm/includes/ftxattr.h +++ b/libftasm/includes/ftxattr.h @@ -3,4 +3,7 @@ # define FT_XATTR_SIZE 10000 # include # include + +int ft_xattr_print(char *path); +int ft_xattr_count(char *path); #endif diff --git a/libftasm/includes/libft.h b/libftasm/includes/libft.h index dda65502..1fcfdaea 100644 --- a/libftasm/includes/libft.h +++ b/libftasm/includes/libft.h @@ -1,13 +1,16 @@ #ifndef LIBFT_H #define LIBFT_H + # include "ftprintf.h" # include "ftxattr.h" # include "getnextline.h" + # include # include # include # include # include + # define FT_SEP(x) (x == ' ' || x == '\t' || x == '\n') # define FT_ABS(x) (((x) < 0) ? -(x) : (x)) # define FT_NEG(x) (((x) < 0) ? 1 : 0) @@ -109,6 +112,7 @@ t_list *ft_id(t_list *a); char *ft_strrev(char *str); char **ft_strsplit(char const *s, char c); +char *ft_str3join(char const *s1, char const *s2, char const *s3); char **ft_split_whitespaces(char *str); char *ft_convert_base(char *str, char *base_from, char *base_to, char *flags); @@ -119,13 +123,12 @@ char *ft_uitoa_base(unsigned int nbr, char *base); size_t ft_ilen(int n); size_t ft_uilen(unsigned int n); -void ft_strlsort(char **list, int size, int (*cmp)()); -void ft_strlprint(char **strl, char sep); +void ft_sstrsort(char **list, int size, int (*cmp)()); +void ft_sstrprint(char **list, char sep); +char **ft_sstrdup(char **list); +char **ft_sstradd(char **list, char *new); int ft_time_isrecent(time_t event); -int ft_xattr_print(char *path); -int ft_xattr_count(char *path); - char *ft_path_notdir(char *path); #endif diff --git a/libftasm/src/sstr/ft_sstradd.c b/libftasm/src/sstr/ft_sstradd.c new file mode 100644 index 00000000..97d1486a --- /dev/null +++ b/libftasm/src/sstr/ft_sstradd.c @@ -0,0 +1,19 @@ +#include "libft.h" + +char **ft_sstradd(char **sstr, char *new) +{ + int i; + int size; + char **newlist; + + i = 0; + size = 0; + while (sstr && sstr[size]) + size++; + newlist = (char **)malloc(sizeof(char *) * (size + 3)); + while (sstr && *sstr) + newlist[i++] = *sstr++; + newlist[i++] = new; + newlist[i] = NULL; + return (newlist); +} diff --git a/libftasm/src/sstr/ft_sstrdup.c b/libftasm/src/sstr/ft_sstrdup.c new file mode 100644 index 00000000..f5403be2 --- /dev/null +++ b/libftasm/src/sstr/ft_sstrdup.c @@ -0,0 +1,20 @@ +#include "libft.h" + +char **ft_sstrdup(char **list) +{ + int i; + int size; + char **cpy; + + i = 0; + size = 0; + while (list[size]) + size++; + cpy = (char **)malloc(sizeof(char *) * (size + 1)); + while (*list) + { + cpy[i++] = ft_strdup(*list); + list++; + } + return (cpy); +} diff --git a/libftasm/src/sstr/ft_sstrprint.c b/libftasm/src/sstr/ft_sstrprint.c new file mode 100644 index 00000000..9ad237c1 --- /dev/null +++ b/libftasm/src/sstr/ft_sstrprint.c @@ -0,0 +1,10 @@ +#include "libft.h" + +void ft_sstrprint(char **list, char sep) +{ + int i; + + i = 0; + while (list[i]) + ft_printf("%s%c", list[i++], sep); +} diff --git a/libftasm/src/strl/ft_strlsort.c b/libftasm/src/sstr/ft_sstrsort.c similarity index 80% rename from libftasm/src/strl/ft_strlsort.c rename to libftasm/src/sstr/ft_sstrsort.c index 767b3edf..dd7d2611 100644 --- a/libftasm/src/strl/ft_strlsort.c +++ b/libftasm/src/sstr/ft_sstrsort.c @@ -1,6 +1,6 @@ #include "libft.h" -void ft_strlsort(char **list, int size, int (*cmp)()) +void ft_sstrsort(char **list, int size, int (*cmp)()) { int i; char *tmp; diff --git a/libftasm/src/str/ft_str3join.c b/libftasm/src/str/ft_str3join.c new file mode 100644 index 00000000..2227a0e3 --- /dev/null +++ b/libftasm/src/str/ft_str3join.c @@ -0,0 +1,14 @@ +#include "libft.h" + +char *ft_str3join(char const *s1, char const *s2, char const *s3) +{ + char *join; + int size; + + size = ft_strlen(s1) + ft_strlen(s2) + ft_strlen(s3); + join = ft_strnew(size + 1); + ft_strcpy(join, s1); + ft_strcat(join, s2); + ft_strcat(join, s3); + return (join); +} diff --git a/libftasm/src/str/ft_strcat.c b/libftasm/src/str/ft_strcat.c index b2947ea8..aa52141a 100644 --- a/libftasm/src/str/ft_strcat.c +++ b/libftasm/src/str/ft_strcat.c @@ -19,7 +19,7 @@ char *ft_strcat(char *s1, const char *s2) size = ft_strlen(s1); j = 0; - while (s2[j] != '\0') + while (s2 && s2[j] != '\0') { s1[size + j] = s2[j]; j++; diff --git a/libftasm/src/strl/ft_strlprint.c b/libftasm/src/strl/ft_strlprint.c deleted file mode 100644 index 4a659e23..00000000 --- a/libftasm/src/strl/ft_strlprint.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "libft.h" - -void ft_strlprint(char **strl, char sep) -{ - int i; - - i = 0; - while (strl[i]) - ft_printf("%s%c", strl[i], sep); -}