Exemple #1
0
static void ofc_file__debug_va(
    const ofc_file_t* file,
    const char* sol, const char* ptr,
    const char* type, const char* format, va_list args)
{
    unsigned row, col;
    bool positional = ofc_file_get_position(
                          file, ptr, &row, &col);

    fprintf(stderr, "%s:", type);

    if (file && file->path)
        fprintf(stderr, "%s:", file->path);

    if (positional)
        fprintf(stderr, "%u,%u:", (row + 1), col);

    fprintf(stderr, " ");
    vfprintf(stderr, format, args);
    fprintf(stderr, "\n");

    if (positional)
    {
        if (!sol)
            sol = ptr;

        const char* s = file->strz;
        const char* p;
        for (p = file->strz; p < sol; p++)
        {
            if (ofc_is_vspace(*p))
                s = &p[1];
        }

        unsigned len = ((uintptr_t)ptr - (uintptr_t)s);
        for (; !ofc_is_vspace(s[len]) && (s[len] != '\0'); len++);

        /* Print line(s) above if line is empty. */
        while (line_empty(s, len)
                && (s != file->strz))
        {
            const char* ns = file->strz;
            for (p = file->strz; p < s; p++)
            {
                if (ofc_is_vspace(*p))
                    ns = &p[1];
            }
            len += ((uintptr_t)s - (uintptr_t)ns);
            s = ns;
        }

        fprintf(stderr, "%.*s\n", len, s);

        unsigned i;
        for (i = 0; i < col; i++)
            fprintf(stderr, " ");
        fprintf(stderr, "^\n");
    }
}
Exemple #2
0
int		measure_render(t_render *r)
{
	int a;
	int b;

	a = 11;
	b = 11;
	while (--a && col_empty(r->screen, a, 11))
		;
	while (--b && line_empty(r->screen, b, 11))
		;
	r->s = a < b ? b : a;
	return (++r->s);
}
Exemple #3
0
int
load(FILE *f, struct puzzle *dst)
{
	char line[MAX_LINE_LEN];
	int state;
	struct shape raw, optimalized;
	int line_no;
	char *res;
	int board_loaded;

	state = 0;
	line_no = 0;
	dst->no_tiles = 0;
	board_loaded = 0;

	while (((res = fgets(line, MAX_LINE_LEN, f)) != NULL) || state != 0) {
		line_no++;

		if (res == NULL) {
			line[0] = '\0';
		} else {
			if (line[strlen(line) - 1] != '\n') {
				errx(1, "Error on line %u: Line too long or file does not end with newline", line_no);
			}
		}

		switch (state) {
		case 0:
			if (!line_empty(line)) {
				raw.height = 0;
				if (strlen(line) > MAX_SHAPE_WIDTH) {
					errx(1, "Error on line %u: Line too long", line_no);
				}

				strcpy(raw.shape[raw.height], line);
				raw.height++;
				state = 1;
			}
			break;
		case 1:
			if (line_empty(line)) {
				/*
				 * Shape loaded
				 */
				optimalize_shape(&raw, &optimalized);

				if (board_loaded) {
					if (dst->no_tiles >= MAX_SHAPES) {
						errx(1, "Error on line %u: Too much tiles", line_no);
					}
					memcpy(&dst->tiles[dst->no_tiles], &optimalized, sizeof(optimalized));
					dst->no_tiles++;
				} else {
					memcpy(&dst->board, &optimalized, sizeof(optimalized));
					dst->no_tiles = 0;
					board_loaded = 1;
				}
				state = 0;
			} else {
				if (strlen(line) > MAX_SHAPE_WIDTH) {
					errx(1, "Error on line %u: Line too long", line_no);
				}

				strcpy(raw.shape[raw.height], line);
				raw.height++;
			}
			break;
		}
	}

	if (!board_loaded || dst->no_tiles == 0) {
		errx(1, "Board not defined or no tiles is defined in file");
	}

	return (0);
}