Example #1
0
int image_load(const char *path,
	       struct format *output_format,
	       struct fb_image *image)
{
	int fd = 0;
	int err = 0;
	char *buf = NULL;
	size_t len = 0;
	struct stat stat;
	parser parse_func;

	if (NULL == path)
		return VMM_EFAIL;

	if (0 > (fd = vfs_open(path, O_RDONLY, 0)))
		return fd;

	if (VMM_OK != (err = vfs_fstat(fd, &stat))) {
		goto out;
	}

	if (NULL == (buf = vmm_malloc(stat.st_size))) {
		err = VMM_ENOMEM;
		goto out;
	}

	len = vfs_read(fd, buf, stat.st_size);

	if (NULL == (parse_func = parser_get(buf, len))) {
		vmm_printf("Unsupported format\n");
		err = VMM_EFAIL;
		goto out;
	}

	err = parse_func(buf, len, image, output_format);

out:
	if ((VMM_OK != err) && buf)
		vmm_free(buf);
	if (fd >= 0)
		vfs_close(fd);

	return err;
}
Example #2
0
t_state		*parse_tab(char *file)
{
	int		fd;
	t_state	*state;
	int		size;
	char	*str;

	size = 0;
	if ((fd = open(file, O_RDONLY)) == -1 ||
		!(state = (t_state *)malloc(sizeof(t_state))))
	{
		print_usage();
		exit(-1);
	}
	parse_func(fd, &str, size, state);
	state->id = 0;
	state->father = -1;
	init_link(state, NULL);
	return (state);
}
Example #3
0
int
parse_config_file(FILE *file)
{
	char buf[4096];
	int rc;

	line = 0;
	parse_func = pf_top_level;

	while (fgets(buf, sizeof(buf), file) != NULL) {
		int len = strlen(buf);
		while (len && (buf[len - 1] == '\n' || buf[len - 1] == '\r')) {
			len--;
		}
		buf[len] = '\0';
		line++;
		rc = parse_func(buf, parse_context);
		if (rc != 0) {
			return (rc);
		}
	}
	return (0);
}