Follow convention for -h option:

Output to stdout & then exit(0).
Add editor modelines.

svn path=/trunk/; revision=54513
This commit is contained in:
Bill Meier 2013-12-31 16:17:09 +00:00
parent 1b180b3f47
commit 6b4944eced
1 changed files with 40 additions and 17 deletions

View File

@ -487,7 +487,7 @@ pkt_example examples[] = {
static int parse_type(char *string); static int parse_type(char *string);
static void usage(void); static void usage(gboolean is_error);
static void seed(void); static void seed(void);
static pkt_example* find_example(int type); static pkt_example* find_example(int type);
@ -535,8 +535,10 @@ main(int argc, char **argv)
break; break;
case 'h': case 'h':
usage(FALSE);
break;
default: default:
usage(); usage(TRUE);
break; break;
} }
} }
@ -546,7 +548,7 @@ main(int argc, char **argv)
produce_filename = argv[optind]; produce_filename = argv[optind];
} }
else { else {
usage(); usage(TRUE);
} }
example = find_example(produce_type); example = find_example(produce_type);
@ -627,24 +629,32 @@ main(int argc, char **argv)
} }
/* Print usage statement and exit program */ /* Print usage statement and exit program */
static static void
void usage(void) usage(gboolean is_error)
{ {
int num_entries = array_length(examples); FILE *output;
int i; int num_entries = array_length(examples);
int i;
printf("Usage: randpkt [-b maxbytes] [-c count] [-t type] filename\n"); if (!is_error) {
printf("Default max bytes (per packet) is 5000\n"); output = stdout;
printf("Default count is 1000.\n"); }
printf("Types:\n"); else {
output = stderr;
for (i = 0; i < num_entries; i++) {
printf("\t%-16s%s\n", examples[i].abbrev, examples[i].longname);
} }
printf("\n"); fprintf(output, "Usage: randpkt [-b maxbytes] [-c count] [-t type] filename\n");
fprintf(output, "Default max bytes (per packet) is 5000\n");
fprintf(output, "Default count is 1000.\n");
fprintf(output, "Types:\n");
exit(0); for (i = 0; i < num_entries; i++) {
fprintf(output, "\t%-16s%s\n", examples[i].abbrev, examples[i].longname);
}
fprintf(output, "\n");
exit(is_error ? 1 : 0);
} }
/* Parse command-line option "type" and return enum type */ /* Parse command-line option "type" and return enum type */
@ -689,7 +699,7 @@ void
seed(void) seed(void)
{ {
unsigned int randomness; unsigned int randomness;
time_t now; time_t now;
#ifndef _WIN32 #ifndef _WIN32
int fd; int fd;
ssize_t ret; ssize_t ret;
@ -737,3 +747,16 @@ fallback:
srand(randomness); srand(randomness);
} }
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/