Skip to content

Commit 5f77b1a

Browse files
committed
Cosmetic cleanups in contrib/isn (doesn't fix the passbyval problem)
1 parent 5d2a1a4 commit 5f77b1a

File tree

2 files changed

+26
-43
lines changed

2 files changed

+26
-43
lines changed

contrib/isn/isn.c

Lines changed: 23 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
*
99
* 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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -17,24 +17,23 @@
1717
#include "fmgr.h"
1818
#include "utils/builtins.h"
1919

20-
PG_MODULE_MAGIC;
21-
2220
#include "isn.h"
23-
2421
#include "EAN13.h"
2522
#include "ISBN.h"
2623
#include "ISMN.h"
2724
#include "ISSN.h"
2825
#include "UPC.h"
2926

27+
PG_MODULE_MAGIC;
28+
3029
#define MAXEAN13LEN 18
3130

3231
enum isn_type
3332
{
3433
INVALID, ANY, EAN13, ISBN, ISMN, ISSN, UPC
3534
};
3635

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"};
3837

3938
static bool g_weak = false;
4039
static bool g_initialized = false;
@@ -58,8 +57,7 @@ static bool g_initialized = false;
5857
* Check if the table and its index is correct (just for debugging)
5958
*/
6059
#ifdef ISN_DEBUG
61-
static
62-
bool
60+
static bool
6361
check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
6462
{
6563
const char *aux1,
@@ -139,8 +137,7 @@ check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
139137
* Formatting and conversion routines.
140138
*---------------------------------------------------------*/
141139

142-
static
143-
unsigned
140+
static unsigned
144141
dehyphenate(char *bufO, char *bufI)
145142
{
146143
unsigned ret = 0;
@@ -165,8 +162,7 @@ dehyphenate(char *bufO, char *bufI)
165162
*
166163
* Returns the number of characters acctually hyphenated.
167164
*/
168-
static
169-
unsigned
165+
static unsigned
170166
hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
171167
{
172168
unsigned ret = 0;
@@ -276,8 +272,7 @@ hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsigned TABLE_
276272
*
277273
* Returns the weight of the number (the check digit value, 0-10)
278274
*/
279-
static
280-
unsigned
275+
static unsigned
281276
weight_checkdig(char *isn, unsigned size)
282277
{
283278
unsigned weight = 0;
@@ -303,8 +298,7 @@ weight_checkdig(char *isn, unsigned size)
303298
*
304299
* Returns the check digit value (0-9)
305300
*/
306-
static
307-
unsigned
301+
static unsigned
308302
checkdig(char *num, unsigned size)
309303
{
310304
unsigned check = 0,
@@ -341,8 +335,7 @@ checkdig(char *num, unsigned size)
341335
* If errorOK is false, ereport a useful error message if the ean13 is bad.
342336
* If errorOK is true, just return "false" for bad input.
343337
*/
344-
static
345-
bool
338+
static bool
346339
ean2isn(ean13 ean, bool errorOK, ean13 * result, enum isn_type accept)
347340
{
348341
enum isn_type type = INVALID;
@@ -445,8 +438,7 @@ ean2isn(ean13 ean, bool errorOK, ean13 * result, enum isn_type accept)
445438
* ean2UPC/ISxN --- Convert in-place a normalized EAN13 string to the corresponding
446439
* UPC/ISxN string number. Assumes the input string is normalized.
447440
*/
448-
static inline
449-
void
441+
static inline void
450442
ean2ISBN(char *isn)
451443
{
452444
char *aux;
@@ -463,17 +455,17 @@ ean2ISBN(char *isn)
463455
else
464456
*aux = check + '0';
465457
}
466-
static inline
467-
void
458+
459+
static inline void
468460
ean2ISMN(char *isn)
469461
{
470462
/* the number should come in this format: 979-0-000-00000-0 */
471463
/* Just strip the first part and change the first digit ('0') to 'M' */
472464
hyphenate(isn, isn + 4, NULL, NULL);
473465
isn[0] = 'M';
474466
}
475-
static inline
476-
void
467+
468+
static inline void
477469
ean2ISSN(char *isn)
478470
{
479471
unsigned check;
@@ -488,8 +480,8 @@ ean2ISSN(char *isn)
488480
isn[8] = check + '0';
489481
isn[9] = '\0';
490482
}
491-
static inline
492-
void
483+
484+
static inline void
493485
ean2UPC(char *isn)
494486
{
495487
/* the number should come in this format: 000-000000000-0 */
@@ -505,8 +497,7 @@ ean2UPC(char *isn)
505497
*
506498
* Returns the ean13 value of the string.
507499
*/
508-
static
509-
ean13
500+
static ean13
510501
str2ean(const char *num)
511502
{
512503
ean13 ean = 0; /* current ean */
@@ -530,8 +521,7 @@ str2ean(const char *num)
530521
* If errorOK is false, ereport a useful error message if the string is bad.
531522
* If errorOK is true, just return "false" for bad input.
532523
*/
533-
static
534-
bool
524+
static bool
535525
ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
536526
{
537527
const char *(*TABLE)[2];
@@ -677,8 +667,7 @@ ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
677667
* if the input string ends with '!' it will always be treated as invalid
678668
* (even if the check digit is valid)
679669
*/
680-
static
681-
bool
670+
static bool
682671
string2ean(const char *str, bool errorOK, ean13 * result,
683672
enum isn_type accept)
684673
{
@@ -1110,7 +1099,6 @@ make_valid(PG_FUNCTION_ARGS)
11101099
PG_RETURN_EAN13(val);
11111100
}
11121101

1113-
#ifdef ISN_WEAK_MODE
11141102
/* this function temporarily sets weak input flag
11151103
* (to lose the strictness of check digit acceptance)
11161104
* It's a helper function, not intended to be used!!
@@ -1119,18 +1107,13 @@ PG_FUNCTION_INFO_V1(accept_weak_input);
11191107
Datum
11201108
accept_weak_input(PG_FUNCTION_ARGS)
11211109
{
1110+
#ifdef ISN_WEAK_MODE
11221111
g_weak = PG_GETARG_BOOL(0);
1123-
PG_RETURN_BOOL(g_weak);
1124-
}
11251112
#else
1126-
PG_FUNCTION_INFO_V1(accept_weak_input);
1127-
Datum
1128-
accept_weak_input(PG_FUNCTION_ARGS)
1129-
{
11301113
/* function has no effect */
1131-
PG_RETURN_BOOL(false);
1132-
}
11331114
#endif /* ISN_WEAK_MODE */
1115+
PG_RETURN_BOOL(g_weak);
1116+
}
11341117

11351118
PG_FUNCTION_INFO_V1(weak_input_status);
11361119
Datum

contrib/isn/isn.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/contrib/isn/isn.h,v 1.5 2008/01/01 19:45:45 momjian Exp $
10+
* $PostgreSQL: pgsql/contrib/isn/isn.h,v 1.6 2008/11/28 18:04:00 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -27,8 +27,8 @@ typedef uint64 ean13;
2727

2828
#define EAN13_FORMAT UINT64_FORMAT
2929

30-
#define PG_GETARG_EAN13(n) PG_GETARG_INT64((int64)n)
31-
#define PG_RETURN_EAN13(x) PG_RETURN_INT64((int64)x)
30+
#define PG_GETARG_EAN13(n) PG_GETARG_INT64(n)
31+
#define PG_RETURN_EAN13(x) PG_RETURN_INT64(x)
3232

3333
extern Datum isn_out(PG_FUNCTION_ARGS);
3434
extern Datum ean13_out(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy