Skip to content

Commit

Permalink
Annotate stubs as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
terryburton committed Oct 13, 2024
1 parent 52b9dbd commit ba3617f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 53 deletions.
15 changes: 15 additions & 0 deletions src/gs1syntaxdictionary-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
#include <string.h>


#if defined(__clang__)
# define DIAG_PUSH _Pragma("clang diagnostic push")
# define DIAG_POP _Pragma("clang diagnostic pop")
# define DIAG_DISABLE_DEPRECATED_DECLARATIONS _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
#elif defined(__GNUC__)
# define DIAG_PUSH _Pragma("GCC diagnostic push")
# define DIAG_POP _Pragma("GCC diagnostic pop")
# define DIAG_DISABLE_DEPRECATED_DECLARATIONS _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#elif defined(_MSC_VER)
# define DIAG_PUSH __pragma(warning(push))
# define DIAG_POP __pragma(warning(pop))
# define DIAG_DISABLE_DEPRECATED_DECLARATIONS __pragma(warning(disable: 4996))
#endif


/**
* @brief Return from a linter indicating that no problem was detected with the
* given data.
Expand Down
108 changes: 66 additions & 42 deletions src/gs1syntaxdictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,58 +19,82 @@
#include <string.h>

#include "gs1syntaxdictionary.h"
#include "gs1syntaxdictionary-utils.h"


struct name_function_s {
char *name;
gs1_linter_t fn;
};


#define ENT(x) { .name = #x, .fn = gs1_lint_##x }
#define DEP(x) \
DIAG_PUSH \
DIAG_DISABLE_DEPRECATED_DECLARATIONS \
ENT(x) \
DIAG_POP

/* GCC has flaky support for pragmas within expressions */
#if defined(__GNUC__) && !defined(__clang__)
#undef DEP
#define DEP(x) ENT(x)
DIAG_PUSH
DIAG_DISABLE_DEPRECATED_DECLARATIONS
#endif

const struct name_function_s name_function_map[] = {
{ .name = "couponcode", .fn = gs1_lint_couponcode },
{ .name = "couponposoffer", .fn = gs1_lint_couponposoffer },
{ .name = "cset39", .fn = gs1_lint_cset39 },
{ .name = "cset64", .fn = gs1_lint_cset64 },
{ .name = "cset82", .fn = gs1_lint_cset82 },
{ .name = "csetnumeric", .fn = gs1_lint_csetnumeric },
{ .name = "csum", .fn = gs1_lint_csum },
{ .name = "csumalpha", .fn = gs1_lint_csumalpha },
{ .name = "hasnondigit", .fn = gs1_lint_hasnondigit },
{ .name = "hh", .fn = gs1_lint_hh },
{ .name = "hhmi", .fn = gs1_lint_hhmi },
{ .name = "hhmm", .fn = gs1_lint_hhmm }, // Stub
{ .name = "hyphen", .fn = gs1_lint_hyphen },
{ .name = "iban", .fn = gs1_lint_iban },
{ .name = "importeridx", .fn = gs1_lint_importeridx },
{ .name = "iso3166", .fn = gs1_lint_iso3166 },
{ .name = "iso3166999", .fn = gs1_lint_iso3166999 },
{ .name = "iso3166alpha2", .fn = gs1_lint_iso3166alpha2 },
{ .name = "iso3166list", .fn = gs1_lint_iso3166list }, // Stub
{ .name = "iso4217", .fn = gs1_lint_iso4217 },
{ .name = "iso5218", .fn = gs1_lint_iso5218 },
{ .name = "key", .fn = gs1_lint_key },
{ .name = "latitude", .fn = gs1_lint_latitude },
{ .name = "longitude", .fn = gs1_lint_longitude },
{ .name = "mediatype", .fn = gs1_lint_mediatype },
{ .name = "mi", .fn = gs1_lint_mi },
{ .name = "mmoptss", .fn = gs1_lint_mmoptss }, // Stub
{ .name = "nonzero", .fn = gs1_lint_nonzero },
{ .name = "nozeroprefix", .fn = gs1_lint_nozeroprefix },
{ .name = "packagetype", .fn = gs1_lint_packagetype },
{ .name = "pcenc", .fn = gs1_lint_pcenc },
{ .name = "pieceoftotal", .fn = gs1_lint_pieceoftotal },
{ .name = "posinseqslash", .fn = gs1_lint_posinseqslash },
{ .name = "ss", .fn = gs1_lint_ss },
{ .name = "winding", .fn = gs1_lint_winding },
{ .name = "yesno", .fn = gs1_lint_yesno },
{ .name = "yymmd0", .fn = gs1_lint_yymmd0 },
{ .name = "yymmdd", .fn = gs1_lint_yymmdd },
{ .name = "yymmddhh", .fn = gs1_lint_yymmddhh }, // Stub
{ .name = "yyyymmd0", .fn = gs1_lint_yyyymmd0 },
{ .name = "yyyymmdd", .fn = gs1_lint_yyyymmdd },
{ .name = "zero", .fn = gs1_lint_zero },
ENT(couponcode),
ENT(couponposoffer),
ENT(cset39),
ENT(cset64),
ENT(cset82),
ENT(csetnumeric),
ENT(csum),
ENT(csumalpha),
ENT(hasnondigit),
ENT(hh),
ENT(hhmi),
DEP(hhmm),
ENT(hyphen),
ENT(iban),
ENT(importeridx),
ENT(iso3166),
ENT(iso3166999),
ENT(iso3166alpha2),
DEP(iso3166list),
ENT(iso4217),
ENT(iso5218),
ENT(key),
ENT(latitude),
ENT(longitude),
ENT(mediatype),
ENT(mi),
DEP(mmoptss),
ENT(nonzero),
ENT(nozeroprefix),
ENT(packagetype),
ENT(pcenc),
ENT(pieceoftotal),
ENT(posinseqslash),
ENT(ss),
ENT(winding),
ENT(yesno),
ENT(yymmd0),
ENT(yymmdd),
DEP(yymmddhh),
ENT(yyyymmd0),
ENT(yyyymmdd),
ENT(zero),
};

/* Flaky GCC */
#if defined(__GNUC__) && !defined(__clang__)
DIAG_POP
#endif

#undef ENT
#undef DEP


/*
Expand Down
9 changes: 5 additions & 4 deletions src/gs1syntaxdictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,19 @@ GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_csumalpha(const char *data, si
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_hasnondigit(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_hh(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_hhmi(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_hhmm(const char *data, size_t *err_pos, size_t *err_len); // Stub
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_hyphen(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iban(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_importeridx(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso3166(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso3166999(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso3166alpha2(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso3166list(const char *data, size_t *err_pos, size_t *err_len); // Stub
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso4217(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_iso5218(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_key(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_latitude(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_longitude(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_mediatype(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_mi(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_mmoptss(const char *data, size_t *err_pos, size_t *err_len); // Stub
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_nonzero(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_nozeroprefix(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_packagetype(const char *data, size_t *err_pos, size_t *err_len);
Expand All @@ -261,11 +258,15 @@ GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_winding(const char *data, size
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_yesno(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_yymmd0(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_yymmdd(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_yymmddhh(const char *data, size_t *err_pos, size_t *err_len); // Stub
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_yyyymmd0(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_yyyymmdd(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_zero(const char *data, size_t *err_pos, size_t *err_len);

GS1_SYNTAX_DICTIONARY_API DEPRECATED gs1_lint_err_t gs1_lint_hhmm(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API DEPRECATED gs1_lint_err_t gs1_lint_iso3166list(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API DEPRECATED gs1_lint_err_t gs1_lint_mmoptss(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API DEPRECATED gs1_lint_err_t gs1_lint_yymmddhh(const char *data, size_t *err_pos, size_t *err_len);

GS1_SYNTAX_DICTIONARY_API gs1_linter_t gs1_linter_from_name(const char *name);

#ifdef __cplusplus
Expand Down
7 changes: 0 additions & 7 deletions src/lint__stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
*
*/

/**
* @file lint__stubs.c
*
* @brief Unused linter stub functions.
*
*/

#include <stddef.h>

#include "gs1syntaxdictionary.h"
Expand Down

0 comments on commit ba3617f

Please sign in to comment.