#include #include #include #include #include "aplinks.h" #include "disp_ctr.h" static DISPLIST *top; static DISPLIST *bot; static DISPLIST *cur; static DISPLIST *disptop; static DISPLIST *dispbot; static DISPLIST *precur; static int disp_y; static int m_col; /* 動けばいいの! (^^; */ static DISPLIST *scrl_top; static DISPLIST *scrl_bot; int init_displist(int m_column, int m_row, int logbuf_line, DATA_RANGE data_range) { int i; disp_y = DATA_MAP_Y + ((((((data_range.end - data_range.start) + 1) / SEC_PER_P) - 1) / m_column) + 1) + 1; m_col = m_column; if(alloc_displist(&top, m_column) == -1){ return -1; } bot = top; for(i = 1; i < logbuf_line; i++){ if(alloc_displist(&(bot->next), m_column) == -1){ return -1; } bot->next->pre = bot; bot = bot->next; } bot->next = top; top->pre = bot; disptop = top; dispbot = disptop; for(i = 1; i < (m_row - disp_y); i++){ dispbot = dispbot->next; } cur = top; precur = cur; scrl_top = NULL; scrl_bot = NULL; return 0; } int alloc_displist(DISPLIST **displist, int m_column) { if((*(displist) = malloc(sizeof(DISPLIST))) == NULL){ return -1; } if(((*(displist))->linebuf = malloc(sizeof(unsigned char) * (m_column + 1) * 6)) == NULL){ return -1; } strcpy((*(displist))->linebuf, ""); return 0; } int displist_c_printf(int c, char *format, ...) { DISPLIST *dispcur; int i; va_list argptr; char buf[1024]; int loc; static char prebuf[1024]; static int sflag; int elen; int len; scrl_top = NULL; scrl_bot = NULL; if(*(cur->linebuf + strlen(cur->linebuf) - 1) == '\n'){ cur = cur->next; strcpy(cur->linebuf, ""); } color_s(c, buf); strcat(cur->linebuf, buf); va_start(argptr, format); vsprintf(buf, format, argptr); va_end(argptr); strcat(cur->linebuf, buf); i = 1; while(1){ if((elen = except_esc_len(cur->linebuf, &loc)) > m_col){ len = strlen(cur->linebuf); memmove(cur->next->linebuf, (cur->linebuf + loc), (len - loc) + 1); *(cur->linebuf + loc) = '\n'; *(cur->linebuf + loc + 1) = '\0'; cur = cur->next; } else{ break; } i++; } sflag = 0; dispcur = disptop; while(1){ if(dispcur == cur){ sflag = 1; break; } else{ dispcur = dispcur->next; } if(dispcur == dispbot->next){ break; } } if(sflag == 0){ while(1){ disptop = disptop->next; dispbot = dispbot->next; if(cur == dispbot){ break; } } } #ifndef UNIX cursor_off(); #endif if(cur != precur){ xy_clr_to_right_bottom(1, disp_y); i = 0; for(dispcur = disptop; dispcur != dispbot->next; dispcur = dispcur->next){ /* xy_clr_to_right(1, disp_y + i); */ xy_printf(1, disp_y + i, "%s", dispcur->linebuf); i++; } precur = cur; strcpy(prebuf, cur->linebuf); } else if(strlen(cur->linebuf) != strlen(prebuf)){ i = 0; for(dispcur = disptop; dispcur != dispbot->next; dispcur = dispcur->next){ if(dispcur == cur){ xy_printf(1, disp_y + i, "%s", dispcur->linebuf); } i++; } precur = cur; strcpy(prebuf, cur->linebuf); } #ifndef UNIX cursor_on(); #endif return 0; } int except_esc_len(char *str, int *loc) { int i; int ch; int loop; ch = 0; for(i = 0; i < strlen(str); i++){ if(*(str + i) == ESC){ loop = 1; while(loop){ i++; switch(*(str + i)){ case 'h': case 'l': case 'S': case 'U': case 'm': case 'K': case 'J': case 'M': case 'L': case 'A': case 'B': case 'C': case 'D': case 'E': loop = 0; break; } } } else{ ch++; } if(ch == (m_col + 1)){ *(loc) = i; } } return ch; } int free_displist(void) { DISPLIST *free_node; cur = top; cur = cur->next; while(1){ free_node = cur; cur = cur->next; free(free_node->linebuf); free(free_node); if(cur == top){ free(cur->linebuf); free(cur); break; } } return 0; } int scrl_up(void) { DISPLIST *dispcur; int i; if(scrl_top == NULL){ scrl_top = disptop->pre; scrl_bot = dispbot->pre; } else{ if(scrl_top->pre == dispbot){ bell(); return -1; } scrl_top = scrl_top->pre; scrl_bot = scrl_bot->pre; } #ifndef UNIX cursor_off(); #endif xy_clr_to_right_bottom(1, disp_y); i = 0; for(dispcur=scrl_top; dispcur != scrl_bot->next; dispcur = dispcur->next){ xy_printf(1, disp_y + i, "%s", dispcur->linebuf); i++; } xy(LAST_X, LAST_Y); #ifndef UNIX cursor_on(); #endif return 0; } int scrl_down(void) { DISPLIST *dispcur; int i; if(scrl_top == NULL){ bell(); return -1; } else{ if(scrl_bot == dispbot){ bell(); return -1; } scrl_top = scrl_top->next; scrl_bot = scrl_bot->next; } #ifndef UNIX cursor_off(); #endif xy_clr_to_right_bottom(1, disp_y); i = 0; for(dispcur=scrl_top; dispcur != scrl_bot->next; dispcur = dispcur->next){ xy_printf(1, disp_y + i, "%s", dispcur->linebuf); i++; } xy(LAST_X, LAST_Y); #ifndef UNIX cursor_on(); #endif return 0; }