1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
/*
* serialno.c
*
* Copyright (c) Chris Putnam 2005-2021
*
* Source code released under the GPL version 2
*
*/
#include <string.h>
#include "bibdefs.h"
#include "serialno.h"
int
add_sn( fields *info, char *buf, int level )
{
int ndigits, issn=0, isbn=0, isbn10=0, isbn13=0, status;
char *p = buf, *tag;
if ( !strncasecmp( p, "ISSN", 4 ) ) issn=1;
else if ( !strncasecmp( p, "ISBN", 4 ) ) isbn=1;
if ( isbn ) {
ndigits = 0;
while ( *p && !(ndigits && (*p==';'||*p==':')) ) {
if ( ( *p>='0' && *p<='9' ) || *p=='x' || *p=='X' )
ndigits++;
p++;
}
if ( ndigits==13 ) isbn13 = 1;
else /* ( ndigits==10) */ isbn10 = 1;
}
if ( !issn && !isbn ) {
/* a lot have semicolons between multiple ISBN's for
paperbacks and hardbacks with different numbers */
ndigits = 0;
while ( *p && !(ndigits && (*p==';'||*p==':')) ) {
if ( ( *p>='0' && *p<='9' ) || *p=='x' || *p=='X' )
ndigits++;
p++;
}
if ( ndigits==8 ) issn = 1;
else if ( ndigits==10 ) isbn10 = 1;
else if ( ndigits==13 ) isbn13 = 1;
}
if ( issn ) tag = "ISSN";
else if ( isbn10 ) tag = "ISBN";
else if ( isbn13 ) tag = "ISBN13";
else tag = "SERIALNUMBER";
status = fields_add( info, tag, buf, level );
if ( status==FIELDS_OK ) return BIBL_OK;
else return BIBL_ERR_MEMERR;
}
|