77 * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
88 *
99 * 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 $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -72,13 +72,16 @@ bool check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
7272aux2 = TABLE [i ][1 ];
7373
7474/* must always start with a digit: */
75- if (!isdigit (* aux1 )|| !isdigit (* aux2 )) gotoinvalidtable ;
75+ if (!isdigit ((unsignedchar )* aux1 )|| !isdigit ((unsignedchar )* aux2 ))
76+ gotoinvalidtable ;
7677a = * aux1 - '0' ;
7778b = * aux2 - '0' ;
7879
7980/* must always have the same format and length: */
8081while (* aux1 && * aux2 ) {
81- if (!(isdigit (* aux1 )&& isdigit (* aux2 ))&& (* aux1 != * aux2 || * aux1 != '-' ))
82+ if (!(isdigit ((unsignedchar )* aux1 )&&
83+ isdigit ((unsignedchar )* aux2 ))&&
84+ (* aux1 != * aux2 || * aux1 != '-' ))
8285gotoinvalidtable ;
8386aux1 ++ ;
8487aux2 ++ ;
@@ -124,7 +127,7 @@ unsigned dehyphenate(char *bufO, char *bufI)
124127{
125128unsigned ret = 0 ;
126129while (* bufI ) {
127- if (isdigit (* bufI )) {
130+ if (isdigit (( unsigned char ) * bufI )) {
128131* bufO ++ = * bufI ;
129132ret ++ ;
130133}
@@ -183,7 +186,7 @@ unsigned hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsign
183186
184187firstdig ++ ,ean_aux1 ++ ,ean_aux2 ++ ;
185188if (!(* 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 ++ ;
187190}else {
188191/* check in what direction we should go and move the pointer accordingly */
189192if (* firstdig < * ean_aux1 && !ean_in1 )upper = search ;
@@ -227,7 +230,7 @@ unsigned weight_checkdig(char *isn, unsigned size)
227230{
228231unsigned weight = 0 ;
229232while (* isn && size > 1 ) {
230- if (isdigit (* isn )) {
233+ if (isdigit (( unsigned char ) * isn )) {
231234weight += size -- * (* isn - '0' );
232235}
233236isn ++ ;
@@ -254,7 +257,7 @@ unsigned checkdig(char *num, unsigned size)
254257pos = 1 ;
255258}
256259while (* num && size > 1 ) {
257- if (isdigit (* num )) {
260+ if (isdigit (( unsigned char ) * num )) {
258261if (pos ++ %2 )check3 += * num - '0' ;
259262else check += * num - '0' ;
260263size -- ;
@@ -366,7 +369,7 @@ void ean2ISBN(char *isn)
366369hyphenate (isn ,isn + 4 ,NULL ,NULL );
367370check = weight_checkdig (isn ,10 );
368371aux = strchr (isn ,'\0' );
369- while (!isdigit (* -- aux ));
372+ while (!isdigit (( unsigned char ) * -- aux ));
370373if (check == 10 )* aux = 'X' ;
371374else * aux = check + '0' ;
372375}
@@ -411,7 +414,7 @@ ean13 str2ean(const char *num)
411414{
412415ean13 ean = 0 ;/* current ean */
413416while (* num ) {
414- if (isdigit (* num ))ean = 10 * ean + (* num - '0' );
417+ if (isdigit (( unsigned char ) * num ))ean = 10 * ean + (* num - '0' );
415418num ++ ;
416419}
417420return (ean <<1 );/* also give room to a flag */
@@ -570,7 +573,7 @@ bool string2ean(const char *str, bool errorOK, ean13 *result,
570573/* recognize and validate the number: */
571574while (* aux2 && length <=13 ) {
572575last = (* (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? */
574577if (* aux2 == '?' && last )/* automagically calculate check digit if it's '?' */
575578magic = digit = true;
576579if (length == 0 && (* aux2 == 'M' || * aux2 == 'm' )) {
@@ -583,13 +586,13 @@ bool string2ean(const char *str, bool errorOK, ean13 *result,
583586/* only ISSN can be here */
584587if (type != INVALID ) gotoeaninvalid ;
585588type = ISSN ;
586- * aux1 ++ = toupper (* aux2 );
589+ * aux1 ++ = toupper (( unsigned char ) * aux2 );
587590length ++ ;
588591}else if (length == 9 && (digit || * aux2 == 'X' || * aux2 == 'x' )&& last ) {
589592/* only ISBN and ISMN can be here */
590593if (type != INVALID && type != ISMN ) gotoeaninvalid ;
591594if (type == INVALID )type = ISBN ;/* ISMN must start with 'M' */
592- * aux1 ++ = toupper (* aux2 );
595+ * aux1 ++ = toupper (( unsigned char ) * aux2 );
593596length ++ ;
594597}else if (length == 11 && digit && last ) {
595598/* only UPC can be here */