From: notaz Date: Wed, 30 Sep 2015 23:54:11 +0000 (+0300) Subject: get rid of some duplication X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=ia32rtools.git;a=commitdiff_plain;h=3084511901606db82741bffafc8582ab9b7591cc get rid of some duplication --- diff --git a/tools/asmproc.c b/tools/asmproc.c index 6e6b62b..956ffa2 100644 --- a/tools/asmproc.c +++ b/tools/asmproc.c @@ -12,6 +12,7 @@ #include "my_assert.h" #include "my_str.h" +#include "common.h" struct sl_item { char *name; @@ -109,7 +110,6 @@ const char *sym_use(const struct sl_item *sym, int is_rm) return buf; } -#define IS(w, y) !strcasecmp(w, y) #define IS_OR2(w, x, y) (IS(w, x) || IS(w, y)) #define IS_OR3(w, x, y, z) (IS(w, x) || IS(w, y) || IS(w, z)) diff --git a/tools/common.h b/tools/common.h index 4ca8e12..e000489 100644 --- a/tools/common.h +++ b/tools/common.h @@ -1,5 +1,10 @@ + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +#define IS(w, y) !strcmp(w, y) +#define IS_START(w, y) !strncmp(w, y, strlen(y)) + // read a line, truncating it if it doesn't fit -static char *my_fgets(char *s, size_t size, FILE *stream) +static inline char *my_fgets(char *s, size_t size, FILE *stream) { char *ret, *ret2; char buf[64]; diff --git a/tools/cvt_data.c b/tools/cvt_data.c index c71c2f8..60e6187 100644 --- a/tools/cvt_data.c +++ b/tools/cvt_data.c @@ -17,10 +17,6 @@ #include "my_str.h" #include "common.h" -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) -#define IS(w, y) !strcmp(w, y) -#define IS_START(w, y) !strncmp(w, y, strlen(y)) - #include "protoparse.h" static const char *asmfn; diff --git a/tools/mkbridge.c b/tools/mkbridge.c index 01a8f56..dda6269 100644 --- a/tools/mkbridge.c +++ b/tools/mkbridge.c @@ -12,9 +12,7 @@ #include "my_assert.h" #include "my_str.h" - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) -#define IS(w, y) !strcmp(w, y) +#include "common.h" #include "protoparse.h" diff --git a/tools/mkdef_ord.c b/tools/mkdef_ord.c index 3904f9a..3873c3a 100644 --- a/tools/mkdef_ord.c +++ b/tools/mkdef_ord.c @@ -12,10 +12,7 @@ #include "my_assert.h" #include "my_str.h" - -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) -#define IS(w, y) !strcmp(w, y) -#define IS_START(w, y) !strncmp(w, y, strlen(y)) +#include "common.h" #include "protoparse.h" diff --git a/tools/translate.c b/tools/translate.c index fe64087..eec360f 100644 --- a/tools/translate.c +++ b/tools/translate.c @@ -25,10 +25,6 @@ #include "my_str.h" #include "common.h" -#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) -#define IS(w, y) !strcmp(w, y) -#define IS_START(w, y) !strncmp(w, y, strlen(y)) - #include "protoparse.h" static const char *asmfn;