Esempio n. 1
0
static void
setsane(DevEntry *p)
{
	p->t.c_iflag |= (ISTRIP | ICRNL | IXON);
	p->t.c_oflag = (ONLCR);
	p->t.c_lflag = (ICANON | ISIG | ECHO | ECHOE);
	p->t.c_cc[VINTR] = CNTRL ('c');
	p->t.c_cc[VEOL] = '\n';
	p->t.c_cc[VEOL2] = CNTRL ('c');
	p->t.c_cc[VERASE] = CNTRL ('h');
	p->t.c_cc[V_STOP] = CNTRL ('s');
	p->t.c_cc[V_START] = CNTRL ('q');
}
Esempio n. 2
0
void Game::render () {
	CNTRL ("game_render");
	window.clear ();
	if (v2u (R_WIND_WIDTH, R_WIND_HEIGHT) != window.getSize ()) {
		R_WIND_WIDTH = window.getSize ().x;
		R_WIND_HEIGHT = window.getSize ().y;
	}
	all_spaces["MAIN"]->render ();

	window.display ();
}
Esempio n. 3
0
int main()
{
	freopen ("data/inf/load.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
	Game *game = new Game ();
	if (game->init (true)) {
		while (game->running) {
			CNTRL ("run");
			game->update ();
			game->render ();
		}
		game->del ();
	}
	sf::Vector2f;
    return 0;
}
Esempio n. 4
0
void Game::update () {
	CNTRL ("game_update");
	rand ();
	if (!window.isOpen ()) {
		running = false;
		return;
	}
    sf::Event event;
	Global_Bool_Key_Pressed = false;
    while (window.pollEvent(event))
    {
		switch (event.type) {
        case sf::Event::Closed:
            window.close();
			running = false;
			break;
		case sf::Event::KeyPressed:
			Global_Bool_Key_Pressed = true;
		default:
			break;
		}
	}

	mouse_left_pressed = sf::Mouse::isButtonPressed (sf::Mouse::Left);

	float dt = (clock.restart ()).asSeconds ();
	if (dt > 1) {
		dt = 0;
	}
	if (all_spaces["MAIN"]->update (dt)) {
		running = false;
	}
	if (kb::isKeyPressed (kb::Escape)) {
		running = false;
	}
}
Esempio n. 5
0
void
process(int ch)
{
	int x,y;
	struct body *nh;

	x = head->x;
	y = head->y;
	switch(ch)
	{
#ifdef KEY_LEFT
		case KEY_LEFT:
#endif
		case 'h':
			x--; break;
#ifdef KEY_DOWN
		case KEY_DOWN:
#endif
		case 'j':
			y++; break;
#ifdef KEY_UP
		case KEY_UP:
#endif
		case 'k':
			y--; break;
#ifdef KEY_RIGHT
		case KEY_RIGHT:
#endif
		case 'l':
			x++; break;
		case 'H': x--; running = RUNLEN; ch = tolower(ch); break;
		case 'J': y++; running = RUNLEN/2; ch = tolower(ch); break;
		case 'K': y--; running = RUNLEN/2; ch = tolower(ch); break;
		case 'L': x++; running = RUNLEN; ch = tolower(ch); break;
		case '\f': setup(); return;
		case CNTRL('Z'): suspend(0); return;
		case CNTRL('C'): crash(); return;
		case CNTRL('D'): crash(); return;
		case ERR: leave(0); return;
		default: return;
	}
	lastch = ch;
	if (growing == 0)
	{
		display(tail, ' ');
		tail->next->prev = NULL;
		nh = tail->next;
		free(tail);
		tail = nh;
		visible_len--;
	}
	else growing--;
	display(head, BODY);
	wmove(tv, y, x);
	if (isdigit(ch = winch(tv)))
	{
		growing += ch-'0';
		prize();
		score += growing;
		running = 0;
		wmove(stw, 0, COLS - 12);
		wprintw(stw, "Score: %3d", score);
		wrefresh(stw);
	}
	else if(ch != ' ') crash();
	nh = newlink();
	nh->next = NULL;
	nh->prev = head;
	head->next = nh;
	nh->y = y;
	nh->x = x;
	display(nh, HEAD);
	head = nh;
	visible_len++;
	if (!(slow && running)) {
		wmove(tv, head->y, head->x);
		wrefresh(tv);
	}
}
Esempio n. 6
0
ttynew()
{
	struct tty	*ptty, *ttyalloc();

	ptty = ttyalloc();
	if(ptty == 0)
		return 0;
	ptty->tty_tchars = dfltchars;	/* struct copy */

	ptty->tty_cpid = getpid();

	ptty->tty_isema = screate(0);
	ptty->tty_iflags = 0;
	ptty->tty_istart = 0;
	ptty->tty_icount = 0;

	ptty->tty_osema = screate(OBLEN);
	ptty->tty_oflags = 0;
	ptty->tty_ostart = 0;
	ptty->tty_ocount = 0;
	return ptty;
}

#define	CNTRL(c) ((c) - 'a' + 1)

struct tchars  dfltchars = {
	'\b', CNTRL('c'), CNTRL('x'), CNTRL('v'), CNTRL('r'),
	CNTRL('d'), CNTRL('s'), CNTRL('q'), CNTRL('z'), CNTRL('w'),
	'\n', CNTRL('t')
};
Esempio n. 7
0
File: input.c Progetto: taysom/tau
void input (void)
{
	int	c;
	u64	x;
	u64	new_block = 0;

	NewNumber = TRUE;
	Radix = HEX;

	output();

	for (;;)	{

		if (new_block != BlockNum) {
			if (readDisk(new_block) != 0) {
				new_block = BlockNum;
			}
		}
		output();

		c = getch();

		switch (c) {
			/*
			 * Don't use these: CNTRL(C), CNTRL(Z), CNTRL(S),
			 *		CNTLR(Q), CNTRL(Y)
			 */
		case '?':			help();		break;
		case '_':	lastx();	neg();		break;
		case '+':	lastx();	add();		break;
		case '-':	lastx();	sub();		break;
		case '*':	lastx();	mul();		break;
		case '/':	lastx();	divide();	break;
		case '%':	lastx();	mod();		break;
		case '~':	lastx();	not();		break;
		case '&':	lastx();	and();		break;
		case '|':	lastx();	or();		break;
		case '^':	lastx();	xor();		break;
		case '<':	lastx();	leftShift();	break;
		case '>':	lastx();	rightShift();	break;
		case '.':	lastx();	swap();		break;
		case '!':	lastx();	store();	break;
		case '=':	lastx();	retrieve();	break;
		case '#':	lastx();	qrand();	break;

		case KEY_RESIZE:	/* Screen resize event - don't do anything */
				break;

		case KEY_LEFT:
		case 'h':	Current->left(); /* left one column */
				break;

		case KEY_DOWN:
		case 'j':	Current->down(); /* down one row */
				break;

		case KEY_UP:
		case 'k':	Current->up(); /* up one row */
				break;

		case KEY_RIGHT:
		case 'l':	Current->right(); /* right one column */
				break;

		case CNTRL('A'):clear(); /* switch to next format */
				next_format();
				break;

		case CNTRL('W'):clear(); /* switch to previous format */
				prev_format();
				break;

		case CNTRL('B'):/* Backward one block */
				if (BlockNum > 0) {
					new_block = BlockNum - 1;
				}
				break;

		case EOF:	/* Ignore EOF - send on resize */
				break;
		case 'q':
		case CNTRL('D'):finish(0); /* Exit */
				break;

		case CNTRL('F'):/* Forward a block */
				new_block = BlockNum + 1;
				break;

		case 'g':	/* Go to specified Block */
				lastx();
				x = pop();
				NewNumber = FALSE;
				new_block = x;
				break;

		case KEY_BACKSPACE:
		case KEY_DC:
		case CNTRL('H'):/* Delete last digit entered */
				push(pop() / RadixTable[Radix]);
				break;

		case CNTRL('I'):/* Next field */
				Current->next();
				break;

		case KEY_CLEAR:
		case CNTRL('L'):/* Refresh the display */
				wrefresh(curscr);
				break;

		case KEY_ENTER:
		case CNTRL('M'):/* Finish entry of number or duplicate top */
				if (!NewNumber)	{
					duptop();
				}
				NewNumber = FALSE;
				break;

		case CNTRL('P'):/* Push copy of current field */
				Current->copy();
				NewNumber = FALSE;
				break;

		case CNTRL('R'):/* Rotate from bottom of stack to top */
				rotate();
				break;

		case 'r':	/* Change radix */
				++Radix;
				if (Radix > UNSIGNED)	Radix = HEX;
				break;

		case CNTRL('T'):/* Reinitialize stack */
				initStack();
				NewNumber = TRUE;
				break;

		case CNTRL('U'):/* Push last x */
				push(Lastx);
				NewNumber = FALSE;
				break;

		case CNTRL('X'):/* Delete top of stack */
				(void)pop();
				push(0);
				NewNumber = TRUE;

		case 'Z':	/* Previous field */
				Current->prev();
				break;

		default:	/* Is it a digit? */
				if ((Radix == HEX) && isxdigit(c)) {
					if (isdigit(c)) {
						digit(c, '0');
					} else if (isupper(c)) {
						digit(c, 'A' - 10);
					} else {
						digit(c, 'a' - 10);
					}
				} else if ((Radix == UNSIGNED) && isdigit(c)) {
					digit(c, '0');
				} else if ((Radix == SIGNED) && isdigit(c)) {
					digit(c, '0');
				} else if (Radix == CHARACTER)	{
					digit(c, 0);
				} else {
					flash();
					sprintf(Error, "bad char=%d", c);
				}
				break;
		}
	}
}
Esempio n. 8
0
void Game::del () {
	CNTRL ("game_del");
	formap(p,end,std::string,space*,all_spaces) {
		p->second->del ();
		delete p->second;
	}
Esempio n. 9
0
int main()
{
    WINDOW *win, *boxing;
    int c;
    int x, y;

    initscr();

    signal(SIGINT, die);
    noecho();
    crmode();

    win = subwin(stdscr,
	    LINES / 2,
	    COLS / 2,
	    LINES / 4,
	    COLS / 4);
    scrollok(win, TRUE);

    boxing = subwin(stdscr,
	    LINES / 2 + 2,
	    COLS / 2 + 2,
	    LINES / 4 - 1,
	    COLS / 4 - 1);

    box(boxing, '!', '-');
    refresh();

    wmove(win, 0, 0);
    wrefresh(win);

    while ((c = wgetch(win)) != '#') {
	if (iscntrl(c)) {
	    switch (c) {
            case CNTRL('E'):
                werase(win);
                wrefresh(win);
                continue;

            case CNTRL('R'):
                wrefresh(curscr);
                continue;

            case CNTRL('['):
                getyx(win, y, x);
                c = wgetch(win);
                if (c == '[' || c == 'O')
                    c = wgetch(win);
                switch (c) {
                case 'H':
                    x = 0;
                    y = 0;
                    goto change;
                case 'A':
                    y--;
                    goto change;
                case 'B':
                    y++;
                    goto change;
                case 'C':
                    x++;
                    goto change;
                case 'D':
                    x--;
change:
                    if (x >= win->_maxx) {
                        x = 0;
                        y++;
                    }
                    if (y >= win->_maxy)
                        y = 0;
                    wmove(win, y, x);
                    wrefresh(win);
                    continue;
                default:
                    break;
                }
                break;
            default:
                continue;
	    }
        }
	waddch(win, c);
	wrefresh(win);
    }
    die(SIGINT);
}
Esempio n. 10
0
int cmdedit_read_input(char *prompt, char command[BUFSIZ])
{
	int break_out = 0;
	int lastWasTab = FALSE;
	unsigned char c;
	unsigned int ic;
#if ENABLE_FEATURE_COMMAND_EDITING_VI
	unsigned int prevc;
	int vi_cmdmode = 0;
#endif
	/* prepare before init handlers */
	cmdedit_y = 0;  /* quasireal y, not true work if line > xt*yt */
	len = 0;
	command_ps = command;

	getTermSettings(0, (void *) &initial_settings);
	memcpy(&new_settings, &initial_settings, sizeof(struct termios));
	new_settings.c_lflag &= ~ICANON;        /* unbuffered input */
	/* Turn off echoing and CTRL-C, so we can trap it */
	new_settings.c_lflag &= ~(ECHO | ECHONL | ISIG);
	/* Hmm, in linux c_cc[] not parsed if set ~ICANON */
	new_settings.c_cc[VMIN] = 1;
	new_settings.c_cc[VTIME] = 0;
	/* Turn off CTRL-C, so we can trap it */
#	ifndef _POSIX_VDISABLE
#       	define _POSIX_VDISABLE '\0'
#	endif
	new_settings.c_cc[VINTR] = _POSIX_VDISABLE;
	command[0] = 0;

	setTermSettings(0, (void *) &new_settings);
	handlers_sets |= SET_RESET_TERM;

	/* Now initialize things */
	cmdedit_init();
	/* Print out the command prompt */
	parse_prompt(prompt);

	while (1) {
		fflush(stdout);                 /* buffered out to fast */

		if (safe_read(0, &c, 1) < 1)
			/* if we can't read input then exit */
			goto prepare_to_die;

		ic = c;

#if ENABLE_FEATURE_COMMAND_EDITING_VI
		newdelflag = 1;
		if (vi_cmdmode)
			ic |= vbit;
#endif
		switch (ic) {
		case '\n':
		case '\r':
		vi_case( case '\n'|vbit: )
		vi_case( case '\r'|vbit: )
			/* Enter */
			goto_new_line();
			break_out = 1;
			break;
		case CNTRL('A'):
		vi_case( case '0'|vbit: )
			/* Control-a -- Beginning of line */
			input_backward(cursor);
			break;
		case CNTRL('B'):
		vi_case( case 'h'|vbit: )
		vi_case( case '\b'|vbit: )
		vi_case( case DEL|vbit: )
			/* Control-b -- Move back one character */
			input_backward(1);
			break;
		case CNTRL('C'):
		vi_case( case CNTRL('C')|vbit: )
			/* Control-c -- stop gathering input */
			goto_new_line();
#if !ENABLE_ASH
			command[0] = 0;
			len = 0;
			lastWasTab = FALSE;
			put_prompt();
#else
			len = 0;
			break_out = -1; /* to control traps */
#endif
			break;
		case CNTRL('D'):
			/* Control-d -- Delete one character, or exit
			 * if the len=0 and no chars to delete */
			if (len == 0) {
				errno = 0;
 prepare_to_die:
#if !ENABLE_ASH
				printf("exit");
				goto_new_line();
				/* cmdedit_reset_term() called in atexit */
				exit(EXIT_SUCCESS);
#else
				/* to control stopped jobs */
				len = break_out = -1;
				break;
#endif
			} else {
				input_delete(0);
			}
			break;
		case CNTRL('E'):
		vi_case( case '$'|vbit: )
			/* Control-e -- End of line */
			input_end();
			break;
		case CNTRL('F'):
		vi_case( case 'l'|vbit: )
		vi_case( case ' '|vbit: )
			/* Control-f -- Move forward one character */
			input_forward();
			break;
		case '\b':
		case DEL:
			/* Control-h and DEL */
			input_backspace();
			break;
		case '\t':
#if ENABLE_FEATURE_COMMAND_TAB_COMPLETION
			input_tab(&lastWasTab);
#endif
			break;
		case CNTRL('K'):
			/* Control-k -- clear to end of line */
			command[cursor] = 0;
			len = cursor;
			printf("\033[J");
			break;
		case CNTRL('L'):
		vi_case( case CNTRL('L')|vbit: )
			/* Control-l -- clear screen */
			printf("\033[H");
			redraw(0, len - cursor);
			break;
#if MAX_HISTORY > 0
		case CNTRL('N'):
		vi_case( case CNTRL('N')|vbit: )
		vi_case( case 'j'|vbit: )
			/* Control-n -- Get next command in history */
			if (get_next_history())
				goto rewrite_line;
			break;
		case CNTRL('P'):
		vi_case( case CNTRL('P')|vbit: )
		vi_case( case 'k'|vbit: )
			/* Control-p -- Get previous command from history */
			if (cur_history > 0) {
				get_previous_history();
				goto rewrite_line;
			} else {
				beep();
			}
			break;
#endif
		case CNTRL('U'):
		vi_case( case CNTRL('U')|vbit: )
			/* Control-U -- Clear line before cursor */
			if (cursor) {
				strcpy(command, command + cursor);
				redraw(cmdedit_y, len -= cursor);
			}
			break;
		case CNTRL('W'):
		vi_case( case CNTRL('W')|vbit: )
			/* Control-W -- Remove the last word */
			while (cursor > 0 && isspace(command[cursor-1]))
				input_backspace();
			while (cursor > 0 &&!isspace(command[cursor-1]))
				input_backspace();
			break;
#if ENABLE_FEATURE_COMMAND_EDITING_VI
		case 'i'|vbit:
			vi_cmdmode = 0;
			break;
		case 'I'|vbit:
			input_backward(cursor);
			vi_cmdmode = 0;
			break;
		case 'a'|vbit:
			input_forward();
			vi_cmdmode = 0;
			break;
		case 'A'|vbit:
			input_end();
			vi_cmdmode = 0;
			break;
		case 'x'|vbit:
			input_delete(1);
			break;
		case 'X'|vbit:
			if (cursor > 0) {
				input_backward(1);
				input_delete(1);
			}
			break;
		case 'W'|vbit:
			vi_Word_motion(command, 1);
			break;
		case 'w'|vbit:
			vi_word_motion(command, 1);
			break;
		case 'E'|vbit:
			vi_End_motion(command);
			break;
		case 'e'|vbit:
			vi_end_motion(command);
			break;
		case 'B'|vbit:
			vi_Back_motion(command);
			break;
		case 'b'|vbit:
			vi_back_motion(command);
			break;
		case 'C'|vbit:
			vi_cmdmode = 0;
			/* fall through */
		case 'D'|vbit:
			goto clear_to_eol;

		case 'c'|vbit:
			vi_cmdmode = 0;
			/* fall through */
		case 'd'|vbit: {
			int nc, sc;
			sc = cursor;
			prevc = ic;
			if (safe_read(0, &c, 1) < 1)
				goto prepare_to_die;
			if (c == (prevc & 0xff)) {
				/* "cc", "dd" */
				input_backward(cursor);
				goto clear_to_eol;
				break;
			}
			switch (c) {
			case 'w':
			case 'W':
			case 'e':
			case 'E':
				switch (c) {
				case 'w':   /* "dw", "cw" */
					vi_word_motion(command, vi_cmdmode);
					break;
				case 'W':   /* 'dW', 'cW' */
					vi_Word_motion(command, vi_cmdmode);
					break;
				case 'e':   /* 'de', 'ce' */
					vi_end_motion(command);
					input_forward();
					break;
				case 'E':   /* 'dE', 'cE' */
					vi_End_motion(command);
					input_forward();
					break;
				}
				nc = cursor;
				input_backward(cursor - sc);
				while (nc-- > cursor)
					input_delete(1);
				break;
			case 'b':  /* "db", "cb" */
			case 'B':  /* implemented as B */
				if (c == 'b')
					vi_back_motion(command);
				else
					vi_Back_motion(command);
				while (sc-- > cursor)
					input_delete(1);
				break;
			case ' ':  /* "d ", "c " */
				input_delete(1);
				break;
			case '$':  /* "d$", "c$" */
			clear_to_eol:
				while (cursor < len)
					input_delete(1);
				break;
			}
			break;
		}
		case 'p'|vbit:
			input_forward();
			/* fallthrough */
		case 'P'|vbit:
			put();
			break;
		case 'r'|vbit:
			if (safe_read(0, &c, 1) < 1)
				goto prepare_to_die;
			if (c == 0)
				beep();
			else {
				*(command + cursor) = c;
				putchar(c);
				putchar('\b');
			}
			break;
#endif /* FEATURE_COMMAND_EDITING_VI */

		case ESC:

#if ENABLE_FEATURE_COMMAND_EDITING_VI
			if (vi_mode) {
				/* ESC: insert mode --> command mode */
				vi_cmdmode = 1;
				input_backward(1);
				break;
			}
#endif
			/* escape sequence follows */
			if (safe_read(0, &c, 1) < 1)
				goto prepare_to_die;
			/* different vt100 emulations */
			if (c == '[' || c == 'O') {
		vi_case( case '['|vbit: )
		vi_case( case 'O'|vbit: )
				if (safe_read(0, &c, 1) < 1)
					goto prepare_to_die;
			}
			if (c >= '1' && c <= '9') {
				unsigned char dummy;

				if (safe_read(0, &dummy, 1) < 1)
					goto prepare_to_die;
				if (dummy != '~')
					c = 0;
			}
			switch (c) {
#if ENABLE_FEATURE_COMMAND_TAB_COMPLETION
			case '\t':                      /* Alt-Tab */

				input_tab(&lastWasTab);
				break;
#endif
#if MAX_HISTORY > 0
			case 'A':
				/* Up Arrow -- Get previous command from history */
				if (cur_history > 0) {
					get_previous_history();
					goto rewrite_line;
				} else {
					beep();
				}
				break;
			case 'B':
				/* Down Arrow -- Get next command in history */
				if (!get_next_history())
					break;
				/* Rewrite the line with the selected history item */
rewrite_line:
				/* change command */
				len = strlen(strcpy(command, history[cur_history]));
				/* redraw and go to eol (bol, in vi */
#if ENABLE_FEATURE_COMMAND_EDITING_VI
				redraw(cmdedit_y, vi_mode ? 9999:0);
#else
				redraw(cmdedit_y, 0);
#endif
				break;
#endif
			case 'C':
				/* Right Arrow -- Move forward one character */
				input_forward();
				break;
			case 'D':
				/* Left Arrow -- Move back one character */
				input_backward(1);
				break;
			case '3':
				/* Delete */
				input_delete(0);
				break;
			case '1':
			case 'H':
				/* <Home> */
				input_backward(cursor);
				break;
			case '4':
			case 'F':
				/* <End> */
				input_end();
				break;
			default:
				c = 0;
				beep();
			}
			break;

		default:        /* If it's regular input, do the normal thing */
#if ENABLE_FEATURE_NONPRINTABLE_INVERSE_PUT
			/* Control-V -- Add non-printable symbol */
			if (c == CNTRL('V')) {
				if (safe_read(0, &c, 1) < 1)
					goto prepare_to_die;
				if (c == 0) {
					beep();
					break;
				}
			} else
#endif
			{
#if ENABLE_FEATURE_COMMAND_EDITING_VI
				if (vi_cmdmode)  /* don't self-insert */
					break;
#endif
				if (!Isprint(c)) /* Skip non-printable characters */
					break;
			}

			if (len >= (BUFSIZ - 2))        /* Need to leave space for enter */
				break;

			len++;

			if (cursor == (len - 1)) {      /* Append if at the end of the line */
				*(command + cursor) = c;
				*(command + cursor + 1) = 0;
				cmdedit_set_out_char(0);
			} else {                        /* Insert otherwise */
				int sc = cursor;

				memmove(command + sc + 1, command + sc, len - sc);
				*(command + sc) = c;
				sc++;
				/* rewrite from cursor */
				input_end();
				/* to prev x pos + 1 */
				input_backward(cursor - sc);
			}

			break;
		}
		if (break_out)                  /* Enter is the command terminator, no more input. */
			break;

		if (c != '\t')
			lastWasTab = FALSE;
	}