From dba5c6b3a8dd6529423d51d5c288c4cfb54addcc Mon Sep 17 00:00:00 2001 From: maxchen32 Date: Sun, 14 Jan 2024 14:56:07 +0800 Subject: [PATCH] arrange code --- src/list/src/list.h | 3 - src/list/src/list_iterator.c | 16 ------ testline.c | 107 ++++------------------------------- 3 files changed, 10 insertions(+), 116 deletions(-) diff --git a/src/list/src/list.h b/src/list/src/list.h index b3214ad..c0075dd 100644 --- a/src/list/src/list.h +++ b/src/list/src/list.h @@ -120,9 +120,6 @@ list_iterator_new_from_node(list_node_t *node, list_direction_t direction); list_node_t * list_iterator_next(list_iterator_t *self); -list_node_t * -list_iterator_prev(list_iterator_t *self); - void list_iterator_destroy(list_iterator_t *self); diff --git a/src/list/src/list_iterator.c b/src/list/src/list_iterator.c index c0edbc6..f1363b2 100644 --- a/src/list/src/list_iterator.c +++ b/src/list/src/list_iterator.c @@ -51,22 +51,6 @@ list_iterator_next(list_iterator_t *self) { return curr; } -/* - * Return the previous list_node_t or NULL when no more - * nodes remain in the list. - */ - -list_node_t * -list_iterator_prev(list_iterator_t *self) { - list_node_t *curr = self->next; - if (curr) { - self->next = self->direction == LIST_HEAD - ? curr->prev - : curr->next; - } - return curr; -} - /* * Free the list iterator. */ diff --git a/testline.c b/testline.c index 23c145a..c771abd 100644 --- a/testline.c +++ b/testline.c @@ -13,8 +13,6 @@ typedef struct InfoState { char* info; list_node_t *pos1, *pos2, *pos3; list_t *wrap; - //list_iterator_t *it; - //list_node_t *node; } InfoState; @@ -92,24 +90,15 @@ list_t* aux_gen_wrap_list(list_t* wrap, char* text) { void initInfoState(InfoState* st, char* text) { st->info = text; - //st->len = strlen(text); - //st->fullLines = st->len / 15; - //st->Nlines = (st->len + 14) / 15; - //st->lastlinelen = st->len % 15; - //st->pos1 = text; - //st->pos2 = text; - //st->pos3 = text; st->wrap = list_new(); st->wrap = aux_gen_wrap_list(st->wrap, st->info); - //st->it = list_iterator_new(st->wrap, LIST_HEAD); - //st->pos1 = list_iterator_next(st->it); st->pos1 = list_at(st->wrap, 0); st->pos2 = st->pos3 = NULL; } InfoRet initInfoScreen(InfoState* st, char* text) { initInfoState(st, text); - printf("%d\n", st->wrap->len); + //printf("%d\n", st->wrap->len); if (st->pos1 == NULL) { return IR_UNKNOWN; } @@ -190,96 +179,20 @@ void destoryInfoState(InfoState* st) { st->info = NULL; } -/* - Separate a substring that can be printed on one line, and return the - original string position corresponding to the end of the substring. - */ -/* -char* aux_sub_line(char* str, char substr[16]) { - int suf = 0; - char* curr = str; - memset(substr, 0, 16); - - while (*curr != '\0' && suf < 15) { - if (*curr != '\n' && *curr != '\r') { - substr[suf++] = *(curr++); - //++curr; - } else - if (curr == str){ ++curr; } else - { - break; - } - } - -//#if !REFRESH - while (suf < 15) { - substr[suf++] = ' '; - } -//#endif - return curr; -} - -char* aux_sub_line_rev(char* str, char substr[16]) { - int suf = 0; - char* curr = str; - memset(substr, 0, 16); - - while (*curr != '\0' && suf < 15) { - if (*curr != '\n' && *curr != '\r') { - substr[suf++] = *(curr--); - } else - if (curr == str){ --curr; } else - { - break; - } - } - - { - int i = 0; - int j = suf - 1; - while (i < j) { - char temp = substr[i]; - substr[i] = substr[j]; - substr[j] = temp; - i++; - j--; - } - } - -//#if !REFRESH - while (suf < 15) { - substr[suf++] = ' '; - } -//#endif - return curr+1; -} -*/ - int main() { char* cinfo = "Far far away, a\n\nbehind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts."; // 0 1516 32 char* s2 = " ba\n ab"; // 0 11 - list_t *wrap = list_new(); - wrap = aux_gen_wrap_list(wrap, cinfo); + //list_t *wrap = list_new(); + //wrap = aux_gen_wrap_list(wrap, cinfo); - list_node_t *node; - //list_iterator_t *it = list_iterator_new(wrap, LIST_HEAD); - - //node = list_iterator_next(it); - node = list_at(wrap, 0); - printf("node val: %d\n", node->val); - printf("node prev: %p\n", node->prev); - /* - node = list_iterator_next(it); - printf("node val: %d\n", node->val); - node = list_iterator_prev(it); - printf("node val: %d\n", node->val); - node = list_iterator_prev(it); - printf("node val: %d\n", node->val); - node = list_iterator_prev(it); - printf("node val: %d\n", node->val); - */ + //list_node_t *node; + + //node = list_at(wrap, 0); + //printf("node val: %d\n", node->val); + //printf("node prev: %p\n", node->prev); + InfoRet ret_code; InfoState st; @@ -344,7 +257,7 @@ int main() { } */ //list_iterator_destroy(it); - list_destroy(wrap); + //list_destroy(wrap); destoryInfoState(&st); return 0; } \ No newline at end of file