From b8d4bb76703bcb15578e2b23c5d256532180b894 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 3 Dec 2019 03:01:24 +0000 Subject: CTAN sync 201912030301 --- support/texlab/crates/bibutils_sys/src/url.c | 316 +++++++++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 support/texlab/crates/bibutils_sys/src/url.c (limited to 'support/texlab/crates/bibutils_sys/src/url.c') diff --git a/support/texlab/crates/bibutils_sys/src/url.c b/support/texlab/crates/bibutils_sys/src/url.c new file mode 100644 index 0000000000..b7a9c9e96f --- /dev/null +++ b/support/texlab/crates/bibutils_sys/src/url.c @@ -0,0 +1,316 @@ +/* + * 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-2019 + * + * Source code released under the GPL version 2 + * + */ +#include +#include +#include +#include +#include "bibutils.h" +#include "url.h" +#include "msvc_fix.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