Make make-{taps,dissectors}.c shared code shared.

Change-Id: I1cacd88ee26d9b21b67d38daf3d8ec8dcaf2e69e
Reviewed-on: https://code.wireshark.org/review/27948
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot
Reviewed-by: João Valverde <j@v6e.pt>
This commit is contained in:
João Valverde 2018-06-01 18:34:40 +01:00 committed by João Valverde
parent f4e3d8cbf3
commit 51318eccfc
5 changed files with 146 additions and 102 deletions

View File

@ -9,13 +9,13 @@
add_subdirectory(lemon)
add_executable(make-dissectors make-dissectors.c)
add_executable(make-dissectors make-dissectors.c make-lib.c)
target_link_libraries(make-dissectors ${GLIB2_LIBRARIES})
if(WIN32)
add_dependencies(make-dissectors copy_cli_dlls)
endif()
add_executable(make-taps make-taps.c)
add_executable(make-taps make-taps.c make-lib.c)
target_link_libraries(make-taps ${GLIB2_LIBRARIES})
#

View File

@ -11,74 +11,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "make-lib.h"
#define ARRAY_RESERVED_SIZE 2048
#define STRING_RESERVED_SIZE (300 * 1024)
#ifdef _WIN32
#define SEP "\r\n"
#else
#define SEP "\n"
#endif
GRegex *protos_regex, *handoffs_regex;
static int
compare_symbols(gconstpointer a, gconstpointer b)
{
return g_strcmp0(*(const char **)a, *(const char **)b);
}
static void
scan_matches(GRegex *regex, const char *string, GPtrArray *dst)
{
GMatchInfo *match_info;
char *match;
g_regex_match(regex, string, G_REGEX_MATCH_NOTEMPTY, &match_info);
while (g_match_info_matches(match_info)) {
match = g_match_info_fetch(match_info, 1);
g_ptr_array_add(dst, match);
g_match_info_next(match_info, NULL);
}
g_match_info_free(match_info);
}
static void
scan_file(const char *file, GPtrArray *protos, GPtrArray *handoffs)
{
char *contents;
GError *err = NULL;
if (!g_file_get_contents(file, &contents, NULL, &err)) {
fprintf(stderr, "%s: %s\n", file, err->message);
exit(1);
}
scan_matches(protos_regex, contents, protos);
scan_matches(handoffs_regex, contents, handoffs);
g_free(contents);
}
static void
scan_list(const char *file, GPtrArray *protos, GPtrArray *handoffs)
{
char *contents, *arg;
GError *err = NULL;
if (!g_file_get_contents(file, &contents, NULL, &err)) {
fprintf(stderr, "%s: %s\n", file, err->message);
exit(1);
}
for (arg = strtok(contents, SEP); arg != NULL; arg = strtok(NULL, SEP)) {
scan_file(arg, protos, handoffs);
}
g_free(contents);
}
int main(int argc, char **argv)
{
GRegex *protos_regex, *handoffs_regex;
GPtrArray *protos = NULL, *handoffs = NULL;
struct symbol_item items[2];
GError *err = NULL;
guint i;
GString *s;
@ -106,13 +49,18 @@ int main(int argc, char **argv)
exit(1);
}
items[0].regex = protos_regex;
items[0].ptr_array = protos;
items[1].regex = handoffs_regex;
items[1].ptr_array = handoffs;
outfile = argv[1];
for (int arg = 2; arg < argc; arg++) {
if (argv[arg][0] == '@') {
scan_list(&argv[arg][1], protos, handoffs);
scan_list(&argv[arg][1], items, G_N_ELEMENTS(items));
}
else {
scan_file(argv[arg], protos, handoffs);
scan_file(argv[arg], items, G_N_ELEMENTS(items));
}
}

89
tools/make-lib.c Normal file
View File

@ -0,0 +1,89 @@
/* make-lib.c
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "make-lib.h"
#ifdef _WIN32
#define SEP "\r\n"
#else
#define SEP "\n"
#endif
int
compare_symbols(gconstpointer a, gconstpointer b)
{
return g_strcmp0(*(const char **)a, *(const char **)b);
}
static void
scan_matches(GRegex *regex, const char *string, GPtrArray *dst)
{
GMatchInfo *match_info;
char *match;
g_regex_match(regex, string, G_REGEX_MATCH_NOTEMPTY, &match_info);
while (g_match_info_matches(match_info)) {
match = g_match_info_fetch(match_info, 1);
g_ptr_array_add(dst, match);
g_match_info_next(match_info, NULL);
}
g_match_info_free(match_info);
}
void
scan_file(const char *file, struct symbol_item *items, size_t items_len)
{
char *contents;
GError *err = NULL;
size_t i;
if (!g_file_get_contents(file, &contents, NULL, &err)) {
fprintf(stderr, "%s: %s\n", file, err->message);
exit(1);
}
for (i = 0; i < items_len; i++) {
scan_matches(items[i].regex, contents, items[i].ptr_array);
}
g_free(contents);
}
void
scan_list(const char *file, struct symbol_item *items, size_t items_len)
{
char *contents, *arg;
GError *err = NULL;
if (!g_file_get_contents(file, &contents, NULL, &err)) {
fprintf(stderr, "%s: %s\n", file, err->message);
exit(1);
}
for (arg = strtok(contents, SEP); arg != NULL; arg = strtok(NULL, SEP)) {
scan_file(arg, items, items_len);
}
g_free(contents);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

38
tools/make-lib.h Normal file
View File

@ -0,0 +1,38 @@
/* make-lib.h
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <glib.h>
struct symbol_item {
GRegex *regex;
GPtrArray *ptr_array;
};
/* Compares symbols using strcmp() */
int compare_symbols(gconstpointer a, gconstpointer b);
/* Scan a C source file for symbols */
void scan_file(const char *file, struct symbol_item *items, size_t items_len);
/* Takes a text file containing a list of C source files on which to call scan_file() */
void scan_list(const char *file, struct symbol_item *items, size_t items_len);
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -11,51 +11,17 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "make-lib.h"
#define ARRAY_RESERVED_SIZE 128
#define STRING_RESERVED_SIZE (8 * 1024)
GRegex *taps_regex;
static int
compare_symbols(gconstpointer a, gconstpointer b)
{
return g_strcmp0(*(const char **)a, *(const char **)b);
}
static void
scan_matches(GRegex *regex, const char *string, GPtrArray *dst)
{
GMatchInfo *match_info;
char *match;
g_regex_match(regex, string, G_REGEX_MATCH_NOTEMPTY, &match_info);
while (g_match_info_matches(match_info)) {
match = g_match_info_fetch(match_info, 1);
g_ptr_array_add(dst, match);
g_match_info_next(match_info, NULL);
}
g_match_info_free(match_info);
}
static void
scan_file(const char *file, GPtrArray *taps)
{
char *contents;
GError *err = NULL;
if (!g_file_get_contents(file, &contents, NULL, &err)) {
fprintf(stderr, "%s: %s\n", file, err->message);
exit(1);
}
scan_matches(taps_regex, contents, taps);
g_free(contents);
}
int main(int argc, char **argv)
{
GRegex *taps_regex;
GPtrArray *taps = NULL;
struct symbol_item items[1];
GError *err = NULL;
guint i;
GString *s;
@ -76,9 +42,12 @@ int main(int argc, char **argv)
exit(1);
}
items[0].regex = taps_regex;
items[0].ptr_array = taps;
outfile = argv[1];
for (int arg = 2; arg < argc; arg++) {
scan_file(argv[arg], taps);
scan_file(argv[arg], items, G_N_ELEMENTS(items));
}
if (taps->len == 0) {