summaryrefslogtreecommitdiff
path: root/contrib/isn/isn.c
diff options
context:
space:
mode:
authorHeikki Linnakangas2015-08-02 19:12:33 +0000
committerHeikki Linnakangas2015-08-02 19:12:33 +0000
commitcb3384a0cb4cf900622b77865f60e31259923079 (patch)
tree95eb1dff1611bfe7a5b14f7fcb9e4a45b854471d /contrib/isn/isn.c
parentd73d14c271653dff10c349738df79ea03b85236c (diff)
Fix output of ISBN-13 numbers beginning with 979.
An EAN beginning with 979 (but not 9790 - those are ISMN's) are accepted as ISBN numbers, but they cannot be represented in the old, 10-digit ISBN format. They must be output in the new 13-digit ISBN-13 format. We printed out an incorrect value for those. Also add a regression test, to test this and some other basic functionality of the module. Patch by Fabien Coelho. This fixes bug #13442, reported by B.Z. Backpatch to 9.1, where we started to recognize ISBN-13 numbers.
Diffstat (limited to 'contrib/isn/isn.c')
-rw-r--r--contrib/isn/isn.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/contrib/isn/isn.c b/contrib/isn/isn.c
index 40398245f6d..9f53e1a1fbf 100644
--- a/contrib/isn/isn.c
+++ b/contrib/isn/isn.c
@@ -443,16 +443,23 @@ ean2ISBN(char *isn)
char *aux;
unsigned check;
- /* the number should come in this format: 978-0-000-00000-0 */
- /* Strip the first part and calculate the new check digit */
- hyphenate(isn, isn + 4, NULL, NULL);
- check = weight_checkdig(isn, 10);
- aux = strchr(isn, '\0');
- while (!isdigit((unsigned char) *--aux));
- if (check == 10)
- *aux = 'X';
- else
- *aux = check + '0';
+ /*
+ * The number should come in this format: 978-0-000-00000-0
+ * or may be an ISBN-13 number, 979-..., which does not have a short
+ * representation. Do the short output version if possible.
+ */
+ if (strncmp("978-", isn, 4) == 0)
+ {
+ /* Strip the first part and calculate the new check digit */
+ hyphenate(isn, isn + 4, NULL, NULL);
+ check = weight_checkdig(isn, 10);
+ aux = strchr(isn, '\0');
+ while (!isdigit((unsigned char) *--aux));
+ if (check == 10)
+ *aux = 'X';
+ else
+ *aux = check + '0';
+ }
}
static inline void