7
7
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8
8
*
9
9
* IDENTIFICATION
10
- * $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.8 2008/01/01 19:45:45 momjian Exp $
10
+ * $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.9 2008/11/28 18:04:00 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
17
17
#include "fmgr.h"
18
18
#include "utils/builtins.h"
19
19
20
- PG_MODULE_MAGIC ;
21
-
22
20
#include "isn.h"
23
-
24
21
#include "EAN13.h"
25
22
#include "ISBN.h"
26
23
#include "ISMN.h"
27
24
#include "ISSN.h"
28
25
#include "UPC.h"
29
26
27
+ PG_MODULE_MAGIC ;
28
+
30
29
#define MAXEAN13LEN 18
31
30
32
31
enum isn_type
33
32
{
34
33
INVALID , ANY , EAN13 , ISBN , ISMN , ISSN , UPC
35
34
};
36
35
37
- static const char * isn_names [] = {"EAN13/UPC/ISxN" , "EAN13/UPC/ISxN" , "EAN13" , "ISBN" , "ISMN" , "ISSN" , "UPC" };
36
+ static const char * const isn_names [] = {"EAN13/UPC/ISxN" , "EAN13/UPC/ISxN" , "EAN13" , "ISBN" , "ISMN" , "ISSN" , "UPC" };
38
37
39
38
static bool g_weak = false;
40
39
static bool g_initialized = false;
@@ -58,8 +57,7 @@ static bool g_initialized = false;
58
57
* Check if the table and its index is correct (just for debugging)
59
58
*/
60
59
#ifdef ISN_DEBUG
61
- static
62
- bool
60
+ static bool
63
61
check_table (const char * (* TABLE )[2 ], const unsigned TABLE_index [10 ][2 ])
64
62
{
65
63
const char * aux1 ,
@@ -139,8 +137,7 @@ check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
139
137
* Formatting and conversion routines.
140
138
*---------------------------------------------------------*/
141
139
142
- static
143
- unsigned
140
+ static unsigned
144
141
dehyphenate (char * bufO , char * bufI )
145
142
{
146
143
unsigned ret = 0 ;
@@ -165,8 +162,7 @@ dehyphenate(char *bufO, char *bufI)
165
162
*
166
163
* Returns the number of characters acctually hyphenated.
167
164
*/
168
- static
169
- unsigned
165
+ static unsigned
170
166
hyphenate (char * bufO , char * bufI , const char * (* TABLE )[2 ], const unsigned TABLE_index [10 ][2 ])
171
167
{
172
168
unsigned ret = 0 ;
@@ -276,8 +272,7 @@ hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsigned TABLE_
276
272
*
277
273
* Returns the weight of the number (the check digit value, 0-10)
278
274
*/
279
- static
280
- unsigned
275
+ static unsigned
281
276
weight_checkdig (char * isn , unsigned size )
282
277
{
283
278
unsigned weight = 0 ;
@@ -303,8 +298,7 @@ weight_checkdig(char *isn, unsigned size)
303
298
*
304
299
* Returns the check digit value (0-9)
305
300
*/
306
- static
307
- unsigned
301
+ static unsigned
308
302
checkdig (char * num , unsigned size )
309
303
{
310
304
unsigned check = 0 ,
@@ -341,8 +335,7 @@ checkdig(char *num, unsigned size)
341
335
* If errorOK is false, ereport a useful error message if the ean13 is bad.
342
336
* If errorOK is true, just return "false" for bad input.
343
337
*/
344
- static
345
- bool
338
+ static bool
346
339
ean2isn (ean13 ean , bool errorOK , ean13 * result , enum isn_type accept )
347
340
{
348
341
enum isn_type type = INVALID ;
@@ -445,8 +438,7 @@ ean2isn(ean13 ean, bool errorOK, ean13 * result, enum isn_type accept)
445
438
* ean2UPC/ISxN --- Convert in-place a normalized EAN13 string to the corresponding
446
439
* UPC/ISxN string number. Assumes the input string is normalized.
447
440
*/
448
- static inline
449
- void
441
+ static inline void
450
442
ean2ISBN (char * isn )
451
443
{
452
444
char * aux ;
@@ -463,17 +455,17 @@ ean2ISBN(char *isn)
463
455
else
464
456
* aux = check + '0' ;
465
457
}
466
- static inline
467
- void
458
+
459
+ static inline void
468
460
ean2ISMN (char * isn )
469
461
{
470
462
/* the number should come in this format: 979-0-000-00000-0 */
471
463
/* Just strip the first part and change the first digit ('0') to 'M' */
472
464
hyphenate (isn , isn + 4 , NULL , NULL );
473
465
isn [0 ] = 'M' ;
474
466
}
475
- static inline
476
- void
467
+
468
+ static inline void
477
469
ean2ISSN (char * isn )
478
470
{
479
471
unsigned check ;
@@ -488,8 +480,8 @@ ean2ISSN(char *isn)
488
480
isn [8 ] = check + '0' ;
489
481
isn [9 ] = '\0' ;
490
482
}
491
- static inline
492
- void
483
+
484
+ static inline void
493
485
ean2UPC (char * isn )
494
486
{
495
487
/* the number should come in this format: 000-000000000-0 */
@@ -505,8 +497,7 @@ ean2UPC(char *isn)
505
497
*
506
498
* Returns the ean13 value of the string.
507
499
*/
508
- static
509
- ean13
500
+ static ean13
510
501
str2ean (const char * num )
511
502
{
512
503
ean13 ean = 0 ; /* current ean */
@@ -530,8 +521,7 @@ str2ean(const char *num)
530
521
* If errorOK is false, ereport a useful error message if the string is bad.
531
522
* If errorOK is true, just return "false" for bad input.
532
523
*/
533
- static
534
- bool
524
+ static bool
535
525
ean2string (ean13 ean , bool errorOK , char * result , bool shortType )
536
526
{
537
527
const char * (* TABLE )[2 ];
@@ -677,8 +667,7 @@ ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
677
667
* if the input string ends with '!' it will always be treated as invalid
678
668
* (even if the check digit is valid)
679
669
*/
680
- static
681
- bool
670
+ static bool
682
671
string2ean (const char * str , bool errorOK , ean13 * result ,
683
672
enum isn_type accept )
684
673
{
@@ -1110,7 +1099,6 @@ make_valid(PG_FUNCTION_ARGS)
1110
1099
PG_RETURN_EAN13 (val );
1111
1100
}
1112
1101
1113
- #ifdef ISN_WEAK_MODE
1114
1102
/* this function temporarily sets weak input flag
1115
1103
* (to lose the strictness of check digit acceptance)
1116
1104
* It's a helper function, not intended to be used!!
@@ -1119,18 +1107,13 @@ PG_FUNCTION_INFO_V1(accept_weak_input);
1119
1107
Datum
1120
1108
accept_weak_input (PG_FUNCTION_ARGS )
1121
1109
{
1110
+ #ifdef ISN_WEAK_MODE
1122
1111
g_weak = PG_GETARG_BOOL (0 );
1123
- PG_RETURN_BOOL (g_weak );
1124
- }
1125
1112
#else
1126
- PG_FUNCTION_INFO_V1 (accept_weak_input );
1127
- Datum
1128
- accept_weak_input (PG_FUNCTION_ARGS )
1129
- {
1130
1113
/* function has no effect */
1131
- PG_RETURN_BOOL (false);
1132
- }
1133
1114
#endif /* ISN_WEAK_MODE */
1115
+ PG_RETURN_BOOL (g_weak );
1116
+ }
1134
1117
1135
1118
PG_FUNCTION_INFO_V1 (weak_input_status );
1136
1119
Datum
0 commit comments