change indentation and correct? ram management

This commit is contained in:
Milang 2020-01-07 16:50:59 +01:00
parent 3357263c63
commit 9c795cc29e
1 changed files with 128 additions and 129 deletions

257
liblog.c
View File

@ -23,19 +23,19 @@ static int number_max_messages=10000; // Ram 10 Ko
typedef struct log_line log_line;
typedef struct log_line
{
void* previous;
char text[MAX_LENGHT];
void* next;
int cursor;
void* previous;
char text[MAX_LENGHT];
void* next;
int cursor;
} log_line;
static log_line first_line=
{
0,
"Log beginning:",
0,
0
0,
"Log beginning:",
0,
0
};
static log_line* current_line=&first_line;
@ -52,7 +52,7 @@ static log_line* cut_line()
first_line.next=maillon_suivant;
if (maillon_suivant)
maillon_suivant->previous=&first_line;
number_messages--;
number_messages--;
return maillon;
}
@ -62,7 +62,7 @@ static void optimize()
{
log_line* line = cut_line();
free(line);
number_messages--;
//number_messages--;
}
}
@ -79,18 +79,18 @@ int ll_get_size();
void ll_set_state(log_state_t s)
{
if (s==LOG_DISABLE)
priority=LEVEL_QUIET;
if (s==LOG_ENABLE)
priority=LEVEL_INFO;
if (s==LOG_DISABLE)
priority=LEVEL_QUIET;
if (s==LOG_ENABLE)
priority=LEVEL_INFO;
}
log_state_t ll_get_state()
{
if (priority=LEVEL_QUIET)
return 0;
else
return 1;
if (priority=LEVEL_QUIET)
return 0;
else
return 1;
}
@ -106,95 +106,94 @@ static void clear_line(log_line* line)
{
line->next=0;
line->cursor=0;
for (int i=0; i<MAX_LENGHT; i++)
current_line->text[i]='\0';
for (int i=0; i<MAX_LENGHT; i++)
current_line->text[i]='\0';
}
static log_line* add_line()
{
int malloc_fail=0;
int malloc_fail=0;
log_line* line;
log_line* line;
int test=(number_messages*sizeof(log_line)>=number_max_messages);
if (!test)
{
line = malloc(sizeof(log_line));
if (0==line)
malloc_fail=1;
else
number_messages++;
}
int test=(number_messages*sizeof(log_line)>=number_max_messages);
if (!test)
{
line = malloc(sizeof(log_line));
if (0==line)
malloc_fail=1;
}
if (test || malloc_fail) // fail du malloc ou dépassement de la limite de ram imposée lors du build
line=cut_line();
if (test || malloc_fail) // fail du malloc ou dépassement de la limite de ram imposée lors du build
line=cut_line();
link_line(line);
clear_line(line);
optimize();
return current_line;
link_line(line);
clear_line(line);
number_messages++;
optimize();
return current_line;
}
void ll_clear()
{
number_messages=0;
while (current_line->previous)
{
log_line* next=current_line->previous;
free(current_line);
current_line=next;
}
current_line->next=0;
current_line->cursor=0;
for (int i=0; i<MAX_LENGHT; i++)
current_line->text[i]='\0';
number_messages=0;
while (current_line->previous)
{
log_line* next=current_line->previous;
free(current_line);
current_line=next;
}
current_line->next=0;
current_line->cursor=0;
for (int i=0; i<MAX_LENGHT; i++)
current_line->text[i]='\0';
}
static void append_character(char c)
{
if (current_line==&first_line)
add_line();
if (c=='\n')
{
current_line->text[current_line->cursor] = '\0';
add_line();
return;
}
current_line->text[current_line->cursor] = c;
if (c!='\0')
{
current_line->cursor ++;
if (current_line==&first_line)
add_line();
if (c=='\n')
{
current_line->text[current_line->cursor] = '\0';
add_line();
return;
}
current_line->text[current_line->cursor] = c;
if (c!='\0')
{
current_line->cursor ++;
if (current_line->cursor == MAX_LENGHT-1)
add_line();
//current_line->text[current_line->cursor] = '\0';
if (current_line->cursor == MAX_LENGHT-1)
add_line();
//current_line->text[current_line->cursor] = '\0';
#ifdef FXCG50
else if (dsize(&current_line->text[0],0,0,0)>396-7)
{
add_line();
}
else if (dsize(&current_line->text[0],0,0,0)>396-7)
{
add_line();
}
#endif
}
}
}
// log something
void ll_send(const char * txt)
{
if (priority!=LEVEL_QUIET)
{
char c=1;
int i=0;
while (c!='\0')
{
c=txt[i];
append_character(c);
i++;
}
}
if (priority!=LEVEL_QUIET)
{
char c=1;
int i=0;
while (c!='\0')
{
c=txt[i];
append_character(c);
i++;
}
}
}
void ll_sendp(log_level_t p, char const *format, ...)
@ -218,27 +217,27 @@ static void show_line(const log_line* l, int y)
{
font_t * f=dfont(0);
dtext(1, y, &l->text[0], C_BLACK, C_NONE);
dtext(1, y, &l->text[0], C_BLACK, C_NONE);
dfont(f);
dfont(f);
}
void ll_display_custom(log_line* line)
{
dclear(C_WHITE);
for (int i=0; i<8; i++)
{
dclear(C_WHITE);
for (int i=0; i<8; i++)
{
#ifdef FX9860G
show_line(line, 63 - 8*(i+1));
show_line(line, 63 - 8*(i+1));
#endif
#ifdef FXCG50
show_line(line, 224 - 13*(i+1));
show_line(line, 224 - 13*(i+1));
#endif
line=line->previous;
if (!line)
break;
}
dupdate_noint();
line=line->previous;
if (!line)
break;
}
dupdate_noint();
}
@ -246,63 +245,63 @@ void ll_display_custom(log_line* line)
void ll_display()
{
ll_display_custom(current_line);
ll_display_custom(current_line);
}
void ll_pause()
{
//for (int i=0; i<timer_count(); i++)
// if (i!=3) // keyboard timer
// timer_pause(i);
dclear(C_WHITE);
log_line* line=current_line;
while (1)
{
ll_display_custom(line);
int key = getkey().key;
if (key==KEY_UP)
{
log_line* linet=line->previous;
if (linet)
line=linet;
}
if (key==KEY_DOWN)
{
log_line* linet=line->next;
if (linet)
line=linet;
}
if (key==KEY_EXIT)
break;
}
//for (int i=0; i<timer_count(); i++)
// if (i!=3)
// timer_start(i);
//for (int i=0; i<timer_count(); i++)
// if (i!=3) // keyboard timer
// timer_pause(i);
dclear(C_WHITE);
log_line* line=current_line;
while (1)
{
ll_display_custom(line);
int key = getkey().key;
if (key==KEY_UP)
{
log_line* linet=line->previous;
if (linet)
line=linet;
}
if (key==KEY_DOWN)
{
log_line* linet=line->next;
if (linet)
line=linet;
}
if (key==KEY_EXIT)
break;
}
//for (int i=0; i<timer_count(); i++)
// if (i!=3)
// timer_start(i);
}
GNORETURN void ll_panic(uint32_t code)
{
char str[10];
sprintf(str, "\nException !\n>> ErrCode=%d",code);
ll_set_state(1);
ll_send(str);
while (1)
ll_pause();
char str[10];
sprintf(str, "\nException !\n>> ErrCode=%d",code);
ll_set_state(1);
ll_send(str);
while (1)
ll_pause();
}
void ll_set_panic()
{
gint_panic_set(ll_panic);
gint_panic_set(ll_panic);
}
void ll_set_level(log_level_t l)
{
priority=l;
priority=l;
}
log_level_t ll_get_level(void)
{
return priority;
return priority;
}