summaryrefslogtreecommitdiff
path: root/contrib/isn/isn.c
diff options
context:
space:
mode:
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 40942750feb..22bdf62641c 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