5
* Handle outputing DOI as a URL (Endnote and RIS formats)
6
* 1) Append http://dx.doi.org as necessary
7
* 2) Check for overlap with pre-existing URL for the DOI
10
* Check for DOI buried in another field.
12
* Copyright (c) Chris Putnam 2008-2010
14
* Source code released under the GPL
24
construct_url( char *prefix, newstr *id, newstr *id_url )
26
if ( !strncasecmp( id->data, "http:", 5 ) )
27
newstr_newstrcpy( id_url, id );
29
newstr_strcpy( id_url, prefix );
30
if ( id->data[0]!='/' ) newstr_addchar( id_url, '/' );
31
newstr_newstrcat( id_url, id );
36
url_exists( fields *info, char *urltag, newstr *doi_url )
40
for ( i=0; i<info->nfields && !found; ++i ) {
41
if ( strcmp( info->tag[i].data, urltag ) )
43
if ( !strcmp( info->data[i].data, doi_url->data ) )
51
doi_to_url( fields *info, int n, char *urltag, newstr *doi_url )
53
newstr_empty( doi_url );
54
construct_url( "http://dx.doi.org", &(info->data[n]), doi_url );
55
if ( url_exists( info, urltag, doi_url ) )
56
newstr_empty( doi_url );
60
jstor_to_url( fields *info, int n, char *urltag, newstr *jstor_url )
62
newstr_empty( jstor_url );
63
construct_url( "http://www.jstor.org/stable", &(info->data[n]),
65
if ( url_exists( info, urltag, jstor_url ) )
66
newstr_empty( jstor_url );
70
pmid_to_url( fields *info, int n, char *urltag, newstr *pmid_url )
72
newstr_empty( pmid_url );
73
construct_url( "http://www.ncbi.nlm.nih.gov/pubmed", &(info->data[n]),
75
if ( url_exists( info, urltag, pmid_url ) )
76
newstr_empty( pmid_url );
80
arxiv_to_url( fields *info, int n, char *urltag, newstr *arxiv_url )
82
newstr_empty( arxiv_url );
83
construct_url( "http://arxiv.org/abs", &(info->data[n]), arxiv_url );
84
if ( url_exists( info, urltag, arxiv_url ) )
85
newstr_empty( arxiv_url );
88
/* Rules for the pattern:
90
* isalpha() = match precisely (matchcase==1) or match regardless of case
92
* all others must match precisely
95
string_pattern( char *s, char *pattern, int matchcase )
98
patlen = strlen( pattern );
99
if ( strlen( s ) < patlen ) return 0; /* too short */
100
for ( i=0; i<patlen; ++i ) {
102
if ( pattern[i]=='#' ) {
103
if ( isdigit( s[i] ) ) match = 1;
104
} else if ( !matchcase && isalpha( pattern[i] ) ) {
105
if ( tolower(pattern[i])==tolower(s[i])) match = 1;
107
if ( pattern[i] == s[i] ) match = 1;
109
if ( !match ) return 0;
114
/* science direct is now doing "M3 - doi: DOI: 10.xxxx/xxxxx" */
118
if ( string_pattern( s, "##.####/", 0 ) ) return 0;
119
if ( string_pattern( s, "doi:##.####/", 0 ) ) return 4;
120
if ( string_pattern( s, "doi: ##.####/", 0 ) ) return 5;
121
if ( string_pattern( s, "doi: DOI: ##.####/", 0 ) ) return 10;