31#ifdef USE_ASSERT_CHECKING
44static const char *
const isn_names[] = {
"EAN13/UPC/ISxN",
"EAN13/UPC/ISxN",
"EAN13",
"ISBN",
"ISMN",
"ISSN",
"UPC"};
112 for (
j =
x;
j <=
y;
j++)
133 elog(
DEBUG1,
"invalid table near {\"%s\", \"%s\"} (pos: %d)",
202 search = *
bufI -
'0';
210 search =
lower + step;
245 search =
lower + step;
286 while (*
isn && size > 1)
290 weight += size-- * (*
isn -
'0');
294 weight = weight % 11;
296 weight = 11 - weight;
319 while (*num && size > 1)
321 if (
isdigit((
unsigned char) *num))
331 check = (check + 3 *
check3) % 10;
369 }
while (
ean && search++ < 12);
370 while (search++ < 12)
390 else if (*
buf ==
'0')
411 errmsg(
"cannot cast EAN13(%s) to %s for number: \"%s\"",
418 errmsg(
"cannot cast %s to %s for number: \"%s\"",
428 errmsg(
"value \"%" PRIu64 "\" is out of range for %s type",
483 isn[8] = check +
'0';
510 if (
isdigit((
unsigned char) *num))
511 ean = 10 *
ean + (*num -
'0');
530 const char *(*TABLE)[2];
562 }
while (
ean && search++ < 13);
563 while (search++ < 13)
577 if (
strncmp(
"978-", result, search) == 0)
584 else if (
strncmp(
"977-", result, search) == 0)
591 else if (
strncmp(
"979-0", result, search + 1) == 0)
598 else if (
strncmp(
"979-", result, search) == 0)
605 else if (*result ==
'0')
656 errmsg(
"value \"%" PRIu64 "\" is out of range for %s type",
688 while (*
aux2 && length <= 13)
690 last = (*(
aux2 + 1) ==
'!' || *(
aux2 + 1) ==
'\0');
693 if (*
aux2 ==
'?' && last)
695 magic =
digit =
true;
696 if (length == 0 && (*
aux2 ==
'M' || *
aux2 ==
'm'))
705 else if (length == 7 && (
digit || *
aux2 ==
'X' || *
aux2 ==
'x') && last)
714 else if (length == 9 && (
digit || *
aux2 ==
'X' || *
aux2 ==
'x') && last)
724 else if (length == 11 &&
digit && last)
733 else if (*
aux2 ==
'-' || *
aux2 ==
' ')
737 else if (*
aux2 ==
'!' && *(
aux2 + 1) ==
'\0')
765 check =
buf[15] -
'0';
767 else if (length == 12)
772 check =
buf[14] -
'0';
774 else if (length == 10)
781 check =
buf[12] -
'0';
783 else if (length == 8)
791 check =
buf[10] -
'0';
849 if (!valid && !magic)
853 *result |= valid ? 0 : 1;
865 if (
rcheck == (
unsigned) -1)
869 errmsg(
"invalid %s number: \"%s\"",
876 errmsg(
"invalid check digit for %s number: \"%s\", should be %c",
883 errmsg(
"invalid input syntax for %s number: \"%s\"",
889 errmsg(
"cannot cast %s to %s for number: \"%s\"",
895 errmsg(
"value \"%s\" is out of range for %s type",
922 "Accept input with invalid ISN check digits.",
static const unsigned EAN13_index[10][2]
static const char * EAN13_range[][2]
static const char * ISBN_range[][2]
static const unsigned ISBN_index[10][2]
static const unsigned ISBN_index_new[10][2]
static const char * ISBN_range_new[][2]
static const char * ISMN_range[][2]
static const unsigned ISMN_index[10][2]
static const unsigned ISSN_index[10][2]
static const char * ISSN_range[][2]
static const unsigned UPC_index[10][2]
static const char * UPC_range[][2]
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
#define PG_MODULE_MAGIC_EXT(...)
#define PG_RETURN_CSTRING(x)
#define PG_GETARG_CSTRING(n)
#define PG_FUNCTION_INFO_V1(funcname)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_BOOL(x)
void DefineCustomBoolVariable(const char *name, const char *short_desc, const char *long_desc, bool *valueAddr, bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, GucShowHook show_hook)
void MarkGUCPrefixReserved(const char *className)
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Datum upc_cast_from_ean13(PG_FUNCTION_ARGS)
Datum ean13_out(PG_FUNCTION_ARGS)
Datum issn_in(PG_FUNCTION_ARGS)
Datum isn_out(PG_FUNCTION_ARGS)
static bool string2ean(const char *str, struct Node *escontext, ean13 *result, enum isn_type accept)
Datum make_valid(PG_FUNCTION_ARGS)
static void ean2ISBN(char *isn)
Datum ismn_in(PG_FUNCTION_ARGS)
Datum accept_weak_input(PG_FUNCTION_ARGS)
static bool ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
const unsigned TABLE_index[10][2]
Datum weak_input_status(PG_FUNCTION_ARGS)
Datum upc_in(PG_FUNCTION_ARGS)
static bool ean2isn(ean13 ean, bool errorOK, ean13 *result, enum isn_type accept)
static const char *const isn_names[]
Datum isbn_in(PG_FUNCTION_ARGS)
Datum issn_cast_from_ean13(PG_FUNCTION_ARGS)
static void ean2UPC(char *isn)
Datum ean13_in(PG_FUNCTION_ARGS)
Datum ismn_cast_from_ean13(PG_FUNCTION_ARGS)
Datum isbn_cast_from_ean13(PG_FUNCTION_ARGS)
static unsigned hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
static unsigned checkdig(char *num, unsigned size)
static void ean2ISMN(char *isn)
Datum is_valid(PG_FUNCTION_ARGS)
static unsigned dehyphenate(char *bufO, char *bufI)
static unsigned weight_checkdig(char *isn, unsigned size)
static ean13 str2ean(const char *num)
pg_attribute_unused() static bool check_table(const char *(*TABLE)[2]
static void ean2ISSN(char *isn)
#define PG_GETARG_EAN13(n)
#define PG_RETURN_EAN13(x)
char * pstrdup(const char *in)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
static char buf[DEFAULT_XLOG_SEG_SIZE]
static unsigned char pg_ascii_toupper(unsigned char ch)
#define accept(s, addr, addrlen)