/* * url.c * * doi_to_url() * Handle outputing DOI as a URL (Endnote and RIS formats) * 1) Append https://doi.org as necessary * 2) Check for overlap with pre-existing URL for the DOI * * is_doi() * Check for DOI buried in another field. * * Copyright (c) Chris Putnam 2008-2018 * * Source code released under the GPL version 2 * */ #include #include #include #include #include "bibutils.h" #include "url.h" static void construct_url( char *prefix, str *id, str *id_url, char sep ) { if ( !strncasecmp( str_cstr( id ), "http:", 5 ) ) str_strcpy( id_url, id ); else { str_strcpyc( id_url, prefix ); if ( sep!='\0' ) { if ( id->data[0]!=sep ) str_addchar( id_url, sep ); } str_strcat( id_url, id ); } } static int url_exists( fields *f, char *urltag, str *doi_url ) { int i, n; if ( urltag ) { n = fields_num( f ); for ( i=0; in; ++i ) { str_strcpyc( &url, prefix ); str_strcatc( &url, ( char * ) vplist_get( values, i ) ); fstatus = fields_add( out, tag_out, str_cstr( &url ), lvl_out ); if ( fstatus!=FIELDS_OK ) { status = BIBL_ERR_MEMERR; goto out; } } out: str_free( &url ); return status; } /* * urls_merge_and_add() * * Append urls of types controlled by the list type and automatically append appropriate * prefixes. If no prefix is found for the entry, don't add one (e.g. "URL" entries). * * Control of the types to be added by list type is necessary as some reference formats * like bibtex ought to do special things with DOI, ARXIV, MRNUMBER, and the like. */ int urls_merge_and_add( fields *in, int lvl_in, fields *out, char *tag_out, int lvl_out, slist *types ) { int i, j, status = BIBL_OK; char *tag, *prefix, *empty=""; vplist a; vplist_init( &a ); for ( i=0; in; ++i ) { tag = slist_cstr( types, i ); /* ...look for data of requested type; if not found skip */ vplist_empty( &a ); fields_findv_each( in, lvl_in, FIELDS_CHRP, &a, tag ); if ( a.n==0 ) continue; /* ...find the prefix (if present) */ prefix = empty; for ( j=0; j