For getopt() arg processing:

- Use exit(0) for -h option as per convention;

For g_option...() arg processing (when USE_GOPTION is set):
 - Fix bug: 'capinfos x' doesn't print any info about x;
   (bug introduced in SVN #48481);
 - Use stderr for error messages related to cmd-line arg parsing;


svn path=/trunk/; revision=54555
This commit is contained in:
Bill Meier 2014-01-02 15:41:45 +00:00
parent be849dcaad
commit 8ef3e2fad3
1 changed files with 98 additions and 93 deletions

View File

@ -474,7 +474,7 @@ print_stats(const gchar *filename, capture_info *cf_info)
}
if (cap_snaplen && cf_info->snap_set)
printf ("Packet size limit: file hdr: %u bytes\n", cf_info->snaplen);
else if(cap_snaplen && !cf_info->snap_set)
else if (cap_snaplen && !cf_info->snap_set)
printf ("Packet size limit: file hdr: (not set)\n");
if (cf_info->snaplen_max_inferred > 0) {
if (cf_info->snaplen_min_inferred == cf_info->snaplen_max_inferred)
@ -663,7 +663,7 @@ print_stats_table(const gchar *filename, capture_info *cf_info)
if (cap_snaplen) {
putsep();
putquote();
if(cf_info->snap_set)
if (cf_info->snap_set)
printf("%u", cf_info->snaplen);
else
printf("(not set)");
@ -843,7 +843,7 @@ process_cap_file(wtap *wth, const char *filename)
if (phdr->presence_flags & WTAP_HAS_TS) {
prev_time = cur_time;
cur_time = nstime_to_sec(&phdr->ts);
if(packet==0) {
if (packet == 0) {
start_time = cur_time;
stop_time = cur_time;
prev_time = cur_time;
@ -935,7 +935,7 @@ process_cap_file(wtap *wth, const char *filename)
/* Packet size limit (snaplen) */
cf_info.snaplen = wtap_snapshot_length(wth);
if(cf_info.snaplen > 0)
if (cf_info.snaplen > 0)
cf_info.snap_set = TRUE;
else
cf_info.snap_set = FALSE;
@ -981,13 +981,13 @@ process_cap_file(wtap *wth, const char *filename)
we replace linefeeds with spaces */
p = cf_info.comment;
while (*p != '\0') {
if (*p=='\n')
*p=' ';
if (*p == '\n')
*p = ' ';
p++;
}
}
if(long_report) {
if (long_report) {
print_stats(filename, &cf_info);
} else {
print_stats_table(filename, &cf_info);
@ -1143,7 +1143,7 @@ main(int argc, char *argv[])
/* Register all the plugin types we have. */
wtap_register_plugin_types(); /* Types known to libwiretap */
init_report_err(failure_message,NULL,NULL,NULL);
init_report_err(failure_message, NULL, NULL, NULL);
/* Scan for plugins. This does *not* call their registration routines;
that's done later. */
@ -1192,18 +1192,23 @@ main(int argc, char *argv[])
argv[0] = (char *)"capinfos";
/* if we have at least one cmdline option, we disable printing all infos */
if (argc>=2 && report_all_infos)
if (argc > 2 && report_all_infos)
disable_all_infos();
if( !g_option_context_parse(ctx, &argc, &argv, &parse_err) ) {
if(parse_err) g_print ("option parsing failed: %s\n", parse_err->message);
g_print("%s", g_option_context_get_help (ctx, TRUE, NULL));
if ( !g_option_context_parse(ctx, &argc, &argv, &parse_err) ) {
if (parse_err)
g_printerr ("option parsing failed: %s\n", parse_err->message);
g_printerr("%s", g_option_context_get_help (ctx, TRUE, NULL));
exit(1);
}
if( cap_help || (argc < 2) ) {
if ( cap_help ) {
g_print("%s", g_option_context_get_help (ctx, FALSE, NULL));
exit(0);
}
if ( argc < 2 ) {
g_printerr("%s", g_option_context_get_help (ctx, FALSE, NULL));
exit(1);
}
g_option_context_free(ctx);
#endif /* USE_GOPTION */
@ -1351,7 +1356,7 @@ main(int argc, char *argv[])
case 'h':
usage(FALSE);
exit(1);
exit(0);
break;
case '?': /* Bad flag - print usage message */
@ -1369,7 +1374,7 @@ main(int argc, char *argv[])
exit(1);
}
if(!long_report && table_report_header) {
if (!long_report && table_report_header) {
print_stats_table_header();
}
@ -1425,11 +1430,11 @@ main(int argc, char *argv[])
break;
}
overall_error_status = 1; /* remember that an error has occurred */
if(!continue_after_wtap_open_offline_failure)
if (!continue_after_wtap_open_offline_failure)
exit(1); /* error status */
}
if(wth) {
if (wth) {
if ((opt > optind) && (long_report))
printf("\n");
status = process_cap_file(wth, argv[opt]);
@ -1448,10 +1453,10 @@ main(int argc, char *argv[])
*
* Local variables:
* c-basic-offset: 2
* tab-width: 2
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=2 tabstop=2 expandtab:
* :indentSize=2:tabSize=2:noTabs=true:
* vi: set shiftwidth=2 tabstop=8 expandtab:
* :indentSize=2:tabSize=8:noTabs=true:
*/