arrange code
This commit is contained in:
parent
28e06e13ea
commit
dba5c6b3a8
3 changed files with 10 additions and 116 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
105
testline.c
105
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);
|
||||
//list_node_t *node;
|
||||
|
||||
//node = list_at(wrap, 0);
|
||||
//printf("node val: %d\n", node->val);
|
||||
//printf("node prev: %p\n", node->prev);
|
||||
|
||||
//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);
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in a new issue