Skip to content

Commit

Permalink
Sync with Syntax Dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
terryburton committed Oct 13, 2024
1 parent 62b9988 commit c6067f1
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 209 deletions.
5 changes: 1 addition & 4 deletions src/c-lib/gs1encoders-test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,19 @@
<ClCompile Include="syntax\lint_hasnondigit.c" />
<ClCompile Include="syntax\lint_hh.c" />
<ClCompile Include="syntax\lint_hhmi.c" />
<ClCompile Include="syntax\lint_hhmm.c" />
<ClCompile Include="syntax\lint_hyphen.c" />
<ClCompile Include="syntax\lint_iban.c" />
<ClCompile Include="syntax\lint_importeridx.c" />
<ClCompile Include="syntax\lint_iso3166.c" />
<ClCompile Include="syntax\lint_iso3166999.c" />
<ClCompile Include="syntax\lint_iso3166alpha2.c" />
<ClCompile Include="syntax\lint_iso3166list.c" />
<ClCompile Include="syntax\lint_iso4217.c" />
<ClCompile Include="syntax\lint_iso5218.c" />
<ClCompile Include="syntax\lint_key.c" />
<ClCompile Include="syntax\lint_latitude.c" />
<ClCompile Include="syntax\lint_longitude.c" />
<ClCompile Include="syntax\lint_mediatype.c" />
<ClCompile Include="syntax\lint_mi.c" />
<ClCompile Include="syntax\lint_mmoptss.c" />
<ClCompile Include="syntax\lint_nonzero.c" />
<ClCompile Include="syntax\lint_nozeroprefix.c" />
<ClCompile Include="syntax\lint_packagetype.c" />
Expand All @@ -211,10 +208,10 @@
<ClCompile Include="syntax\lint_yesno.c" />
<ClCompile Include="syntax\lint_yymmd0.c" />
<ClCompile Include="syntax\lint_yymmdd.c" />
<ClCompile Include="syntax\lint_yymmddhh.c" />
<ClCompile Include="syntax\lint_yyyymmdd.c" />
<ClCompile Include="syntax\lint_yyyymmd0.c" />
<ClCompile Include="syntax\lint_zero.c" />
<ClCompile Include="syntax\lint__stubs.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
15 changes: 3 additions & 12 deletions src/c-lib/gs1encoders-test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@
<ClCompile Include="syntax\lint_hhmi.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_hhmm.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_hyphen.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -128,9 +125,6 @@
<ClCompile Include="syntax\lint_iso3166alpha2.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_iso3166list.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_iso4217.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -152,9 +146,6 @@
<ClCompile Include="syntax\lint_mi.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_mmoptss.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_nonzero.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -188,9 +179,6 @@
<ClCompile Include="syntax\lint_yymmdd.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_yymmddhh.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_yyyymmd0.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -200,5 +188,8 @@
<ClCompile Include="syntax\lint_zero.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint__stubs.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
5 changes: 1 addition & 4 deletions src/c-lib/gs1encoders.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,22 +153,19 @@
<ClCompile Include="syntax\lint_hasnondigit.c" />
<ClCompile Include="syntax\lint_hh.c" />
<ClCompile Include="syntax\lint_hhmi.c" />
<ClCompile Include="syntax\lint_hhmm.c" />
<ClCompile Include="syntax\lint_hyphen.c" />
<ClCompile Include="syntax\lint_iban.c" />
<ClCompile Include="syntax\lint_importeridx.c" />
<ClCompile Include="syntax\lint_iso3166.c" />
<ClCompile Include="syntax\lint_iso3166999.c" />
<ClCompile Include="syntax\lint_iso3166alpha2.c" />
<ClCompile Include="syntax\lint_iso3166list.c" />
<ClCompile Include="syntax\lint_iso4217.c" />
<ClCompile Include="syntax\lint_iso5218.c" />
<ClCompile Include="syntax\lint_key.c" />
<ClCompile Include="syntax\lint_latitude.c" />
<ClCompile Include="syntax\lint_longitude.c" />
<ClCompile Include="syntax\lint_mediatype.c" />
<ClCompile Include="syntax\lint_mi.c" />
<ClCompile Include="syntax\lint_mmoptss.c" />
<ClCompile Include="syntax\lint_nonzero.c" />
<ClCompile Include="syntax\lint_nozeroprefix.c" />
<ClCompile Include="syntax\lint_packagetype.c" />
Expand All @@ -180,10 +177,10 @@
<ClCompile Include="syntax\lint_yesno.c" />
<ClCompile Include="syntax\lint_yymmd0.c" />
<ClCompile Include="syntax\lint_yymmdd.c" />
<ClCompile Include="syntax\lint_yymmddhh.c" />
<ClCompile Include="syntax\lint_yyyymmd0.c" />
<ClCompile Include="syntax\lint_yyyymmdd.c" />
<ClCompile Include="syntax\lint_zero.c" />
<ClCompile Include="syntax\lint__stubs.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ai.h" />
Expand Down
15 changes: 3 additions & 12 deletions src/c-lib/gs1encoders.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@
<ClCompile Include="syntax\lint_hhmi.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_hhmm.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_hyphen.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -87,9 +84,6 @@
<ClCompile Include="syntax\lint_iso3166alpha2.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_iso3166list.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_iso4217.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -111,9 +105,6 @@
<ClCompile Include="syntax\lint_mi.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_mmoptss.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_nonzero.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -147,9 +138,6 @@
<ClCompile Include="syntax\lint_yymmdd.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_yymmddhh.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_yyyymmd0.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -159,6 +147,9 @@
<ClCompile Include="syntax\lint_zero.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint__stubs.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="enc-private.h">
Expand Down
35 changes: 15 additions & 20 deletions src/c-lib/syntax/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 Expand Up @@ -119,24 +134,4 @@ do { \
} \
} while (0)


/**
* @brief Generates a stub function to replace legacy linters.
*
* The generated stub function is retained for API compatibility purposes only
* and is no longer referenced by the Syntax Dictionary.
*
*/
#define GS1_LINTER_STUB(linter) \
GS1_SYNTAX_DICTIONARY_API DEPRECATED gs1_lint_err_t linter( \
const char* const data, \
size_t* const err_pos, \
size_t* const err_len) \
{ \
(void)data; \
(void)err_pos; \
(void)err_len; \
GS1_LINTER_RETURN_OK; \
}

#endif /* GS1_SYNTAXDICTIONARY_UTILS_H */
108 changes: 66 additions & 42 deletions src/c-lib/syntax/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/c-lib/syntax/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
Loading

0 comments on commit c6067f1

Please sign in to comment.