#include "tt.h"
#define CL(x) COLOR_PAIR(x)
#define isprint(x) my_isprint(x)
#define NEW_LINES 5
#define NEW_COLS 48
#define INT_32_TYPE int
static int signal_if_ik;
static jmp_buf jmpint;
static jmp_buf jmp_chinese;
static jmp_buf jmp_chinese_error;
static chtype *ler;
void tt_exit()
{
delwin(stdscr);
if (ler != NULL)
free(ler);
endwin();
}
void slg_exit(int value)
{
WINDOW *exitwin;
int inch, ik = 0;
if (!signal_if_ik)
longjmp(jmpint, 1);
exitwin = newwin(2, 14, (LINES - 3) / 2, (COLS - 15) / 2);
assert(exitwin != NULL);
WBKGD(exitwin, 2);
wattron(exitwin, A_BOLD);
mvwaddstr(exitwin, 0, 2, "是否要退出");
wattron(exitwin, COLOR_PAIR(3));
mvwaddstr(exitwin, 1, 4, "是");
wattroff(exitwin, COLOR_PAIR);
mvwaddch(exitwin, 1, 6, '/');
mvwaddstr(exitwin, 1, 7, "否");
touchwin(exitwin);
wrefresh(exitwin);
while ((inch = getch()) != '\n' && inch != ' ') {
if (inch == KEY_LEFT || inch == KEY_RIGHT)
ik ^= 1;
if (ik == 0) {
wattron(exitwin, COLOR_PAIR(3));
mvwaddstr(exitwin, 1, 4, "是");
wattroff(exitwin, COLOR_PAIR);
mvwaddstr(exitwin, 1, 7, "否");
} else {
wattroff(exitwin, COLOR_PAIR(3));
mvwaddstr(exitwin, 1, 4, "是");
wattron(exitwin, COLOR_PAIR(3));
mvwaddstr(exitwin, 1, 7, "否");
}
wrefresh(exitwin);
}
delwin(exitwin);
if (!ik) {
if (signal_if_ik == 1)
longjmp(jmpint, 1);
else
longjmp(jmp_chinese, 1);
}
touchwin(stdscr);
refresh();
}
void tt_letter(WINDOW *start_choose)
{
int letter_lines, letter_cols;
int inch, for_max;
int err_letter = 0, ik = 0, for_ik = 0, in_ik = 0;
time_t paa_letter, pbb_letter;
double max_time = 0;
wclear(start_choose);
wattron(start_choose, COLOR_PAIR(3));
mvwaddstr(start_choose, 2, 6, "小写字母");
wattroff(start_choose, COLOR_PAIR);
mvwaddstr(start_choose, 2, 48 - 14, "大写汉字");
wrefresh(start_choose);
while ((inch = getch()) != '\n' && inch != ' ') {
if (inch == KEY_LEFT || inch == KEY_RIGHT)
ik ^= 1;
if (ik == 0) {
wattron(start_choose, COLOR_PAIR(3));
mvwaddstr(start_choose, 2, 6, "小写字母");
wattroff(start_choose, COLOR_PAIR);
mvwaddstr(start_choose, 2, 48 - 14, "大写字母");
} else {
wattroff(start_choose, COLOR_PAIR(3));
mvwaddstr(start_choose, 2, 6, "小写字母");
wattron(start_choose, COLOR_PAIR(3));
mvwaddstr(start_choose, 2, 48 - 14, "大写字母");
}
wrefresh(start_choose);
}
ler = (chtype *) malloc(sizeof(chtype));
if (ler == NULL) {
puts("内存错误");
tt_exit();
exit(1);
}
signal_if_ik = 1;
switch (rand() % 3) {
case 0 :
for_max = 200;
break;
case 1 :
for_max = 300;
case 2 :
for_max = 500;
}
For_001:
clear();
bkgd(CL(3));
letter_lines = 0;
letter_cols = -3;
while (for_ik++ < for_max) {
if ((letter_cols += 3) > COLS - 1) {
letter_lines += 2;
letter_cols = 0;
}
if (letter_lines > LINES - 2)
break;
while ((inch = rand()) > RAND_OK_MAX)
;
if (!ik)
inch = inch % 26 + 'a';
else
inch = inch % 26 + 'A';
mvaddch(letter_lines, letter_cols, inch);
}
letter_lines = 1;
letter_cols = -3;
paa_letter = time(NULL);
while (in_ik++ < for_max) {
if ((letter_cols += 3) > COLS - 1) {
letter_lines += 2;
letter_cols = 0;
}
if (letter_lines > LINES - 1)
break;
*ler = mvinch(letter_lines - 1, letter_cols);
while ((inch = getch()) >= KEY_MIN && inch <= KEY_MAX || inch == '\n')
;
if (inch == (char) *ler) {
attron(CL(5));
mvaddch(letter_lines, letter_cols, inch);
} else {
++err_letter;
attron(CL(4));
mvaddch(letter_lines, letter_cols, inch);
printf("\a");
}
}
pbb_letter = time(NULL);
max_time += difftime(pbb_letter, paa_letter);
if (for_ik < for_max)
goto For_001;
max_time = for_max / (max_time / 60);
refresh();
wclear(start_choose);
wattroff(start_choose, COLOR_PAIR);
mvwaddstr(start_choose, 1, (48 - 23) / 2 - 1, "速 度 : 每分钟");
wattron(start_choose, COLOR_PAIR(6));
wprintw(start_choose, " %d ", (int) max_time);
wattroff(start_choose, COLOR_PAIR);
waddstr(start_choose, "个字母");
mvwaddstr(start_choose, 3, (48 - 23) / 2 - 1, "正确率: ");
wattron(start_choose, COLOR_PAIR(6));
wprintw(start_choose, "%d", (int) ((double) (for_max - err_letter) / for_max * 100));
waddstr(start_choose, "%");
touchwin(start_choose);
wrefresh(start_choose);
signal_if_ik = 0;
while (getch() != '\n')
;
}
void zero_array(char *tmp_array)
{
int ik = 0;
while (ik < BUFFER)
tmp_array[ik++] = 0;
}
void tab_delete(char *tmp_char)
{
int n_ik = 0, x_ik = 0, rd_if = 0;
char *paa = tmp_char, *p_head = tmp_char;
char *p_tmp;
char ch_if;
/*********************************************/
#if 1
while (*paa != '\0') {
x_ik = 1;
rd_if = 0;
if (*paa == '*')
++n_ik;
else
n_ik = 0;
if (n_ik == 10) {
*(paa - 9) = '\0';
while (*(paa + x_ik) != '\0') {
if ((ch_if = *(paa + x_ik)) != '\n'
&& ch_if != '\t' && ch_if != ' ')
rd_if = 1;
++x_ik;
}
if (rd_if) {
if (rand() % 100 > 49) {
/**(paa - 9) = '\0';*/
break;
}
else {
*p_head = -1;
p_tmp = paa;
while (*p_tmp != -1)
*p_tmp-- = -1;
}
} else {
/**(paa - 9) = '\0';*/
break;
}
}
++paa;
}
#endif
/*********************************************/
paa = p_head;
n_ik = 0;
while (*tmp_char == -1)
++tmp_char;
while (*tmp_char == '\n')
*tmp_char++ = -1;
while (*tmp_char != '\0') {
if (*tmp_char == '\n') {
while (*++tmp_char == '\n')
*tmp_char = -1;
}
paa = tmp_char;
if (*tmp_char == '\t')
*tmp_char = -1;
while (*tmp_char == ' ') {
++tmp_char;
n_ik = 1;
}
if (n_ik) {
if (*tmp_char == '\n') {
while (paa < tmp_char)
*paa++ = -1;
}
n_ik = 0;
}
++tmp_char;
}
for (paa = p_head; *paa != '\0'; ++paa)
if (*paa != -1)
*p_head++ = *paa;
while (*--p_head == '\n' || *p_head == ' ')
;
*++p_head = '\0';
}
char *print_n(char *tmp_char)
{
int y = 0, x = 0, sv_y, odd;
int mycmp(char const *, char const *);
clear();
attroff(COLOR_PAIR);
move(0, 0);
/*printw("%s", tmp_char);*/
sv_y = y;
odd = COLS - 1;
while (*tmp_char != '\0') {
int ik = 0;
if (*tmp_char >= 0 && *tmp_char <= 127) {
if (*tmp_char == '\n') {
y += 2;
x = 0;
} else {
printw("%c", *tmp_char);
x += 1;
}
++tmp_char;
} else {
while (ik++ < 3)
printw("%c", *tmp_char++);
x += 2;
}
if (x >= odd) {
y += 2;
x = 0;
}
if (y < LINES - 1)
move(y, x);
else
break;
}
return tmp_char;
}
int mycmp(char const *paa, char const *pbb)
{
int ik;
if (isprint(*paa))
if (*paa == *pbb)
return 1;
for (ik = 0; ik < 3; ++ik)
if (paa[ik] != pbb[ik])
return 0;
return 1;
}
int my_isprint(int inch)
{
if (inch >= 0 && inch <= 127)
return 1;
else
return 0;
}
void tt_chinese(WINDOW *start_choose)
{
int filedes, array_ik = 0, inspection_x = 0;
char array_chinese[BUFFER] = {0}, *pointer_chinese = array_chinese;
char *array_save = NULL;
if ((filedes = open("/etc/yjftt/chinese_txt", O_RDONLY)) == -1) {
if (errno != 0) {
wclear(start_choose);
wattroff(start_choose, COLOR_PAIR);
mvwaddstr(start_choose, 1, (48 - 29) /