Commit c1192965 authored by Dario Lombardo's avatar Dario Lombardo Committed by Michael Mann

randpkt: restyle the list generation to get rid of the const compiler warning.

Change-Id: Id7c62ef18f919ba8a476898bc88c02fd3b6bf5a1
Reviewed-on: https://code.wireshark.org/review/14730
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: default avatarPetri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: default avatarMichael Mann <mmann78@netscape.net>
parent f4bdaf9d
......@@ -65,10 +65,9 @@ static struct option longopts[] = {
static void help(const char* binname)
{
unsigned i;
const char** abbrev_list;
const char** longname_list;
unsigned list_num;
unsigned i = 0;
char** abbrev_list;
char** longname_list;
printf("Help\n");
printf(" Usage:\n");
......@@ -94,22 +93,23 @@ static void help(const char* binname)
printf(" --all-random: a random type is chosen for each packet\n");
printf(" --type <type>: the packet type\n");
printf("\n\nPacket types:\n");
randpkt_example_list(&abbrev_list, &longname_list, &list_num);
for (i = 0; i < list_num; i++) {
randpkt_example_list(&abbrev_list, &longname_list);
while (abbrev_list[i] && longname_list[i]) {
printf("\t%-16s%s\n", abbrev_list[i], longname_list[i]);
i++;
}
g_free((char**)abbrev_list);
g_free((char**)longname_list);
printf("\n");
g_strfreev(abbrev_list);
g_strfreev(longname_list);
}
static int list_config(char *interface)
{
unsigned inc = 0;
unsigned i;
const char** abbrev_list;
const char** longname_list;
unsigned list_num;
unsigned i = 0;
char** abbrev_list;
char** longname_list;
if (!interface) {
errmsg_print("ERROR: No interface specified.");
......@@ -138,12 +138,13 @@ static int list_config(char *interface)
printf("arg {number=%u}{call=--type}{display=Type of packet}"
"{type=selector}{tooltip=Type of packet to generate}\n",
inc);
randpkt_example_list(&abbrev_list, &longname_list, &list_num);
for (i = 0; i < list_num; i++) {
randpkt_example_list(&abbrev_list, &longname_list);
while (abbrev_list[i] && longname_list[i]) {
printf("value {arg=%u}{value=%s}{display=%s}\n", inc, abbrev_list[i], longname_list[i]);
i++;
}
g_free((char**)abbrev_list);
g_free((char**)longname_list);
g_strfreev(abbrev_list);
g_strfreev(longname_list);
inc++;
return EXIT_SUCCESS;
......
......@@ -22,6 +22,7 @@
*/
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <wsutil/ws_diag_control.h>
......@@ -63,10 +64,9 @@ static void
usage(gboolean is_error)
{
FILE *output;
const char** abbrev_list;
const char** longname_list;
unsigned list_num;
unsigned i;
char** abbrev_list;
char** longname_list;
unsigned i = 0;
if (!is_error) {
output = stdout;
......@@ -83,12 +83,14 @@ usage(gboolean is_error)
fprintf(output, "Types:\n");
/* Get the examples list */
randpkt_example_list(&abbrev_list, &longname_list, &list_num);
for (i = 0; i < list_num; i++) {
randpkt_example_list(&abbrev_list, &longname_list);
while (abbrev_list[i] && longname_list[i]) {
fprintf(output, "\t%-16s%s\n", abbrev_list[i], longname_list[i]);
i++;
}
g_free((char**)abbrev_list);
g_free((char**)longname_list);
g_strfreev(abbrev_list);
g_strfreev(longname_list);
fprintf(output, "\nIf type is not specified, a random packet will be chosen\n\n");
......
......@@ -779,15 +779,16 @@ int randpkt_parse_type(char *string)
return -1;
}
void randpkt_example_list(const char*** abbrev_list, const char*** longname_list, unsigned* list_num)
void randpkt_example_list(char*** abbrev_list, char*** longname_list)
{
unsigned i;
*list_num = randpkt_example_count();
*abbrev_list = g_new0(const char*, *list_num);
*longname_list = g_new0(const char*, *list_num);
for (i = 0; i < *list_num; i++) {
(*abbrev_list)[i] = examples[i].abbrev;
(*longname_list)[i] = examples[i].longname;
unsigned list_num;
list_num = randpkt_example_count();
*abbrev_list = g_new0(char*, list_num + 1);
*longname_list = g_new0(char*, list_num + 1);
for (i = 0; i < list_num; i++) {
(*abbrev_list)[i] = g_strdup(examples[i].abbrev);
(*longname_list)[i] = g_strdup(examples[i].longname);
}
}
......
......@@ -48,7 +48,7 @@ typedef struct {
guint randpkt_example_count(void);
/* Return the list of the active examples */
void randpkt_example_list(const char*** abbrev_list, const char*** longname_list, unsigned* list_num);
void randpkt_example_list(char*** abbrev_list, char*** longname_list);
/* Seed the random-number generator */
void randpkt_seed(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment