first attempt

This commit is contained in:
maxchen32 2024-01-11 23:21:34 +08:00
parent 79a8c00636
commit e6ba036c73
2 changed files with 85 additions and 46 deletions

13
.c4droid Normal file
View File

@ -0,0 +1,13 @@
#Sat Jan 06 23:52:39 GMT+08:00 2024
binary_fname=
run_mode=0
use_cmake=false
sm_names=testline.c src/list/src/list.c src/list/src/list_iterator.c src/list/src/list_node.c
qmake_cmd=export PATH\=(c4droid\:GCCROOT)qt/bin/\:$PATH\nqmake -spec android-g++
cmake_cmd=cmake .
prepare_cmds=export PATH\=/busybox-virtual\:(c4droid\:DATADIR)\:(c4droid\:GCCROOT)bin\:(c4droid\:GCCROOT)(c4droid\:PREFIX)/bin/\:$PATH\nexport CC\="(c4droid\:PREFIX)-gcc (c4droid\:PIE) (c4droid\:MAKEMODEARGS)"\nexport CXX\="(c4droid\:PREFIX)-g++ (c4droid\:PIE) (c4droid\:MAKEMODEARGS)"\nexport SHELL\="(c4droid\:DATADIR)sh"\ncd (c4droid\:CURSRCDIR)
comp_mode=4
make_cmd=make CC\="$CC" CXX\="$CXX" SHELL\="$SHELL"
conf_patch=true
conf_cmd=export PATH\=/busybox-virtual\:(c4droid\:DATADIR)\:(c4droid\:GCCROOT)bin\:(c4droid\:GCCROOT)(c4droid\:PREFIX)/bin/\:$PATH\nexport CFLAGS\="-Os -s (c4droid\:PIE)"\nexport CXXFLAGS\="-Os -s (c4droid\:PIE)"\nexport SHELL\="(c4droid\:DATADIR)sh"\nexport CONFIG_SHELL\="sh"\nexport PKG_CONFIG_PATH\=(c4droid\:GCCROOT)(c4droid\:PREFIX)/lib/pkgconfig\ncd (c4droid\:CURSRCDIR)\nfind . -exec touch {} \\;\ncd (c4droid\:BUILDDIR)\n(c4droid\:CURSRCDIR)/configure --host\=(c4droid\:PREFIX) --prefix\=(c4droid\:GCCROOT)(c4droid\:PREFIX) CFLAGS\="$CFLAGS" CXXFLAGS\="$CXXFLAGS" --build\=i686-linux --disable-shared --enable-static\nmake SHELL\="$SHELL"\nmake install SHELL\="$SHELL"
conf_internal=false

View File

@ -2,62 +2,50 @@
#include <string.h>
#include "src/list/src/list.h"
/*
typedef struct InfoState {
char* info;
int len;
int fullLines;
int Nlines;
int lastlinelen;
char *pos1, *pos2, *pos3;
list_t* wrap;
list_node_t *pos1, *pos2, *pos3;
list_t *wrap;
list_iterator_t *it;
//list_node_t *node;
} InfoState;
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();
char* tmp = text;
//list_node_t *c = list_rpush(st->wrap, list_node_new("c"));
}
void lcd_blank_line() {
for (int i = 0; i < 15; ++i) {
lcd.print(' ');
//lcd.print(' ');
printf(" ");
}
}
void initInfoScreen(InfoState* st, char* text) {
initInfoState(st, text);
lcd.setCursor(0, 0);
if (*(st->pos1) == '\n' || *(st->pos1) == '\r') {
lcd_blank_line();
++st->pos1;
++st->pos2;
} else {
st->pos2 += lcd_print_line(st->pos1);
int lcd_print_between(char* pos1, char* pos2) {
//int i = 0;
int va = 0;
char* p = pos1;
//int slen = strlen(str);
while (p < pos2) {
if (*p != '\n' && *p != '\r') {
//lcd.print(*(p++));
putchar(*(p++));
++va;
} //else
//if (i == 0){ ++i; } else
//{
// break;
//}
}
lcd.setCursor(0, 1);
if ((*(st->pos2) == '\n' || *(st->pos2) == '\r') && *(st->pos2 - 1) == *(st->pos2)) {
lcd_blank_line();
} else {
lcd_print_line(st->pos2);
if (va < 15) {
for (int j = 15 - va; j > 0; --j) {
//lcd.print(' ');
putchar(' ');
}
}
#ifdef DEBUG
//Serial.println(String("pos1: ") + st->pos1);
//Serial.println(String("pos2: ") + st->pos2);
Serial.println("init");
Serial.print(st->pos1-st->info);
Serial.println(String(" ")+(st->pos2-st->info));
#endif
return va;
}
*/
list_t* aux_gen_wrap_list(list_t* wrap, char* text) {
if (wrap == NULL) {
@ -66,7 +54,7 @@ list_t* aux_gen_wrap_list(list_t* wrap, char* text) {
char* curr = text;
int suf = 0;
list_node_t *node;
if (list_rpush(wrap, list_node_new(0)) == NULL) {
if (list_rpush(wrap, list_node_new(-1)) == NULL) {
return NULL;
}
while (*curr != '\0') {
@ -91,6 +79,36 @@ list_t* aux_gen_wrap_list(list_t* wrap, char* text) {
return wrap;
}
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->pos2 = st->pos3 = NULL;
}
void initInfoScreen(InfoState* st, char* text) {
initInfoState(st, text);
//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);
}
}
/*
Separate a substring that can be printed on one line, and return the
original string position corresponding to the end of the substring.
@ -158,20 +176,28 @@ 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
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);
InfoState st;
initInfoScreen(&st, cinfo);
/*
while ((node = list_iterator_next(it))) {
printf("%d\n", (unsigned int)(node->val));
}
*/
/*
if ((node = list_iterator_next(it))) {
}
if ((node = list_iterator_next(it))) {
//if (node->val == -1) {
char* p = cinfo;
list_node_t *test;
while (*p != '\0') {