Compare commits

..

No commits in common. "3bbb476505b4d2f66c777c2c93b8086b7cbc3ae2" and "0451a89dce186c65c20788b0bd6863b634a4f7de" have entirely different histories.

3 changed files with 23 additions and 26 deletions

View File

@ -22,7 +22,7 @@ OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILES))
CC = gcc CC = gcc
CFLAGS = -Wall -Werror -Wextra -g3 CFLAGS = -Wall -Werror -Wextra -g2
LIB_NAME = libft LIB_NAME = libft

2
libft

@ -1 +1 @@
Subproject commit e846b98fcda5878a1d4d9de8f422dec09b97456c Subproject commit 1cab2379213f62f814312dc2cc7b0f3aa65268fc

View File

@ -139,32 +139,24 @@ char *get_sym_char(Elf64_Sym sym, Elf64_Shdr sec) {
return ("n"); return ("n");
} }
int strcmp_nm(void *a, void *b) { int strcmp_nm(t_list *a, t_list *b) {
t_entry *aa = (t_entry *)a;
t_entry *bb = (t_entry *)b;
char *s1 = aa->symbol;
char *s2 = bb->symbol;
return ft_strcmp(s1, s2);
}
int reverse(void *a, void *b) {
return strcmp_nm(b, a);
}
int nosort(void *a, void *b) {
(void)a; (void)a;
(void)b; (void)b;
return 1; return 1;
} }
void put_entry(void *data) { int reverse(t_list *a, t_list *b) {
t_node *node = (t_node *)data; return strcmp_nm(b, a);
t_entry *entry = (t_entry *)node->data; }
ft_putstr(entry->string);
int nosort(t_list *a, t_list *b) {
(void)a;
(void)b;
return -1;
} }
int nm64(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_ordering ordering) { int nm64(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_ordering ordering) {
t_root *tree = NULL; t_list *list = NULL;
t_entry *entry = (t_entry *)malloc(sizeof(t_entry)); t_entry *entry = (t_entry *)malloc(sizeof(t_entry));
if (!entry) if (!entry)
return FT_NM_FAILURE; return FT_NM_FAILURE;
@ -259,13 +251,13 @@ int nm64(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_orderin
// ensuite un switch ordering avec un ft_lstinsert (pointeur sur fonction serait plus opti mais osef) // ensuite un switch ordering avec un ft_lstinsert (pointeur sur fonction serait plus opti mais osef)
switch (ordering) { switch (ordering) {
case NOSORT: case NOSORT:
ft_rbt_insert(&tree, ft_rbt_new((void *)entry, sizeof(t_entry)), &nosort); ft_lstinsert(&list, ft_lstnew((void *)entry, sizeof(t_entry)), &nosort);
break; break;
case REVERSE: case REVERSE:
ft_rbt_insert(&tree, ft_rbt_new((void *)entry, sizeof(t_entry)), &reverse); ft_lstinsert(&list, ft_lstnew((void *)entry, sizeof(t_entry)), &reverse);
break; break;
case DEFAULT_ORDERING: case DEFAULT_ORDERING:
ft_rbt_insert(&tree, ft_rbt_new((void *)entry, sizeof(t_entry)), &strcmp_nm); ft_lstinsert(&list, ft_lstnew((void *)entry, sizeof(t_entry)), &strcmp_nm);
break; break;
} }
// pas de bst oops :D // pas de bst oops :D
@ -277,9 +269,14 @@ int nm64(t_mapped_file mapped_file, char *path, t_verbosity verbosity, t_orderin
free(str); free(str);
} }
// ici on affiche tout ou no symbols en cas de list vide // ici on affiche tout ou no symbols en cas de list vide
if (tree) { if (list) {
ft_putrbt(tree, &put_entry); while (list) {
} else { t_entry *my_entry = (t_entry *)list->content;
ft_putstr(my_entry->string);
list = list->next;
}
}
else {
ft_printf("sss", "nm: ", path, ": no symbols\n"); ft_printf("sss", "nm: ", path, ": no symbols\n");
} }
return FT_NM_SUCCESS; return FT_NM_SUCCESS;