print the list of available types also if the given type is invalid

svn path=/trunk/; revision=16993
This commit is contained in:
Ulf Lamping 2006-01-10 22:00:37 +00:00
parent c38f10aec7
commit ae477dc44f
1 changed files with 24 additions and 18 deletions

View File

@ -245,33 +245,28 @@ static void usage(void)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
static void list_capture_types(void) {
int i;
static void bad_option_help(int bad_opt) { fprintf(stderr, "editcap: The available capture file types for \"F\":\n");
int i;
const char *string;
switch(bad_opt) {
case'F':
fprintf(stderr, "The available capture file types for \"F\":\n");
for (i = 0; i < WTAP_NUM_FILE_TYPES; i++) { for (i = 0; i < WTAP_NUM_FILE_TYPES; i++) {
if (wtap_dump_can_open(i)) if (wtap_dump_can_open(i))
fprintf(stderr, " %s - %s\n", fprintf(stderr, " %s - %s\n",
wtap_file_type_short_string(i), wtap_file_type_string(i)); wtap_file_type_short_string(i), wtap_file_type_string(i));
} }
break; }
case'T':
fprintf(stderr, "The available encapsulation types for \"T\":\n"); static void list_encap_types(void) {
int i;
const char *string;
fprintf(stderr, "editcap: The available encapsulation types for \"T\":\n");
for (i = 0; i < WTAP_NUM_ENCAP_TYPES; i++) { for (i = 0; i < WTAP_NUM_ENCAP_TYPES; i++) {
string = wtap_encap_short_string(i); string = wtap_encap_short_string(i);
if (string != NULL) if (string != NULL)
fprintf(stderr, " %s - %s\n", fprintf(stderr, " %s - %s\n",
string, wtap_encap_string(i)); string, wtap_encap_string(i));
} }
break;
default:
usage();
}
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -316,8 +311,9 @@ int main(int argc, char *argv[])
case 'F': case 'F':
out_file_type = wtap_short_string_to_file_type(optarg); out_file_type = wtap_short_string_to_file_type(optarg);
if (out_file_type < 0) { if (out_file_type < 0) {
fprintf(stderr, "editcap: \"%s\" isn't a valid capture file type\n", fprintf(stderr, "editcap: \"%s\" isn't a valid capture file type\n\n",
optarg); optarg);
list_capture_types();
exit(1); exit(1);
} }
break; break;
@ -346,7 +342,16 @@ int main(int argc, char *argv[])
break; break;
case '?': /* Bad options if GNU getopt */ case '?': /* Bad options if GNU getopt */
bad_option_help(optopt); switch(optopt) {
case'F':
list_capture_types();
break;
case'T':
list_encap_types();
break;
default:
usage();
}
exit(1); exit(1);
break; break;
@ -375,8 +380,9 @@ int main(int argc, char *argv[])
case 'T': case 'T':
out_frame_type = wtap_short_string_to_encap(optarg); out_frame_type = wtap_short_string_to_encap(optarg);
if (out_frame_type < 0) { if (out_frame_type < 0) {
fprintf(stderr, "editcap: \"%s\" isn't a valid encapsulation type\n", fprintf(stderr, "editcap: \"%s\" isn't a valid encapsulation type\n\n",
optarg); optarg);
list_encap_types();
exit(1); exit(1);
} }
break; break;