Example #1
0
int			read_tube(t_app *app, char *line)
{
	char			**tube;
	unsigned int	count;
	int				rt;

	if (ft_strcount(line, ' ') != 1)
	{
		app->read_mode = 5;
		return (-1);
	}
	count = ft_strcount(line, '-');
	if (count != 2 || line[0] == '#' || line[0] == 'L')
	{
		if (line[0] != '#' && line[0] != 'L')
			app->read_mode = 5;
		return (-1);
	}
	tube = ft_strsplit(line, '-');
	clean_spaces(tube[0]);
	clean_spaces(tube[1]);
	rt = (read_tube2(app, what_nbr(app, tube[0]), what_nbr(app, tube[1])));
	while (count--)
		free(tube[count]);
	free(tube);
	return (rt);
}
static int parse_user_color_line(char *filename, char *line, int ln,
					struct user_color_entry *e)
{
	int rc;
	unsigned int r, g, b;
	char name[100], ui_component[100], colorname[100];

	if (line[0] == '#')
		return 1; /* comment */

	clean_spaces(line);
	remove_trailing_whitespace(line);

	if (strcmp(line, "") == 0)
		return 1; /* comment (blank line) */

	memset(name, 0, sizeof(name));
	rc = sscanf(line, "color %[^	 ] #%02x%02x%02x",
			name, &r, &g, &b);
	if (rc == 4) {
		name[19] = '\0';
		memcpy(e->name, name, 20);
		e->index = sng_add_user_color(r, g, b);
		if (e->index < 0) {
			fprintf(stderr, "%s:%d Failed to add user color '%s'\n",
				filename, ln, name);
			return -1;
		}
		return 0;
	} else {
		rc = sscanf(line, "%[^	 ] #%02x%02x%02x",
				ui_component, &r, &g, &b);
		if (rc == 4) {
			e->index = sng_add_user_color(r, g, b);
			if (e->index < 0) {
				fprintf(stderr, "%s:%d Failed to modify ui component color '%s'\n",
					filename, ln, line);
				return -1;
			}
			modify_ui_color(ui_component, e->index);
			return 0;
		} else {
			rc = sscanf(line, "%[^	 ] %[^	 ]",
				ui_component, colorname);
			if (rc == 2) {
				e->index = lookup_user_color(colorname);
				if (e->index < 0) {
					fprintf(stderr,
						"%s:%d Failed to modify ui component color '%s'\n",
						filename, ln, line);
					return -1;
				}
				modify_ui_color(ui_component, e->index);
				return 0;
			}
		}
	}
	fprintf(stderr, "%s:%d: Syntax error: '%s'\n", filename, ln, line);
	return -1;
}