Beispiel #1
0
char		*fmt_x(t_mods mods, char *out_str)
{
	char	*new_str;
	char	*pad;
	int		slen;

	slen = ft_strlen(out_str);
	if (mods.width != -1)
	{
		new_str = (char *)malloc(sizeof(char) * mods.width + 1);
		pad = (char *)malloc(sizeof(char) * (mods.width - slen));
		if (mods.precision != -1 && mods.precision > slen)
			new_str = do_precision(new_str, pad, out_str, mods);
		else if (mods.precision == -1)
			new_str = do_width(new_str, pad, out_str, mods);
	}
	else if (mods.precision > slen)
	{
		new_str = (char *)malloc(sizeof(char) * mods.precision);
		pad = (char *)malloc(sizeof(char) * (mods.precision - slen));
		new_str = do_precision(new_str, pad, out_str, mods);
	}
	else
		new_str = out_str;
	if (mods.flag == '#')
		new_str = do_flags(mods, new_str);
	return (new_str);
}
Beispiel #2
0
static void
parse_cmdline(int argc, char * const argv[])
{
	int ch;
	int index = 0;

	struct option options[] = {
		{"help", no_argument, NULL, 'h'},
		{"version", no_argument, NULL, 'V'},
		{"geometry", required_argument, NULL, 'g'},
		{"resolution", required_argument, NULL, 'r'},
		{"center", required_argument, NULL, 'c'},
		{"width", required_argument, NULL, 'w'},
		{"height", required_argument, NULL, 'H'},
		{"method", required_argument, NULL, 'm'},
		{"nthreads", required_argument, NULL, 'n'},
		{"output", required_argument, NULL, 'o'},
	};

	while ((ch = getopt_long(argc, argv, 
	                         "hc:H:m:n:o:r:w:g:V", options, &index)) != -1) {
		switch (ch) {
		case 'h':
			do_usage(argv[0], 0);
			break;
		case 'V':
			do_version(argv[0]);
			break;
		case 'g':
			do_geometry(argv[0], optarg);
			break;
		case 'r':
			do_resolution(argv[0], optarg);
			break;
		case 'c':
			do_center(argv[0], optarg);
			break;
		case 'w':
			do_width(argv[0], optarg);
			break;
		case 'H':
			do_height(argv[0], optarg);
			break;
		case 'm':
			do_method(argv[0], optarg);
			break;
		case 'n':
			do_nthreads(argv[0], optarg);
			break;
		case 'o':
			do_output(argv[0], optarg);
			break;
		default:
			do_usage(argv[0], 1);
		}
	}

	if (plot == NULL)
		do_method(argv[0], "generic");
	if (!output) {
		fprintf(stderr, "no output file.\n");
		exit(1);
	}
}