LIST delete_d(LIST list, void *key, TessResultCallback2<int, void*, void*>* is_equal) { LIST result = NIL_LIST; LIST last_one = NIL_LIST; while (list != NIL_LIST) { if (!(*is_equal).Run (first_node (list), key)) { if (last_one == NIL_LIST) { last_one = list; list = list_rest (list); result = last_one; set_rest(last_one, NIL_LIST); } else { set_rest(last_one, list); last_one = list; list = list_rest (list); set_rest(last_one, NIL_LIST); } } else { list = pop (list); } } return (result); }
/********************************************************************** * d e l e t e d * * Delete all the elements out of the current list that match the key. * This operation destroys the original list. The caller will supply a * routine that will compare each node to the * key, and return a non-zero value when they match. If the value * NULL is supplied for is_equal, the is_key routine will be used. **********************************************************************/ LIST delete_d(LIST list, void *key, int_compare is_equal) { LIST result = NIL_LIST; LIST last_one = NIL_LIST; if (is_equal == NULL) is_equal = is_same; while (list != NIL_LIST) { if (!(*is_equal) (first_node (list), key)) { if (last_one == NIL_LIST) { last_one = list; list = list_rest (list); result = last_one; set_rest(last_one, NIL_LIST); } else { set_rest(last_one, list); last_one = list; list = list_rest (list); set_rest(last_one, NIL_LIST); } } else { list = pop (list); } } return (result); }
/********************************************************************** * i n s e r t * * Create a list element and rearange the pointers so that the first * element in the list is the second aurgment. **********************************************************************/ void insert(LIST list, void *node) { LIST element; if (list != NIL_LIST) { element = push (NIL_LIST, node); set_rest (element, list_rest (list)); set_rest(list, element); node = first_node (list); list->node = first_node (list_rest (list)); list->next->node = (LIST) node; } }
int get_next_line(int const fd, char **line) { int check; size_t ret; char *str; static char *rest = NULL; check = start(line, &rest, fd); if (check != 0) return (check); str = ft_strnew(BUFF_SIZE); while ((ret = read(fd, str, BUFF_SIZE)) > 0 && !ft_strchr(str, '\n')) { add_str(line, str); ft_bzero(str, BUFF_SIZE + 1); } if (ret > 0) { str[ret] = '\0'; add_str(line, str); rest = set_rest(str); } free(str); ret = (ret > 1) ? 1 : ret; ret = (ret == 0 && *line != NULL) ? 1 : ret; return (ret); }
/********************************************************************** * p u s h * * Create a list element. Push the second parameter (the node) onto * the first parameter (the list). Return the new list to the caller. **********************************************************************/ LIST push(LIST list, void *element) { LIST t; t = new_cell (); t->node = (LIST) element; set_rest(t, list); return (t); }
/** * This routine deallocates all of the memory consumed by * a micro-feature outline. * @param arg micro-feature outline to be freed * @return none * @note Exceptions: none * @note History: 7/27/89, DSJ, Created. */ void FreeMFOutline(void *arg) { //MFOUTLINE Outline) MFOUTLINE Start; MFOUTLINE Outline = (MFOUTLINE) arg; /* break the circular outline so we can use std. techniques to deallocate */ Start = list_rest (Outline); set_rest(Outline, NIL_LIST); while (Start != NULL) { free_struct (first_node (Start), sizeof (MFEDGEPT), "MFEDGEPT"); Start = pop (Start); } } /* FreeMFOutline */
/** * This routine deallocates all of the memory consumed by * a micro-feature outline. * @param arg micro-feature outline to be freed * @return none */ void FreeMFOutline(void *arg) { //MFOUTLINE Outline) MFOUTLINE Start; MFOUTLINE Outline = (MFOUTLINE) arg; /* break the circular outline so we can use std. techniques to deallocate */ Start = list_rest (Outline); set_rest(Outline, NIL_LIST); while (Start != nullptr) { free(first_node(Start)); Start = pop (Start); } } /* FreeMFOutline */
static int init_with_rest(char **line, char **rest) { char *del; if (*rest && ft_strchr(*rest, '\n')) { add_str(line, *rest); del = *rest; *rest = set_rest(del); free(del); return (1); } else if (*rest && !ft_strchr(*rest, '\n')) { *line = ft_strdup(*rest); free(*rest); *rest = NULL; } return (0); }
/********************************************************************** * j o i n * * Join the two lists together. This function is similar to concat * except that concat creates a new list. This function returns the * first list updated. **********************************************************************/ LIST join(LIST list1, LIST list2) { if (list1 == NIL_LIST) return (list2); set_rest (last (list1), list2); return (list1); }