Denys Vlasenko <dvlasenk(a)redhat.com> writes:
On Wed, 2011-07-27 at 16:17 +0200, Nikola Pajkovsky wrote:
> abrt-cli can report problems by specifying number of crash instead of
> long path name.
>
> Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
> ---
> src/cli/Makefile.am | 3 +-
> src/cli/abrt-cli-core.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++
> src/cli/abrt-cli-core.h | 32 ++++++++++++++++
I would rather collapse abrt-cli into fewer .c files than multiply
them even more. A personal preference of mine...
I'd rather left it as it is, because there will be a lot of other
functions, which will be shared across list.c/report.c/rm.c.
> if (optind < argc)
> {
> while (optind < argc)
> {
> - int status = report_problem_in_dir(argv[optind++],
> + const char *dir_name = argv[optind++];
> +
> + vector_of_problem_data_t *ci = NULL;
> + if (*dir_name == '@')
> + {
> + dir_name++;
> + char *end;
> + errno = 0;
> + unsigned long at = strtoul(dir_name, &end, 10);
> + if (errno || end == dir_name || *end != '\0')
> + error_msg_and_die("error: not a number '%s'",
dir_name);
"unsinged at = xatoi_positive(str);" will do it.
forgot, that we have that function
> +
> + ci = fetch_crash_infos(D_list);
> + if (at >= ci->len)
> + error_msg_and_die("error: number is out of range
'%s'", dir_name);
> +
> + g_ptr_array_sort_with_data(ci, &cmp_problem_data, (char *)
FILENAME_TIME);
> + problem_data_t *pd = get_problem_data(ci, at);
> +
> + dir_name = get_problem_item_content_or_NULL(pd, CD_DUMPDIR);
> + }
> +
> + int status = report_problem_in_dir(dir_name,
> LIBREPORT_ANALYZE
> | LIBREPORT_WAIT
> | LIBREPORT_RUN_CLI);
> + free_vector_of_problem_data(ci);
> if (status)
> exit(status);
> }
The if and loop looks wrong:
Why do you think that it's wrong? That would mean, that man page of
getopt_long is wrong also :)
if (optind < argc)
{
while (optind < argc)
{
const char *dump_dir = argv[optind++];
...
if (optind - argc)
printf("\n");
}
exit(0);
}
show_usage_and_die(program_usage_string, program_options);
return 0;
I'd rewrite it like this:
if (!argv[optind])
show_usage_and_die(program_usage_string, program_options);
while (1)
{
const char *dump_dir = argv[optind++];
...
if (!argv[optind])
break;
printf("\n");
}
return 0;
--
Save the whales. Feed the hungry. Free the mallocs