GS1 Barcode Syntax Tests reference
A reference to the AI component "linter" routines referred to by the GS1 Barcode Syntax Dictionary. Copyright (c) 2022-2024 GS1 AISBL.
Macros
lint_gcppos1.c File Reference

Macros

#define GCP_MIN_LENGTH   4
 Currently the shortest GS1 Company Prefix is four digits.
 

Purpose

The gcppos1 linter checks whether an input starts with a GS1 Company Prefix ("GCP").

Remarks
The GCP is defined in the GS1 General Specifications section "GS1 Company Prefix".

Functional Description

◆ gs1_lint_gcppos1()

GS1_SYNTAX_DICTIONARY_API gs1_lint_err_t gs1_lint_gcppos1 ( const char *const  data,
size_t *const  err_pos,
size_t *const  err_len 
)

Used to ensure that an AI component starts with a GCP.

Note
To enable this linter to hook into a GS1 Company Prefix lookup service containing a record of current GCP allocations (provided by the user) the GS1_LINTER_CUSTOM_GCP_LOOKUP_H macro may be set to the name of a header file to be included that defines a custom GS1_LINTER_CUSTOM_GCP_LOOKUP macro.
If provided, the GS1_LINTER_CUSTOM_GCP_LOOKUP macro shall invoke whatever API is defined by the user-provided GCP lookup service, then using the result must assign to locally-scoped variables as follows:
  • valid: Set to 1 if the GCP is valid (or should be treated as such). Otherwise 0.
  • offline: Set to 1 to indicate that the GCP data source is offline and the linter must fail. Otherwise 0.
Parameters
[in]dataPointer to the null-terminated data to be linted. Must not be NULL.
[out]err_posTo facilitate error highlighting, the start position of the bad data is written to this pointer, if not NULL.
[out]err_lenThe length of the bad data is written to this pointer, if not NULL.
Returns
GS1_LINTER_OK if okay.
GS1_LINTER_INVALID_GCP_PREFIX if the data does not start with a GCP.
GS1_LINTER_TOO_SHORT_FOR_GCP if the data is too short to start with a GCP.
GS1_LINTER_GCP_DATASOURCE_OFFLINE if the user-provided GCP lookup source is unavailable and this should result in the linting failing. [IMPLEMENTATION SPECIFIC]
Note
When GCP lookup service is provided by the user, it will be called with strings whose prefix may be one of (1) a regular GCP, (2) a UPC Company Code normalised to a regular GCP (by prefixing "0"), or (3) a GS1-8 Prefix normalised to a regular GCP by prefixing "00000".
The choice of whether or not to assign offline = 1 in order to return GS1_LINTER_GCP_DATASOURCE_OFFLINE when a user-provided GCP lookup service is unavailable is implementation specific. It depends on whether the desired behaviour is to fail open (return GS1_LINTER_OK) or to fail closed (return GS1_LINTER_GCP_DATASOURCE_OFFLINE). In the case that it is desirable to fail open then in addition to assigning offline = 0 it is necessary to assign valid = 1 to avoid returning GS1_LINTER_INVALID_GCP_PREFIX, which would be misleading in the event of service outage.
102{
103
104 size_t i;
105
106 assert(data);
107
108 /*
109 * Any character within the minimum-length GCP prefix that is outside
110 * the range '0' to '9' is illegal.
111 *
112 */
113 for (i = 0; i < GCP_MIN_LENGTH; i++) {
114 if (GS1_LINTER_UNLIKELY(!data[i]))
117 0,
118 i
119 );
120 if (GS1_LINTER_UNLIKELY(data[i] < '0' || data[i] > '9'))
123 i,
124 1
125 );
126 }
127
128 /*
129 * Call the custom GCP lookup routine if one has been provided.
130 *
131 */
132#ifdef GS1_LINTER_CUSTOM_GCP_LOOKUP
133{
134 int valid = 0, offline = 0;
135 GS1_LINTER_CUSTOM_GCP_LOOKUP(data);
136 if (GS1_LINTER_UNLIKELY(offline))
138 else if (GS1_LINTER_UNLIKELY(!valid))
140}
141#endif
142
144
145}
#define GS1_LINTER_UNLIKELY(x)
Implemention may provide hint to the compiler that the expression is likely to be false.
Definition gs1syntaxdictionary-utils.h:76
#define GS1_LINTER_RETURN_ERROR(error, position, length)
Return from a linter indicating that a problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:103
#define GS1_LINTER_RETURN_OK
Return from a linter indicating that no problem was detected with the given data.
Definition gs1syntaxdictionary-utils.h:88
@ GS1_LINTER_TOO_SHORT_FOR_GCP
The component is shorter than the minimum length GS1 Company Prefix.
Definition gs1syntaxdictionary.h:199
@ GS1_LINTER_GCP_DATASOURCE_OFFLINE
The data source for GCP lookups is offline.
Definition gs1syntaxdictionary.h:87
@ GS1_LINTER_INVALID_GCP_PREFIX
The GS1 Company Prefix is invalid.
Definition gs1syntaxdictionary.h:89
#define GCP_MIN_LENGTH
Currently the shortest GS1 Company Prefix is four digits.
Definition lint_gcppos1.c:50