Esempio n. 1
0
/* Displays contents read from the fp in the other pane starting from the second
 * line and second column.  The wrapped parameter determines whether lines
 * should be wrapped. */
static void
view_file(FILE *fp, int wrapped)
{
	const size_t max_width = other_view->window_width - 1;
	const size_t max_y = other_view->window_rows - 1;

	char line[1024];
	int line_continued = 0;
	int y = LINE;
	const char *res = get_line(fp, line, sizeof(line));
	esc_state state;
	esc_state_init(&state, &other_view->cs.color[WIN_COLOR]);
	while(res != NULL && y <= max_y)
	{
		int offset;
		int printed;
		const size_t len = add_to_line(fp, max_width, line, sizeof(line));
		if(!wrapped && line[len - 1] != '\n')
		{
			skip_until_eol(fp);
		}

		offset = esc_print_line(line, other_view->win, COL, y, max_width, 0, &state,
				&printed);
		y += !wrapped || (!line_continued || printed);
		line_continued = line[len - 1] != '\n';

		if(!wrapped || shift_line(line, len, offset))
		{
			res = get_line(fp, line, sizeof(line));
		}
	}
}
Esempio n. 2
0
GameBoard &GameBoard::shift(Direction dir, score_t *score)
{
    std::array<std::array<cell_value_t*, board_size>, board_size> views{0};
    switch (dir) {
    case DIR_UP:
    {
        for (size_t x = 0; x < board_size; x++) {
            for (size_t y = 0; y < board_size; y++) {
                views[x][y] = &rows[y][x];
            }
        }
        break;
    };
    case DIR_DOWN:
    {
        for (size_t x = 0; x < board_size; x++) {
            for (size_t y = 0; y < board_size; y++) {
                views[x][(board_size-1)-y] = &rows[y][x];
            }
        }
        break;
    };
    case DIR_LEFT:
    {
        for (size_t y = 0; y < board_size; y++) {
            for (size_t x = 0; x < board_size; x++) {
                views[y][x] = &rows[y][x];
            }
        }
        break;
    };
    case DIR_RIGHT:
    {
        for (size_t y = 0; y < board_size; y++) {
            for (size_t x = 0; x < board_size; x++) {
                views[y][(board_size-1)-x] = &rows[y][x];
            }
        }
        break;
    };
    };

    score_t total_score = 0;
    for (size_t i = 0; i < board_size; i++) {
        total_score += shift_line(
            views[i]);
    }
    if (score) {
        *score = total_score;
    }

    return *this;
};
Esempio n. 3
0
void drop_until(int count) {
    int qsize = 0;
    line_t *line = buf.top;
    while (line) {
        line = line->next;
        qsize++;
    }

    while (qsize > count) {
        shift_line();
        qsize--;
    }
}
Esempio n. 4
0
int main() {
    int c, pos;

    pos = 0;
    while ((c = getchar()) != EOF) {
        line[pos] = c; // store character

        if (c == '\t')
            pos = extend_tab(pos);
        else if (c == '\n') {
            print_line(pos);
            pos = 0;
        }
        else if (++pos == MAX_LINE) {
            pos = last_space();
            print_line(pos);
            pos = shift_line(pos);
        }
    }
}