void tstp(int ignored) { int y, x; int oy, ox; NOOP(ignored); /* * leave nicely */ getyx(curscr, oy, ox); mvcur(0, COLS - 1, LINES - 1, 0); endwin(); resetltchars(); fflush(stdout); md_tstpsignal(); /* * start back up again */ md_tstpresume(); raw(); noecho(); keypad(stdscr,1); playltchars(); clearok(curscr, TRUE); wrefresh(curscr); getyx(curscr, y, x); mvcur(y, x, oy, ox); fflush(stdout); curscr->_cury = oy; curscr->_curx = ox; }
PROC writeline(int y,int x,int start) { int endd,oxp; unsigned int size; char buf[MAXCOLS+1]; unsigned int bi = 0; endd = fseekeol(start); if (start==0 || core[start-1] == EOL) mvcur(y, 0); else mvcur(y, x); oxp = curpos.x; while (start < endd && curpos.x < COLS) { size = format(&buf[bi],core[start++]); bi += size; curpos.x += size; } if (list) { buf[bi++] = '$'; curpos.x++; } size = min(bi,COLS-oxp); if (size > 0) { zwrite(buf, size); } if (curpos.x < COLS) strput(CE); }
int main (int argc, char **argv) { if (argc > 1) { if (strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-h")==0) chrono_help (); } window = initscr (); noecho (); atexit (chrono_exit); thr01_start (); int c; while (1) { c = getch (); if (c == 'H' || c == 'h') { show_help = !show_help; mvcur (0, 0, 2, 2); if (show_help) chrono_help (); else { int cnt; for (cnt = 0; cnt < getmaxx (window); cnt++) fputc (' ', stdout); fflush (stdout); } mvcur (2, 2, 0, 0); } else if (c == ' ' || c == 'P' || c == 'p') { paused = !paused; if (paused) { gettimeofday (&tvp0, NULL); mvcur (0, 0, 0, 16); printf ("paused"); fflush (stdout); } else { gettimeofday (&tvp1, NULL); tvdiff (&tvp0, &tvp1, &tvpd); pause_time += tvpd.tv_sec; pause_days = pause_time / 60 / 60 / 24; pause_hours = (pause_time - (pause_days*24*60*60)) / 60 / 60; pause_minutes = (pause_time - (pause_days*24*60*60) - (pause_hours*60*60)) / 60; pause_seconds = (pause_time - (pause_days*24*60*60) - (pause_hours*60*60) - (pause_minutes*60)); printf ("%s \n\r%03u days %02u:%02u:%02u:%03ld paused", chrono_str, pause_days, pause_hours, pause_minutes, pause_seconds, tvpd.tv_usec/1000); mvcur (1, getcurx(window), 0, strlen(chrono_str)); fflush (stdout); } } else if (c == 'Q' || c == 'q') exit (0); } return 0; }
/* * Suspend/Resume */ static errr Term_xtra_gcu_alive(int v) { /* Suspend */ if (!v) { /* Go to normal keymap mode */ keymap_norm(); /* Restore modes */ nocbreak(); echo(); nl(); /* Hack -- make sure the cursor is visible */ Term_xtra(TERM_XTRA_SHAPE, 1); /* Flush the curses buffer */ (void)refresh(); #ifdef SPECIAL_BSD /* this moves curses to bottom right corner */ mvcur(curscr->cury, curscr->curx, LINES - 1, 0); #else /* this moves curses to bottom right corner */ mvcur(getcury(curscr), getcurx(curscr), LINES - 1, 0); #endif /* Exit curses */ endwin(); /* Flush the output */ (void)fflush(stdout); } /* Resume */ else { /* Refresh */ /* (void)touchwin(curscr); */ /* (void)wrefresh(curscr); */ /* Restore the settings */ cbreak(); noecho(); nonl(); /* Go to angband keymap mode */ keymap_game(); } /* Success */ return (0); }
void *thr01_func (void *arg) { gettimeofday (&tv0, NULL); while (1) { if (paused) { usleep (10000); continue; } gettimeofday (&tvc, NULL); if (!show_help_once) { if ((tvc.tv_sec - tv0.tv_sec) < 5) { cx_prev = getcurx (window); cy_prev = getcury (window); mvcur (cy_prev, cx_prev, 2, 2); chrono_help (); mvcur (2, getcurx (window), cy_prev, cx_prev); fflush (stdout); } else { show_help_once = 1; cx_prev = getcurx (window); cy_prev = getcury (window); mvcur (cy_prev, cx_prev, 2, 2); int cnt; for (cnt = 0; cnt < getmaxx(window); cnt++) fputc (' ', stdout); mvcur (2, getmaxx(window)-1, cy_prev, cx_prev); fflush (stdout); } } tvdiff (&tv0, &tvc, &tvd); seconds = tvd.tv_sec; if (pause_time) seconds -= pause_time; days = seconds / 60 / 60 / 24; if (days) seconds -= days * 60 * 60 * 24; hours = seconds / 60 / 60; if (hours) seconds -= hours * 60 * 60; minutes = seconds / 60; if (minutes) seconds -= minutes * 60; if (days) sprintf (chrono_str, "\r%d day%s %02d:%02d:%02d:%03d", days, (days > 1)?"s":"", hours, minutes, seconds, (int)tvd.tv_usec / 1000); else sprintf (chrono_str, "\r%02d:%02d:%02d:%03d", hours, minutes, seconds, (int)tvd.tv_usec / 1000); printf ("%s", chrono_str); fflush (stdout); usleep (10000); } return NULL; }
/* * display_redraw_screen: * redraw the screen */ void display_redraw_screen(void) { int i; mvcur(cur_row, cur_col, 0, 0); for (i = 0; i < SCREEN_HEIGHT - 1; i++) { fwrite(screen[i], sizeof (char), SCREEN_WIDTH, stdout); if (COLS > SCREEN_WIDTH || (COLS == SCREEN_WIDTH && !AM)) putchar('\n'); } fwrite(screen[SCREEN_HEIGHT - 1], sizeof (char), SCREEN_WIDTH - 1, stdout); mvcur(SCREEN_HEIGHT - 1, SCREEN_WIDTH - 1, cur_row, cur_col); }
void parser (void) { char command_line [80]; int quit=0; noecho(); cbreak(); wtimeout(command_win, 100); keypad(command_win, 1); while (!quit) { /* Terminal screen size has changed */ if (redraw_request) { redraw_all(); redraw_request=0; } wmove (command_win,0,0);wclrtoeol (command_win); wmove(command_win, 0, 0); wprintw(command_win, "ext2ed > "); read_line(command_line); /* If only enter was pressed, recall the last command */ if (*command_line==0) strcpy (command_line,last_command_line); mvcur (-1,-1,LINES-COMMAND_WIN_LINES + 1,0); strcpy (last_command_line,command_line); /* Save this command in our tiny cache */ /* And call dispatch to do the actual job */ quit=dispatch (command_line); } }
int main(int argc, char *argv[]) { int x, i; for (i = 1; i < argc; ++i) { if (*argv[i] == '-') { option(argv[i] + 1); } } initscr(); if (INTR == 0) { signal(SIGINT, SIG_IGN); } noecho(); leaveok(stdscr, TRUE); scrollok(stdscr, FALSE); (void)curs_set(0); for (x = COLS - 1; ; --x) { if (LOGO == 0) { if (add_D51(x) == ERR) break; } else { if (add_sl(x) == ERR) break; } refresh(); usleep(20000); } mvcur(0, COLS - 1, LINES - 1, 0); (void)curs_set(1); endwin(); return 0; }
PROC scroll(bool down) { int i; if (count <= 0) count = dofscroll; strput(CURoff); if (down) { curr = min(bufmax-1, nextline(TRUE, curr, count)); i = min(bufmax-1, nextline(TRUE, pend, count)); if (i > pend) scrollforward(i); } else { curr = bseekeol(max(0,nextline(FALSE, curr, count))); i = bseekeol(max(0,nextline(FALSE, ptop, count))); if (i < ptop) if (canUPSCROLL) scrollback(i); else { ptop = i; setend(); redisplay(TRUE); } } strput(CURon); setpos(skipws(curr)); /* initialize new position - first nonwhite */ yp = setY(curr); mvcur(yp, xp); /* go there */ }
/* * die: Die properly. */ void die(int n) { mvcur(0, COLS - 1, LINES - 1, 0); endwin(); putchar('\n'); exit(0); }
void diesoft(void) { #ifndef USE_SLCURSES mvcur(0, COLS-1, LINES-1, 0); /* move curser to lower left corner */ #endif endwin(); /* make terminal the way it was */ }
int main(int argc, char *argv[]) { int x, i; for (i = 1; i < argc; ++i) { if (*argv[i] == '-') { option(argv[i] + 1); } } initscr(); signal(SIGINT, SIG_IGN); noecho(); leaveok(stdscr, TRUE); scrollok(stdscr, FALSE); for (x = COLS - 1; ; --x) { if (LOGO == 1) { if (add_sl(x) == ERR) break; } else if (C51 == 1) { if (add_C51(x) == ERR) break; } else { if (add_D51(x) == ERR) break; } refresh(); usleep(40000); } mvcur(0, COLS - 1, LINES - 1, 0); endwin(); }
void sym_getword(void) { uint tries; off_t pos; int buflen; char symbuf[1 + BUFSIZ], *sym, *end; size_t symlen; for (tries = 0; tries < MAXBADWORDS; tries++) { pos = arc4random_uniform(symsize); if (lseek(symfd, pos + symoffs, SEEK_SET) == -1) continue; buflen = read(symfd, symbuf, BUFSIZ); if (buflen < 0) continue; /* * The buffer is hopefully large enough to hold at least * a complete symbol, i.e. two occurences of NUL, or * one occurence of NUL and the buffer containing the end * of the string table. We make sure the buffer will be * NUL terminated in all cases. */ if (buflen + pos >= symsize) buflen = symsize - pos; *(end = symbuf + buflen) = '\0'; for (sym = symbuf; *sym != '\0'; sym++) ; if (sym == end) continue; symlen = strlen(++sym); if (symlen < MINLEN || symlen > MAXLEN) continue; /* ignore symbols containing dots or dollar signs */ if (strchr(sym, '.') != NULL || strchr(sym, '$') != NULL) continue; break; } if (tries >= MAXBADWORDS) { mvcur(0, COLS - 1, LINES -1, 0); endwin(); errx(1, "can't seem a suitable symbol in %s", Dict_name); } strlcpy(Word, sym, sizeof Word); strlcpy(Known, sym, sizeof Known); for (sym = Known; *sym != '\0'; sym++) { if (*sym == '-') *sym = '_'; /* try not to confuse player */ if (isalnum((unsigned char)*sym)) *sym = '-'; } }
void die(){ signal( SIGINT, SIG_IGN ); mvcur( 0, COLS - 1, LINES - 1, 0 ); endwin(); exit( 1 ); }
/* * Nuke the "curses" system */ static void Term_nuke_gcu(term *t) { int x, y; term_data *td = (term_data *)(t->data); /* Delete this window */ delwin(td->win); /* Count nuke's, handle last */ if (--active != 0) return; /* Hack -- make sure the cursor is visible */ Term_xtra(TERM_XTRA_SHAPE, 1); #ifdef A_COLOR /* Reset colors to defaults */ start_color(); #endif /* This moves curses to bottom right corner */ getyx(stdscr, y, x); mvcur(y, x, LINES - 1, 0); /* Flush the curses buffer */ (void)refresh(); /* Exit curses */ endwin(); /* Flush the output */ (void)fflush(stdout); /* Normal keymap */ keymap_norm(); }
PROC refresh(int y,int x,int start,int endd, bool rest) { int sp; #if ST /* turn the cursor off */ asm(" clr.l -(sp) "); asm(" move.w #21,-(sp) "); asm(" trap #14 "); asm(" addq.l #6,sp "); #endif sp = start; while (sp <= endd) { writeline(y, x, sp); sp = 1+fseekeol(sp); y++; x = 0; } if (rest && sp >= bufmax) while (y<LINES-1) { /* fill screen with ~ */ mvcur(y, 0); printch('~'); strput(CE); y++; } #if ST /* turn the cursor back on */ asm(" clr.w -(sp) "); asm(" move.w #1,-(sp) "); asm(" move.w #21,-(sp) "); asm(" trap #14 "); asm(" addq.l #6,sp "); #endif }
void display_menu(MENU *menu) { int i; cls(); title(menu->title); mvcur(0, 0, STARTROW, STARTCOL); refresh(); for (i = 0; i <= menu->num_items - 1; i++) { move(STARTROW + i, STARTCOL); standend(); addstr(menu->items[i]); refresh(); } center_text(STARTROW + menu->num_items + 2, "Enter a number, <up arrow>, or <down arrow>."); if (!level) { center_text(STARTROW + menu->num_items + 3, "Press 'q' to exit, <return> to confirm choice."); } else { center_text(STARTROW + menu->num_items + 3, "Press 'q' to exit, 'r' for main menu, " "<return> to confirm choice."); } if (!level) highlight(main_menu); }
int main(int argc, char *argv[]) { int x, i; for (i = 1; i < argc; ++i) { if (*argv[i] == '-') { option(argv[i] + 1); } } initscr(); signal(SIGINT, SIG_IGN); noecho(); curs_set(0); nodelay(stdscr, TRUE); leaveok(stdscr, TRUE); scrollok(stdscr, FALSE); for (x = COLS - 1; ; --x) { if (LOLI == 1) { if (add_lolitaso(x) == ERR) break; } else if (MAYAKA == 1) { if (add_mayakataso(x) == ERR) break; } else { if (add_erutaso(x) == ERR) break; } getch(); refresh(); usleep(40000); } mvcur(0, COLS - 1, LINES - 1, 0); endwin(); }
/* * tstp: * Handle stop and start signals */ static void tstp(int dummy) { int y, x; y = cur_row; x = cur_col; mvcur(cur_row, cur_col, HEIGHT, 0); cur_row = HEIGHT; cur_col = 0; _puts(VE); _puts(TE); fflush(stdout); tcsetattr(0, TCSADRAIN, &__orig_termios); kill(getpid(), SIGSTOP); signal(SIGTSTP, tstp); tcsetattr(0, TCSADRAIN, &saved_tty); _puts(TI); _puts(VS); cur_row = y; cur_col = x; _puts(tgoto(CM, cur_row, cur_col)); display_redraw_screen(); fflush(stdout); }
void start_display_buff(char *buff) { char buffer[5]; num_members++; if (moreflg) return; if (currow >= LINES - 2) { page++; currow++; mvcur(0, 0, currow, STARTCOL); refresh(); if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) { erase_line(currow, STARTCOL); show_text(currow, STARTCOL, "Flushing query..."); moreflg = 1; return; } clrwin(DISPROW + 2); currow = DISPROW + 2; show_text(currow, STARTCOL, "continued"); currow++; } show_text(currow, STARTCOL, buff); currow++; return; }
/* * display_move: * move the cursor */ void display_move(int y, int x) { mvcur(cur_row, cur_col, y, x); cur_row = y; cur_col = x; }
/* * display_clear_eol: * clear to end of line, without moving cursor */ void display_clear_eol(void) { if (CE != NULL) tputs(CE, 1, __cputchar); else { fwrite(blanks, sizeof (char), SCREEN_WIDTH - cur_col, stdout); if (COLS != SCREEN_WIDTH) mvcur(cur_row, SCREEN_WIDTH, cur_row, cur_col); else if (AM) mvcur(cur_row + 1, 0, cur_row, cur_col); else mvcur(cur_row, SCREEN_WIDTH - 1, cur_row, cur_col); } memcpy(&screen[cur_row][cur_col], blanks, SCREEN_WIDTH - cur_col); }
static void _useceod(int topy, int boty) { short *begns, *begch; /* skip lines already blanked */ begch = _virtscr->_firstch + topy; begns = _BEGNS + topy; for (; topy < boty; ++topy, ++begns, ++begch) if (*begns < scrco || *begch == _REDRAW) break; else *begch = _INFINITY; /* nothing to do */ if (topy + 1 >= boty) return; /* see if bottom is clear */ for (begns = _BEGNS + boty; boty < scrli; ++boty, ++begns) if (*begns < scrco) return; /* use clear-screen if appropriate */ if (topy == 0) { /* SS: colors */ if (back_color_erase) _turn_off_background(); _PUTS(clear_screen, scrli); cy = 0; cx = 0; (void) werase(curscr); } else /* use clear-to-end-of-display or delete lines */ if (clr_eos || (parm_delete_line && !memory_below)) { (void) mvcur(cy, cx, topy, 0); /* LINTED */ cy = (short) topy; cx = 0; /* SS: colors */ if (back_color_erase) _turn_off_background(); _PUTS(clr_eos ? clr_eos : tparm_p1(parm_delete_line, scrli - topy), scrli - topy); /* update curscr */ /* LINTED */ curscr->_cury = (short) topy; curscr->_curx = 0; (void) wclrtobot(curscr); } else /* no hardware support */ return; /* correct the update structure */ (void) wtouchln(_virtscr, topy, scrli, FALSE); }
void sighandler(int signum) { signal(SIGINT, SIG_IGN); nocrmode(); echo(); mvcur(0, COLS-1, LINES-2, 0); endwin(); exit(0); }
/* * bye: * Leave the program, cleaning things up as we go. */ void bye(void) { signal(SIGINT, SIG_IGN); mvcur(0, COLS - 1, LINES - 1, 0); fflush(stdout); endwin(); putchar('\n'); }
endfly() { alarm(0); signal(SIGALRM, SIG_DFL); mvcur(0,COLS-1,LINES-1,0); endwin(); signal(SIGTSTP, SIG_DFL); signal(SIGINT, oldsig); }
/* * Die gracefully... */ void diehard(int signum) { signal(SIGINT, SIG_IGN); /* ignore all further interrupts */ signal(SIGTERM, SIG_IGN); /* ignore all further interrupts */ #ifndef USE_SLCURSES mvcur(0, COLS-1, LINES-1, 0); /* move curser to lower left corner */ #endif endwin(); /* make terminal the way it was */ exit(0); }
void kgetword() { uint tries; off_t pos; int buflen; char symbuf[1 + BUFSIZ], *sym, *end; size_t symlen; for (tries = 0; tries < MAXBADWORDS; tries++) { pos = (double) random() / (RAND_MAX + 1.0) * (double)ksymsize; if (lseek(ksyms, pos + ksymoffs, SEEK_SET) == -1) continue; buflen = read(ksyms, symbuf, BUFSIZ); if (buflen < 0) continue; /* * The buffer is hopefully large enough to hold at least * a complete symbol, i.e. two occurences of NUL, or * one occurence of NUL and the buffer containing the end * of the string table. We make sure the buffer will be * NUL terminated in all cases. */ if (buflen + pos >= ksymsize) buflen = ksymsize - pos; *(end = symbuf + buflen) = '\0'; for (sym = symbuf; *sym != '\0'; sym++) ; if (sym == end) continue; symlen = strlen(++sym); if (symlen < MINLEN || symlen > MAXLEN) continue; break; } if (tries >= MAXBADWORDS) { mvcur(0, COLS - 1, LINES -1, 0); endwin(); errx(1, "can't seem a suitable kernel symbol in %s", Dict_name); } strlcpy(Word, sym, sizeof Word); strlcpy(Known, sym, sizeof Known); for (sym = Known; *sym != '\0'; sym++) { if (*sym == '-') *sym = '_'; /* try not to confuse player */ if (isalpha(*sym)) *sym = '-'; } }
PROC scrollback(int curr) { mvcur(0,0); /* move to the top line */ do { ptop = bseekeol(ptop-1); strput(UpS); writeline(0, 0, ptop); } while (ptop > curr); setend(); }
/* * Suspend/Resume */ static errr Term_xtra_gcu_alive(int v) { int x, y; /* Suspend */ if (!v) { /* Go to normal keymap mode */ keymap_norm(); /* Restore modes */ nocbreak(); echo(); nl(); /* Hack -- make sure the cursor is visible */ Term_xtra(TERM_XTRA_SHAPE, 1); /* Flush the curses buffer */ (void)refresh(); /* Get current cursor position */ getyx(curscr, y, x); /* Move the cursor to bottom right corner */ mvcur(y, x, LINES - 1, 0); /* Exit curses */ endwin(); /* Flush the output */ (void)fflush(stdout); } /* Resume */ else { /* Refresh */ /* (void)touchwin(curscr); */ /* (void)wrefresh(curscr); */ /* Restore the settings */ cbreak(); noecho(); nonl(); /* Go to angband keymap mode */ keymap_game(); } /* Success */ return (0); }