second attempt

This commit is contained in:
maxchen32 2024-01-12 22:30:17 +08:00
parent e6ba036c73
commit 17ccbacd8d

View file

@ -16,26 +16,27 @@ typedef struct InfoState {
void lcd_blank_line() {
for (int i = 0; i < 15; ++i) {
//lcd.print(' ');
printf(" ");
putchar(' ');
}
}
int lcd_print_between(char* pos1, char* pos2) {
int lcd_print_between(char* str, int pos1, int pos2) {
//int i = 0;
int va = 0;
char* p = pos1;
char* p = str+pos1;
//int slen = strlen(str);
while (p < pos2) {
while (p < str+pos2) {
if (*p != '\n' && *p != '\r') {
//lcd.print(*(p++));
putchar(*(p++));
putchar(*p);
++va;
} //else
//if (i == 0){ ++i; } else
//{
// break;
//}
++p;
}
if (va < 15) {
@ -44,6 +45,7 @@ int lcd_print_between(char* pos1, char* pos2) {
putchar(' ');
}
}
putchar('!');
return va;
}
@ -76,6 +78,9 @@ list_t* aux_gen_wrap_list(list_t* wrap, char* text) {
}
++curr;
}
if (list_rpush(wrap, list_node_new((int)(curr-text))) == NULL) {
return NULL;
}
return wrap;
}
@ -90,24 +95,42 @@ void initInfoState(InfoState* st, char* 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->it = list_iterator_new(st->wrap, LIST_HEAD);
st->pos1 = list_iterator_next(st->it);
st->pos2 = st->pos3 = NULL;
}
void initInfoScreen(InfoState* st, char* text) {
int initInfoScreen(InfoState* st, char* text) {
initInfoState(st, text);
printf("%d\n", st->wrap->len);
int retn = 0;
//lcd.setCursor(0, 0);
if ((st->pos2 = list_iterator_next(st->it))) {
//printf("hello\n");
printf("%d\n", st->pos2->val);
int tmp = lcd_print_between(st->info, st->info+(int)st->pos2->val);
printf("%d\n", tmp);
//printf("%d\n", st->pos2->val);
int tmp = lcd_print_between(st->info, 0, (int)st->pos2->val);
//printf("%d\n", tmp);
//printf("%d\n", st->wrap->len);
if ((st->pos3 = list_iterator_next(st->it))) {
printf("\n");
//printf("%d\n", st->pos2->val);
//printf("%d\n", st->pos3->val);
int tmp = lcd_print_between(st->info, (int)st->pos2->val, (int)st->pos3->val);
//printf("%d\n", tmp);
//printf("%d\n", st->wrap->len);
} else {
printf("\n");
lcd_blank_line();
}
} else {
retn = 1;
}
return retn;
}
int scrollDown(InfoState* st) {
}
/*
Separate a substring that can be printed on one line, and return the
@ -177,6 +200,8 @@ char* aux_sub_line_rev(char* str, char substr[16]) {
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);