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 Sep 22, 2024
1 parent 93d0b6d commit 97e296b
Show file tree
Hide file tree
Showing 50 changed files with 1,718 additions and 774 deletions.
2 changes: 2 additions & 0 deletions src/c-lib/gs1-syntax-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,14 @@
7038 ? N3,iso3166999 X..27 req=01,02 # PROCESSOR # 8
7039 ? N3,iso3166999 X..27 req=01,02 # PROCESSOR # 9
7040 N1 X1 X1 X1,importeridx # UIC+EXT
7041 X..4,packagetype req=00 # UFRGT UNIT TYPE
710 ? X..20 req=01 # NHRN PZN
711 ? X..20 req=01 # NHRN CIP
712 ? X..20 req=01 # NHRN CN
713 ? X..20 req=01 # NHRN DRN
714 ? X..20 req=01 # NHRN AIM
715 ? X..20 req=01 # NHRN NDC
716 ? X..20 req=01 # NHRN AIC
7230 ? X2 X..28 req=01,8004 # CERT # 1
7231 ? X2 X..28 req=01,8004 # CERT # 2
7232 ? X2 X..28 req=01,8004 # CERT # 3
Expand Down
2 changes: 2 additions & 0 deletions src/c-lib/gs1encoders-test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
<ClInclude Include="syn.h" />
<ClInclude Include="syntax\acutest.h" />
<ClInclude Include="syntax\gs1syntaxdictionary.h" />
<ClInclude Include="syntax\gs1syntaxdictionary-utils.h" />
<ClInclude Include="syntax\unittest.h" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -200,6 +201,7 @@
<ClCompile Include="syntax\lint_mmoptss.c" />
<ClCompile Include="syntax\lint_nonzero.c" />
<ClCompile Include="syntax\lint_nozeroprefix.c" />
<ClCompile Include="syntax\lint_packagetype.c" />
<ClCompile Include="syntax\lint_pcenc.c" />
<ClCompile Include="syntax\lint_pieceoftotal.c" />
<ClCompile Include="syntax\lint_posinseqslash.c" />
Expand Down
6 changes: 6 additions & 0 deletions src/c-lib/gs1encoders-test.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<ClInclude Include="syntax\gs1syntaxdictionary.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="syntax\gs1syntaxdictionary-utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="syntax\unittest.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -155,6 +158,9 @@
<ClCompile Include="syntax\lint_nozeroprefix.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_packagetype.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_pcenc.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions src/c-lib/gs1encoders.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<ClCompile Include="syntax\lint_mmoptss.c" />
<ClCompile Include="syntax\lint_nonzero.c" />
<ClCompile Include="syntax\lint_nozeroprefix.c" />
<ClCompile Include="syntax\lint_packagetype.c" />
<ClCompile Include="syntax\lint_pcenc.c" />
<ClCompile Include="syntax\lint_pieceoftotal.c" />
<ClCompile Include="syntax\lint_posinseqslash.c" />
Expand All @@ -192,6 +193,7 @@
<ClInclude Include="scandata.h" />
<ClInclude Include="syn.h" />
<ClInclude Include="syntax\gs1syntaxdictionary.h" />
<ClInclude Include="syntax\gs1syntaxdictionary-utils.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
6 changes: 6 additions & 0 deletions src/c-lib/gs1encoders.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<ClCompile Include="syntax\lint_nozeroprefix.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_packagetype.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="syntax\lint_pcenc.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -179,5 +182,8 @@
<ClInclude Include="syntax\gs1syntaxdictionary.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="syntax\gs1syntaxdictionary-utils.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
117 changes: 117 additions & 0 deletions src/c-lib/syntax/gs1syntaxdictionary-utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* GS1 Syntax Dictionary. Copyright (c) 2022-2024 GS1 AISBL.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/**
* @file gs1syntaxdictionary-utils.h
*
* @brief This header provides utility macros used by the reference linter
* functions.
*
*/

#ifndef GS1_SYNTAXDICTIONARY_UTILS_H
#define GS1_SYNTAXDICTIONARY_UTILS_H

#include "gs1syntaxdictionary.h"
#include <limits.h>


/**
* @brief Return from a linter indicating that no problem was detected with the
* given data.
*
* @note For many linters this does not guarantee that the data is valid, only
* that it satisfies all of the checks performed by the linter.
*
*/
#define GS1_LINTER_RETURN_OK \
do { \
return GS1_LINTER_OK; \
} while (0)


/**
* @brief Return from a linter indicating that a problem was detected with the
* given data.
*
* @param [in] error An error of type ::gs1_lint_err_t to return.
* @param [in] position The starting position of the invalid data.
* @param [in] length The length of the invalid data segment.
*
*/
#define GS1_LINTER_RETURN_ERROR(error, position, length) \
do { \
if (err_pos) *err_pos = position; \
if (err_len) *err_len = length; \
return error; \
} while (0)


/**
* @brief Perform a lookup of a position in a bit field
*
* @param [in] bit The bit position in the field to lookup. The position
* must be in the field otherwise the behaviour is undefined.
* @param [in] field An array whose elements (of type with arbitrary size) when
* concatinated produce a single bit field whose positions
* are numbered from left to right (MSB of first element to
* LSB of last element).
*
* The macro's effect is to set the value of the variable `valid` to `1` if
* the position numbered `bit` is set in the `field`.
*
*/
#define GS1_LINTER_BITFIELD_LOOKUP(bit, field) \
do { \
int w = CHAR_BIT * sizeof(field[0]); \
assert((size_t)(bit/w) < sizeof(field) / sizeof(field[0])); \
if (field[bit/w] & (1ull << (w-1) >> (bit%w))) \
valid = 1; \
} while (0)


/**
* @brief Perform a binary search for a search term in a sorted set of strings.
*
* @param [in] needle A search term string to be exactly matched.
* @param [in] haystack A array of strings to be searched. The array must be
* otherwise the matching behaviour is undefined.
*
* The macro's effect is to set the value of the variable `valid` to `1` if
* `needle` is found in `haystack`.
*
*/
#define GS1_LINTER_BINARY_SEARCH(needle, haystack) \
do { \
size_t s = 0; \
size_t e = sizeof(haystack) / sizeof(haystack[0]); \
while (s < e) { \
const size_t m = s + (e - s) / 2; \
const int cmp = strcmp(haystack[m], needle); \
if (cmp < 0) \
s = m + 1; \
else if (cmp > 0) \
e = m; \
else { \
valid = 1; \
break; \
} \
} \
} while (0)

#endif /* GS1_SYNTAXDICTIONARY_UTILS_H */
2 changes: 2 additions & 0 deletions src/c-lib/syntax/gs1syntaxdictionary.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const struct name_function_s name_function_map[] = {
{ .name = "mmoptss", .fn = gs1_lint_mmoptss },
{ .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 },
Expand Down Expand Up @@ -229,6 +230,7 @@ GS1_SYNTAX_DICTIONARY_API const char *gs1_lint_err_str[] = {
"The minute is too long for MM format.",
"The second is too short for SS format.",
"The second is too long for SS format.",
"A valid PackageTypeCode is required.",
};

#endif /* GS1_LINTER_ERR_STR_EN */
Expand Down
2 changes: 2 additions & 0 deletions src/c-lib/syntax/gs1syntaxdictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ typedef enum
GS1_LINTER_MINUTE_TOO_LONG, ///< The minute is too long for MM format.
GS1_LINTER_SECOND_TOO_SHORT, ///< The second is too short for SS format.
GS1_LINTER_SECOND_TOO_LONG, ///< The second is too long for SS format.
GS1_LINTER_INVALID_PACKAGE_TYPE, ///< A valid PackageTypeCode is required.
__GS1_LINTER_NUM_ERRS // Keep this as the last element which captures the size of this enumeration.
} gs1_lint_err_t;

Expand Down Expand Up @@ -250,6 +251,7 @@ GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_mm(const char *data, size_t *e
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_mmoptss(const char *data, size_t *err_pos, size_t *err_len);
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);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_pieceoftotal(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_posinseqslash(const char *data, size_t *err_pos, size_t *err_len);
GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_pcenc(const char *data, size_t *err_pos, size_t *err_len);
Expand Down
Loading

0 comments on commit 97e296b

Please sign in to comment.