7
7
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
8
8
*
9
9
* IDENTIFICATION
10
- * $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.2 2006/09/10 20:45:17 tgl Exp $
10
+ * $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.3 2006/09/22 21:39:57 tgl Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -72,13 +72,16 @@ bool check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
72
72
aux2 = TABLE [i ][1 ];
73
73
74
74
/* must always start with a digit: */
75
- if (!isdigit (* aux1 ) || !isdigit (* aux2 )) goto invalidtable ;
75
+ if (!isdigit ((unsigned char ) * aux1 ) || !isdigit ((unsigned char ) * aux2 ))
76
+ goto invalidtable ;
76
77
a = * aux1 - '0' ;
77
78
b = * aux2 - '0' ;
78
79
79
80
/* must always have the same format and length: */
80
81
while (* aux1 && * aux2 ) {
81
- if (!(isdigit (* aux1 ) && isdigit (* aux2 )) && (* aux1 != * aux2 || * aux1 != '-' ))
82
+ if (!(isdigit ((unsigned char ) * aux1 ) &&
83
+ isdigit ((unsigned char ) * aux2 )) &&
84
+ (* aux1 != * aux2 || * aux1 != '-' ))
82
85
goto invalidtable ;
83
86
aux1 ++ ;
84
87
aux2 ++ ;
@@ -124,7 +127,7 @@ unsigned dehyphenate(char *bufO, char *bufI)
124
127
{
125
128
unsigned ret = 0 ;
126
129
while (* bufI ) {
127
- if (isdigit (* bufI )) {
130
+ if (isdigit (( unsigned char ) * bufI )) {
128
131
* bufO ++ = * bufI ;
129
132
ret ++ ;
130
133
}
@@ -183,7 +186,7 @@ unsigned hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsign
183
186
184
187
firstdig ++ , ean_aux1 ++ , ean_aux2 ++ ;
185
188
if (!(* ean_aux1 && * ean_aux2 && * firstdig )) break ;
186
- if (!isdigit (* ean_aux1 )) ean_aux1 ++ , ean_aux2 ++ ;
189
+ if (!isdigit (( unsigned char ) * ean_aux1 )) ean_aux1 ++ , ean_aux2 ++ ;
187
190
} else {
188
191
/* check in what direction we should go and move the pointer accordingly */
189
192
if (* firstdig < * ean_aux1 && !ean_in1 ) upper = search ;
@@ -227,7 +230,7 @@ unsigned weight_checkdig(char *isn, unsigned size)
227
230
{
228
231
unsigned weight = 0 ;
229
232
while (* isn && size > 1 ) {
230
- if (isdigit (* isn )) {
233
+ if (isdigit (( unsigned char ) * isn )) {
231
234
weight += size -- * (* isn - '0' );
232
235
}
233
236
isn ++ ;
@@ -254,7 +257,7 @@ unsigned checkdig(char *num, unsigned size)
254
257
pos = 1 ;
255
258
}
256
259
while (* num && size > 1 ) {
257
- if (isdigit (* num )) {
260
+ if (isdigit (( unsigned char ) * num )) {
258
261
if (pos ++ %2 ) check3 += * num - '0' ;
259
262
else check += * num - '0' ;
260
263
size -- ;
@@ -366,7 +369,7 @@ void ean2ISBN(char *isn)
366
369
hyphenate (isn , isn + 4 , NULL , NULL );
367
370
check = weight_checkdig (isn , 10 );
368
371
aux = strchr (isn , '\0' );
369
- while (!isdigit (* -- aux ));
372
+ while (!isdigit (( unsigned char ) * -- aux ));
370
373
if (check == 10 ) * aux = 'X' ;
371
374
else * aux = check + '0' ;
372
375
}
@@ -411,7 +414,7 @@ ean13 str2ean(const char *num)
411
414
{
412
415
ean13 ean = 0 ; /* current ean */
413
416
while (* num ) {
414
- if (isdigit (* num )) ean = 10 * ean + (* num - '0' );
417
+ if (isdigit (( unsigned char ) * num )) ean = 10 * ean + (* num - '0' );
415
418
num ++ ;
416
419
}
417
420
return (ean <<1 ); /* also give room to a flag */
@@ -570,7 +573,7 @@ bool string2ean(const char *str, bool errorOK, ean13 *result,
570
573
/* recognize and validate the number: */
571
574
while (* aux2 && length <= 13 ) {
572
575
last = (* (aux2 + 1 ) == '!' || * (aux2 + 1 ) == '\0' ); /* is the last character */
573
- digit = (isdigit (* aux2 )!= 0 ); /* is current character a digit? */
576
+ digit = (isdigit (( unsigned char ) * aux2 )!= 0 ); /* is current character a digit? */
574
577
if (* aux2 == '?' && last ) /* automagically calculate check digit if it's '?' */
575
578
magic = digit = true;
576
579
if (length == 0 && (* aux2 == 'M' || * aux2 == 'm' )) {
@@ -583,13 +586,13 @@ bool string2ean(const char *str, bool errorOK, ean13 *result,
583
586
/* only ISSN can be here */
584
587
if (type != INVALID ) goto eaninvalid ;
585
588
type = ISSN ;
586
- * aux1 ++ = toupper (* aux2 );
589
+ * aux1 ++ = toupper (( unsigned char ) * aux2 );
587
590
length ++ ;
588
591
} else if (length == 9 && (digit || * aux2 == 'X' || * aux2 == 'x' ) && last ) {
589
592
/* only ISBN and ISMN can be here */
590
593
if (type != INVALID && type != ISMN ) goto eaninvalid ;
591
594
if (type == INVALID ) type = ISBN ; /* ISMN must start with 'M' */
592
- * aux1 ++ = toupper (* aux2 );
595
+ * aux1 ++ = toupper (( unsigned char ) * aux2 );
593
596
length ++ ;
594
597
} else if (length == 11 && digit && last ) {
595
598
/* only UPC can be here */
0 commit comments