📄 new_curse.c
字号:
temp |= Temp_Stack[--place]; Temp_Stack[place++] = temp; } else if (*Otemp == '^') { Otemp++; temp = Temp_Stack[--place]; temp ^= Temp_Stack[--place]; Temp_Stack[place++] = temp; } else if (*Otemp == '=') { Otemp++; temp = Temp_Stack[--place]; temp = (temp == Temp_Stack[--place]); Temp_Stack[place++] = temp; } else if (*Otemp == '>') { Otemp++; temp = Temp_Stack[--place]; temp = temp > Temp_Stack[--place]; Temp_Stack[place++] = temp; } else if (*Otemp == '<') { Otemp++; temp = Temp_Stack[--place]; temp = temp < Temp_Stack[--place]; Temp_Stack[place++] = temp; } else if (*Otemp == 'c') { Otemp++; putchar(Temp_Stack[--place]); } else if (*Otemp == 'i') { Otemp++; p[1]++; p[2]++; } else if (*Otemp == '%') { putchar(*Otemp); Otemp++; } else if (*Otemp == '!') { temp = ! Temp_Stack[--place]; Temp_Stack[place++] = temp; Otemp++; } else if (*Otemp == '~') { temp = ~Temp_Stack[--place]; Temp_Stack[place++] = temp; Otemp++; } else if (*Otemp == 'p') { Otemp++; Temp_Stack[place++] = p[*Otemp - '0']; Otemp++; } else if (*Otemp == 'P') { Otemp++; Temp_Stack[place++] = variable[*Otemp - 'a']; Otemp++; } else if (*Otemp == 'g') { Otemp++; variable[*Otemp - 'a'] = Temp_Stack[--place]; Otemp++; } else if (*Otemp == '\'') { Otemp++; Temp_Stack[place++] = *Otemp; Otemp++; Otemp++; } else if (*Otemp == '{') { Otemp++; temp = atoi(Otemp); Temp_Stack[place++] = temp; while (*Otemp != '}') Otemp++; Otemp++; } return(place);}void Info_Out(string, p_list, place) /* interpret the output string if necessary */char *string;int p_list[];int place;{ char *tchar; int delay; int temp; int Cond_FLAG; int EVAL; int Cond_Stack[128]; int Cond_place; int Stack[128]; int Top_of_stack; if (string == NULL) return; Cond_FLAG = FALSE; Cond_place = 0; Top_of_stack = 0; p[0] = 0; p[1] = 0; p[2] = 0; p[3] = 0; p[4] = 0; p[5] = 0; p[6] = 0; p[7] = 0; p[8] = 0; p[9] = 0; if (p_list != NULL) { for (temp = 1; (place != 0); temp++) { p[temp] = p_list[--place]; } } delay = 0; Otemp = string; while (*Otemp != (char) NULL) { if (*Otemp == '%') { Otemp++; if ((*Otemp == '?') || (*Otemp == 't') || (*Otemp == 'e') || (*Otemp == ';')) { if (*Otemp == '?') { Otemp++; Cond_FLAG = TRUE; EVAL = TRUE; while (EVAL) { /* | find the end of the | conditional statement */ while ((strncmp(Otemp, "%t", 2)) && (*Otemp != (char) NULL)) { /* | move past '%' */ Otemp++; Cond_place = Operation(Cond_Stack, Cond_place); } /* | if condition is true */ if ((Cond_place > 0) && (Cond_Stack[Cond_place-1])) { /* | end conditional | parsing */ EVAL = FALSE; Otemp++; Otemp++; } else /* condition is false */ { /* | find 'else' or end | of if statement */ while ((strncmp(Otemp, "%e", 2)) && (strncmp(Otemp, "%;", 2)) && (*Otemp != (char) NULL)) Otemp++; /* | if an 'else' found */ if ((*Otemp != (char) NULL) && (!strncmp(Otemp, "%e", 2))) { Otemp++; Otemp++; tchar = Otemp; /* | check for 'then' part */ while ((*tchar != (char) NULL) && (strncmp(tchar, "%t", 2)) && (strncmp(tchar, "%;", 2))) tchar++; /* | if end of string */ if (*tchar == (char) NULL) { EVAL = FALSE; Cond_FLAG = FALSE; Otemp = tchar; } /* | if end of if found, | set up to parse | info */ else if (!strncmp(tchar, "%;", 2)) EVAL = FALSE; /* | otherwise, check | conditional in | 'else' */ } /* | if end of if found, | get out of if | statement */ else if ((*Otemp != (char) NULL) && (!strncmp(Otemp, "%;", 2))) { EVAL = FALSE; Otemp++; Otemp++; } else /* Otemp == NULL */ { EVAL = FALSE; Cond_FLAG = FALSE; } } } } else { Otemp++; Cond_FLAG = FALSE; if (*Otemp != ';') { while ((*Otemp != (char) NULL) && (strncmp(Otemp, "%;", 2))) Otemp++; if (*Otemp != (char) NULL) { Otemp++; Otemp++; } } else Otemp++; } } else { Top_of_stack = Operation(Stack, Top_of_stack); } } else if (!strncmp(Otemp, "$<", 2)) { Otemp++; Otemp++; delay = atoi(Otemp); while (*Otemp != '>') Otemp++; Otemp++; chars = delay * chars_per_millisecond; delay = chars; if ((chars - delay) > 0.0) delay++; if (String_table[pc__] == NULL) temp = 0; else temp = *String_table[pc__]; for (; delay > 0; delay--) putc(temp, stdout); } else { putchar(*Otemp); Otemp++; } } fflush(stdout);}#endifvoid wmove(window, row, column) /* move cursor to indicated position in window */WINDOW *window;int row, column;{ if ((row < window->Num_lines) && (column < window->Num_cols)) { window->LX = column; window->LY = row; }}void clear_line(line, column, cols)struct _line *line;int column;int cols;{ int j; if (column > line->last_char) { for (j = line->last_char; j < column; j++) { line->row[j] = ' '; line->attributes[j] = (char) NULL; } } line->last_char = column; line->row[column] = (char) NULL; line->attributes[column] = (char) NULL; line->changed = TRUE;}void werase(window) /* clear the specified window */WINDOW *window;{ int i; struct _line *tmp; window->SCROLL_CLEAR = CLEAR; window->scroll_up = window->scroll_down = 0; for (i = 0, tmp = window->first_line; i < window->Num_lines; i++, tmp = tmp->next_screen) clear_line(tmp, 0, window->Num_cols);}void wclrtoeol(window) /* erase from current cursor position to end of line */WINDOW *window;{ int column, row; struct _line *tmp; window->SCROLL_CLEAR = CHANGE; column = window->LX; row = window->LY; for (row = 0, tmp = window->first_line; row < window->LY; row++) tmp = tmp->next_screen; clear_line(tmp, column, window->Num_cols);}void wrefresh(window) /* flush all previous output */WINDOW *window;{ wnoutrefresh(window);#ifdef DIAG{ struct _line *temp; int value; fprintf(stderr, "columns=%d, lines=%d, SC=%d, SR=%d\n",window->Num_cols, window->Num_lines, window->SC, window->SR); for (value = 0, temp = window->first_line; value < window->Num_lines; value++, temp = temp->next_screen) { if (temp->number == -1) fprintf(stderr, "line moved "); if (temp->scroll) fprintf(stderr, "scroll_x is set: "); fprintf(stderr, "lc%d=%s|\n", temp->last_char, temp->row); } fprintf(stderr, "+-------------------- virtual screen ----------------------------------------+\n"); fprintf(stderr, "columns=%d, lines=%d \n",virtual_scr->Num_cols, virtual_scr->Num_lines); for (value = 0, temp = virtual_scr->first_line; value < virtual_scr->Num_lines; value++, temp = temp->next_screen) { if (temp->number == -1) fprintf(stderr, "line moved "); if (temp->scroll) fprintf(stderr, "scroll_x is set: "); fprintf(stderr, "lc%d=%s|\n", temp->last_char, temp->row); } fprintf(stderr, "columns=%d, lines=%d \n",curscr->Num_cols, curscr->Num_lines); for (value = 0, temp = curscr->first_line; value < curscr->Num_lines; value++, temp = temp->next_screen) fprintf(stderr, "line=%s|\n", temp->row);}#endif doupdate(); virtual_scr->SCROLL_CLEAR = FALSE; virtual_scr->scroll_down = virtual_scr->scroll_up = 0; fflush(stdout);}void touchwin(window)WINDOW *window;{ struct _line *user_line; int line_counter = 0; for (line_counter = 0, user_line = window->first_line; line_counter < window->Num_lines; line_counter++) { user_line->changed = TRUE; } window->SCROLL_CLEAR = TRUE;}void wnoutrefresh(window)WINDOW *window;{ struct _line *user_line; struct _line *virtual_line; int line_counter = 0; int user_col = 0; int virt_col = 0; if (window->SR >= virtual_scr->Num_lines) return; user_line = window->first_line; virtual_line = virtual_scr->first_line; virtual_scr->SCROLL_CLEAR = window->SCROLL_CLEAR; virtual_scr->LX = window->LX + window->SC; virtual_scr->LY = window->LY + window->SR; virtual_scr->scroll_up = window->scroll_up; virtual_scr->scroll_down = window->scroll_down; if ((last_window_refreshed == window) && (!window->SCROLL_CLEAR)) return; for (line_counter = 0; line_counter < window->SR; line_counter++) { virtual_line = virtual_line->next_screen; } for (line_counter = 0; (line_counter < window->Num_lines) && ((line_counter + window->SR) < virtual_scr->Num_lines); line_counter++) { if ((last_window_refreshed != window) || (user_line->changed) || ((SCROLL | CLEAR) & window->SCROLL_CLEAR)) { for (user_col = 0, virt_col = window->SC; (virt_col < virtual_scr->Num_cols) && (user_col < user_line->last_char); virt_col++, user_col++) { virtual_line->row[virt_col] = user_line->row[user_col]; virtual_line->attributes[virt_col] = user_line->attributes[user_col]; } for (user_col = user_line->last_char, virt_col = window->SC + user_line->last_char; (virt_col < virtual_scr->Num_cols) && (user_col < window->Num_cols); virt_col++, user_col++) { virtual_line->row[virt_col] = ' '; virtual_line->attributes[virt_col] = (char) NULL; } } if (virtual_scr->Num_cols != window->Num_cols) { if (virtual_line->last_char < (user_line->last_char + window->SC)) { if (virtual_line->row[virtual_line->last_char] == (char) NULL) virtual_line->row[virtual_line->last_char] = ' '; virtual_line->last_char = min(virtual_scr->Num_cols, (user_line->last_char + window->SC)); } } else virtual_line->last_char = user_line->last_char; virtual_line->row[virtual_line->last_char] = (char) NULL; virtual_line->changed = user_line->changed; virtual_line = virtual_line->next_screen; user_line = user_line->next_screen; } window->SCROLL_CLEAR = FALSE; window->scroll_up = window->scroll_down = 0; last_window_refreshed = window;}void flushinp() /* flush input */{}void ungetch(c) /* push a character back on input */int c;{ if (bufp < 100) in_buff[bufp++] = c;}#ifdef BSD_SELECTint timed_getchar(){ struct timeval tv; fd_set fds; int ret_val; int nfds = 1; char temp; FD_ZERO(&fds); tv.tv_sec = 0; tv.tv_usec = 500000; /* half a second */ FD_SET(0, &fds); Time_Out = FALSE; /* just in case */ ret_val = select(nfds, &fds, 0, 0, &tv); /* | if ret_val is less than zero, there was no input | otherwise, get a character and return it */ if (ret_val <= 0) { Time_Out = TRUE; return(-1); } return(read(0, &temp, 1)? temp : -1);}#endifint wgetch(window) /* get character from specified window */WINDOW *window;{ int in_value; char temp;#ifndef SYS5 int old_arg;#endif /* SYS5 */#ifdef BSD_SELECT if (Noblock) in_value = ((bufp > 0) ? in_buff[--bufp] : timed_getchar()); else in_value = ((bufp > 0) ? in_buff[--bufp] : read(0, &temp, 1)? temp : -1);#else /* BSD_SELECT */#ifdef SYS5 in_value = ((bufp > 0) ? in_buff[--bufp] : (read(0, &temp, 1)> 0) ? temp : -1);#else /* SYS5 */ if (Noblock) { Time_Out = FALSE; old_arg = fcntl(0, F_GETFL, 0); in_value = fcntl(0, F_SETFL, old_arg | FNDELAY); } in_value = ((bufp > 0) ? in_buff[--bufp] : read(0, &temp, 1)? temp : -1); if (Noblock) { fcntl(0, F_SETFL, old_arg); if (Time_Out) in_value = -1; }#endif /* SYS5 */#endif /* BSD_SELECT */ if (in_value != -1) { in_value &= 0xff; if ((Parity) && (Num_bits < 8)) /* strip eighth bit if parity in use */ in_value &= 0177; } else if (interrupt_flag) { interrupt_flag = FALSE; in_value = wgetch(window); } if ((in_value == '\033') || (in_value == '\037'))/* escape character */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -