hs-bibutils 6.5.0.0 → 6.6.0.0
raw patch · 11 files changed
+614/−44 lines, 11 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Bibutils: nbib_out :: BiblioOut
Files
- ChangeLog.md +7/−0
- bibutils/bibcore.c +14/−13
- bibutils/bibformats.h +19/−18
- bibutils/bibutils.c +1/−0
- bibutils/bibutils.h +2/−1
- bibutils/iso639_3.c +11/−0
- bibutils/iso639_3.h +1/−0
- bibutils/nbibout.c +544/−0
- bibutils/nbibtypes.c +3/−2
- hs-bibutils.cabal +10/−10
- src/Text/Bibutils.hsc +2/−0
ChangeLog.md view
@@ -1,3 +1,10 @@+# 6.6.0.0++ - Import Bibutils 6.6.++ - Expose NBIB output support.++ # 6.5.0.0 - Import Bibutils 6.5.
bibutils/bibcore.c view
@@ -44,15 +44,15 @@ case BIBL_EBIIN: fprintf( fp, " (BIBL_EBIIN)\n" ); break; case BIBL_WORDIN: fprintf( fp, " (BIBL_WORDIN)\n" ); break; case BIBL_NBIBIN: fprintf( fp, " (BIBL_NBIBIN)\n" ); break;- default: fprintf( fp, " (Illegal value %d)\n", p->readformat ); break;+ default: fprintf( fp, " (Illegal value)\n" ); break; } fprintf( fp, "\tcharsetin=%d\n", p->charsetin ); fprintf( fp, "\tcharsetin_src=%d", p->charsetin_src ); switch ( p->charsetin_src ) {- case 0: fprintf( fp, " (BIBL_SRC_DEFAULT)\n" ); break;- case 1: fprintf( fp, " (BIBL_SRC_FILE)\n" ); break;- case 2: fprintf( fp, " (BIBL_SRC_USER)\n" ); break;- default: fprintf( fp, " (Illegal value %d)\n", p->charsetin_src ); break;+ case BIBL_SRC_DEFAULT: fprintf( fp, " (BIBL_SRC_DEFAULT)\n" ); break;+ case BIBL_SRC_FILE: fprintf( fp, " (BIBL_SRC_FILE)\n" ); break;+ case BIBL_SRC_USER: fprintf( fp, " (BIBL_SRC_USER)\n" ); break;+ default: fprintf( fp, " (Illegal value)\n" ); break; } fprintf( fp, "\tutf8in=%d\n", p->utf8in ); fprintf( fp, "\tlatexin=%d\n", p->latexin );@@ -61,22 +61,23 @@ fprintf( fp, "\twriteformat=%d", p->writeformat ); switch ( p->writeformat ) { case BIBL_INTERNALOUT: fprintf( fp, " (BIBL_INTERNALOUT)\n" ); break;- case BIBL_MODSOUT: fprintf( fp, " (BIBL_MODSOUT)\n" ); break;+ case BIBL_ADSABSOUT: fprintf( fp, " (BIBL_ADSABSOUT)\n" ); break; case BIBL_BIBTEXOUT: fprintf( fp, " (BIBL_BIBTEXOUT)\n" ); break;- case BIBL_RISOUT: fprintf( fp, " (BIBL_RISOUT)\n" ); break; case BIBL_ENDNOTEOUT: fprintf( fp, " (BIBL_ENDNOTEOUT)\n" ); break; case BIBL_ISIOUT: fprintf( fp, " (BIBL_ISIOUT)\n" ); break;+ case BIBL_MODSOUT: fprintf( fp, " (BIBL_MODSOUT)\n" ); break;+ case BIBL_NBIBOUT: fprintf( fp, " (BIBL_NBIBOUT)\n" ); break;+ case BIBL_RISOUT: fprintf( fp, " (BIBL_RISOUT)\n" ); break; case BIBL_WORD2007OUT: fprintf( fp, " (BIBL_WORD2007OUT)\n" ); break;- case BIBL_ADSABSOUT: fprintf( fp, " (BIBL_ADSABSOUT)\n" ); break;- default: fprintf( fp, " (Illegal value %d)\n", p->writeformat ); break;+ default: fprintf( fp, " (Illegal value)\n"); break; } fprintf( fp, "\tcharsetout=%d\n", p->charsetout ); fprintf( fp, "\tcharsetout_src=%d", p->charsetout_src ); switch ( p->charsetout_src ) {- case 0: fprintf( fp, " (BIBL_SRC_DEFAULT)\n" ); break;- case 1: fprintf( fp, " (BIBL_SRC_FILE)\n" ); break;- case 2: fprintf( fp, " (BIBL_SRC_USER)\n" ); break;- default: fprintf( fp, " (Illegal value %d)\n", p->charsetout_src ); break;+ case BIBL_SRC_DEFAULT: fprintf( fp, " (BIBL_SRC_DEFAULT)\n" ); break;+ case BIBL_SRC_FILE: fprintf( fp, " (BIBL_SRC_FILE)\n" ); break;+ case BIBL_SRC_USER: fprintf( fp, " (BIBL_SRC_USER)\n" ); break;+ default: fprintf( fp, " (Illegal value)\n" ); break; } fprintf( fp, "\tutf8out=%d\n", p->utf8out ); fprintf( fp, "\tutf8bom=%d\n", p->utf8bom );
bibutils/bibformats.h view
@@ -11,25 +11,26 @@ #include "bibutils.h" -void adsout_initparams( param *p, const char *progname );+void adsout_initparams ( param *p, const char *progname ); void biblatexin_initparams( param *p, const char *progname );-void bibtexin_initparams( param *p, const char *progname );-void bibtexout_initparams( param *p, const char *progname );-void copacin_initparams( param *p, const char *progname );-void ebiin_initparams( param *p, const char *progname );-void endin_initparams( param *p, const char *progname );-void endout_initparams( param *p, const char *progname );-void endxmlin_initparams( param *p, const char *progname );-void isiin_initparams( param *p, const char *progname );-void isiout_initparams( param *p, const char *progname );-void medin_initparams( param *p, const char *progname );-void modsin_initparams( param *p, const char *progname );-void modsout_initparams( param *p, const char *progname );-void nbibin_initparams( param *p, const char *progname );-void risin_initparams( param *p, const char *progname );-void risout_initparams( param *p, const char *progname );-void wordin_initparams( param *p, const char *progname );-void wordout_initparams( param *p, const char *progname );+void bibtexin_initparams ( param *p, const char *progname );+void bibtexout_initparams ( param *p, const char *progname );+void copacin_initparams ( param *p, const char *progname );+void ebiin_initparams ( param *p, const char *progname );+void endin_initparams ( param *p, const char *progname );+void endout_initparams ( param *p, const char *progname );+void endxmlin_initparams ( param *p, const char *progname );+void isiin_initparams ( param *p, const char *progname );+void isiout_initparams ( param *p, const char *progname );+void medin_initparams ( param *p, const char *progname );+void modsin_initparams ( param *p, const char *progname );+void modsout_initparams ( param *p, const char *progname );+void nbibin_initparams ( param *p, const char *progname );+void nbibout_initparams ( param *p, const char *progname );+void risin_initparams ( param *p, const char *progname );+void risout_initparams ( param *p, const char *progname );+void wordin_initparams ( param *p, const char *progname );+void wordout_initparams ( param *p, const char *progname ); #endif
bibutils/bibutils.c view
@@ -36,6 +36,7 @@ case BIBL_ENDNOTEOUT: endout_initparams( p, progname ); break; case BIBL_ISIOUT: isiout_initparams( p, progname ); break; case BIBL_MODSOUT: modsout_initparams( p, progname ); break;+ case BIBL_NBIBOUT: nbibout_initparams( p, progname ); break; case BIBL_RISOUT: risout_initparams( p, progname ); break; case BIBL_WORD2007OUT: wordout_initparams( p, progname ); break; default: /* internal error */;
bibutils/bibutils.h view
@@ -47,7 +47,8 @@ #define BIBL_ISIOUT (BIBL_FIRSTOUT+4) #define BIBL_WORD2007OUT (BIBL_FIRSTOUT+5) #define BIBL_ADSABSOUT (BIBL_FIRSTOUT+6)-#define BIBL_LASTOUT (BIBL_FIRSTOUT+6)+#define BIBL_NBIBOUT (BIBL_FIRSTOUT+7)+#define BIBL_LASTOUT (BIBL_FIRSTOUT+7) #define BIBL_FORMAT_VERBOSE (1) #define BIBL_FORMAT_BIBOUT_FINALCOMMA (2)
bibutils/iso639_3.c view
@@ -8417,3 +8417,14 @@ } return NULL; }++char *+iso639_3_from_name( const char *name )+{+ int i;+ for ( i=0; i<niso639_3; ++i ) {+ if ( !strcasecmp( iso639_3[i].language, name ) )+ return iso639_3[i].code;+ }+ return NULL;+}
bibutils/iso639_3.h view
@@ -5,5 +5,6 @@ #define ISO639_3_H char * iso639_3_from_code( const char *code );+char * iso639_3_from_name( const char *name ); #endif
+ bibutils/nbibout.c view
@@ -0,0 +1,544 @@+/*+ * nbibout.c+ *+ * Copyright (c) Chris Putnam 2018+ *+ * Source code released under the GPL version 2+ *+ */+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <ctype.h>+#include "utf8.h"+#include "str.h"+#include "is_ws.h"+#include "strsearch.h"+#include "fields.h"+#include "iso639_3.h"+#include "title.h"+#include "bibutils.h"+#include "bibformats.h"++static int nbibout_write( fields *info, FILE *fp, param *p, unsigned long refnum );+static void nbibout_writeheader( FILE *outptr, param *p );++void+nbibout_initparams( param *p, const char *progname )+{+ p->writeformat = BIBL_NBIBOUT;+ p->format_opts = 0;+ p->charsetout = BIBL_CHARSET_DEFAULT;+ p->charsetout_src = BIBL_SRC_DEFAULT;+ p->latexout = 0;+ p->utf8out = BIBL_CHARSET_UTF8_DEFAULT;+ p->utf8bom = BIBL_CHARSET_BOM_DEFAULT;+ p->xmlout = BIBL_XMLOUT_FALSE;+ p->nosplittitle = 0;+ p->verbose = 0;+ p->addcount = 0;+ p->singlerefperfile = 0;++ if ( p->charsetout == BIBL_CHARSET_UNICODE ) {+ p->utf8out = p->utf8bom = 1;+ }++ p->headerf = nbibout_writeheader;+ p->footerf = NULL;+ p->writef = nbibout_write;+}++enum {+ TYPE_UNKNOWN = 0,+ TYPE_ARTICLE = 1,+ TYPE_INBOOK = 2,+ TYPE_BOOK = 3,+};++static void+append_type( fields *in, fields *out, int *status )+{+ int fstatus;+ char *s;+ int type = TYPE_UNKNOWN, i, n, level;+ char *tag, *value;++ n = fields_num( in );+ for ( i=0; i<n; ++i ) {+ tag = fields_tag( in, i, FIELDS_CHRP );+ if ( strcasecmp( tag, "GENRE:MARC" ) &&+ strcasecmp( tag, "GENRE:BIBUTILS" ) &&+ strcasecmp( tag, "GENRE:UNKNOWN" ) ) continue;+ value = fields_value( in, i, FIELDS_CHRP );+ level = fields_level( in, i );+ if ( !strcasecmp( value, "periodical" ) ||+ !strcasecmp( value, "academic journal" ) ||+ !strcasecmp( value, "journal article" ) ) {+ type = TYPE_ARTICLE;+ } else if ( !strcasecmp( value, "book" ) ) {+ if ( level==0 ) type=TYPE_BOOK;+ else type=TYPE_INBOOK;+ } else if ( !strcasecmp( value, "book chapter" ) ) {+ type = TYPE_INBOOK;+ }+ }++ if ( type==TYPE_ARTICLE ) s = "Journal Article";+ else if ( type==TYPE_INBOOK ) s = "Chapter";+ else if ( type==TYPE_BOOK ) s = "Book";+ else s = "Miscellaneous";++ fstatus = fields_add( out, "PT", s, LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+}++static void+append_titlecore( fields *in, char *nbibtag, int level, char *maintag, char *subtag, fields *out, int *status )+{+ str *mainttl = fields_findv( in, level, FIELDS_STRP, maintag );+ str *subttl = fields_findv( in, level, FIELDS_STRP, subtag );+ str fullttl;+ int fstatus;++ str_init( &fullttl );+ title_combine( &fullttl, mainttl, subttl );++ if ( str_memerr( &fullttl ) ) {+ *status = BIBL_ERR_MEMERR;+ goto out;+ }++ if ( str_has_value( &fullttl ) ) {+ fstatus = fields_add( out, nbibtag, str_cstr( &fullttl ), LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }+out:+ str_free( &fullttl );+}++static void+append_title( fields *in, char *nbibtag, int level, fields *out, int *status )+{+ append_titlecore( in, nbibtag, level, "TITLE", "SUBTITLE", out, status );+}++static void+append_abbrtitle( fields *in, char *nbibtag, int level, fields *out, int *status )+{+ append_titlecore( in, nbibtag, level, "SHORTTITLE", "SHORTSUBTITLE", out, status );+}++static void+process_person( str *person, char *name, int full )+{+ str family, given, suffix;+ char *p = name;++ str_empty( person );++ strs_init( &family, &given, &suffix, NULL );++ while ( *p && *p!='|' )+ str_addchar( &family, *p++ );++ if ( full ) {+ while ( *p=='|' && *(p+1)!='|' ) {+ p++;+ if ( *p!='|' && str_has_value( &given ) ) str_addchar( &given, ' ' );+ while ( *p && *p!='|' ) str_addchar( &given, *p++ );+ }+ }+ else {+ while ( *p=='|' && *(p+1)!='|' ) {+ p++;+ if ( *p!='|' ) str_addchar( &given, *p++ );+ while ( *p && *p!='|' ) p++;+ }+ }++ if ( *p=='|' && *(p+1)=='|' ) {+ p += 2;+ while ( *p && *p!='|' ) str_addchar( &suffix, *p++ );+ }++ if ( str_has_value( &family ) ) str_strcat( person, &family );+ if ( str_has_value( &suffix ) ) {+ if ( str_has_value( &family ) ) str_strcatc( person, " " );+ str_strcat( person, &suffix );+ }+ if ( str_has_value( &given ) ) {+ if ( str_has_value( person ) ) {+ if ( full ) str_strcatc( person, ", " );+ else str_strcatc( person, " " );+ }+ str_strcat( person, &given );+ }++ strs_free( &family, &given, &suffix, NULL );+}++static void+append_people( fields *f, char *tag, char *nbibtag_full, char *nbibtag_abbr, int level, fields *out, int *status )+{+ vplist_index i;+ vplist people;+ str person;+ int fstatus;++ str_init( &person );+ vplist_init( &people );++ fields_findv_each( f, level, FIELDS_CHRP, &people, tag );+ for ( i=0; i<people.n; ++i ) {++ process_person( &person, (char *)vplist_get( &people, i ), 1 );+ if ( str_memerr( &person ) ) { *status = BIBL_ERR_MEMERR; goto out; }+ fstatus = fields_add_can_dup( out, nbibtag_full, str_cstr( &person ), LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) { *status = BIBL_ERR_MEMERR; goto out; }++ process_person( &person, (char *)vplist_get( &people, i ), 0 );+ if ( str_memerr( &person ) ) { *status = BIBL_ERR_MEMERR; goto out; }+ fstatus = fields_add_can_dup( out, nbibtag_abbr, str_cstr( &person ), LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) { *status = BIBL_ERR_MEMERR; goto out; }++ }++out:+ vplist_free( &people );+ str_free( &person );+}++static void+append_easy( fields *in, char *tag, char *nbibtag, int level, fields *out, int *status )+{+ char *value;+ int fstatus;++ value = fields_findv( in, level, FIELDS_CHRP, tag );+ if ( value ) {+ fstatus = fields_add( out, nbibtag, value, LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }+}++static void+append_easyall( fields *in, char *tag, char *nbibtag, int level, fields *out, int *status )+{+ vplist_index i;+ int fstatus;+ vplist a;++ vplist_init( &a );+ fields_findv_each( in, level, FIELDS_CHRP, &a, tag );+ for ( i=0; i<a.n; ++i ) {+ fstatus = fields_add( out, nbibtag, (char *) vplist_get( &a, i ), LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }+ vplist_free( &a );+}++static void+append_pages( fields *in, char *nbibtag, int level, fields *out, int *status )+{+ str *start, *stop, *articlenumber;+ int fstatus;+ str pages;+ char *p, *q;++ str_init( &pages );++ start = fields_findv_firstof( in, level, FIELDS_STRP, "PAGES:START", NULL );+ if ( start ) {+ str_strcpy( &pages, start );+ }++ stop = fields_findv_firstof( in, level, FIELDS_STRP, "PAGES:STOP", NULL );+ if ( stop ) {+ /* nbib from pubmed doesn't do "PG - 101-109", but rather "PG - 101-9" */+ if ( start ) {+ p = str_cstr( start );+ q = str_cstr( stop );+ while ( *p && *p == *q ) {+ p++;+ q++;+ }+ if ( *q ) {+ str_addchar( &pages, '-' );+ str_strcatc( &pages, q );+ }+ }+ else {+ str_strcat( &pages, stop );+ }+ }++ articlenumber = fields_findv_firstof( in, level, FIELDS_STRP, "ARTICLENUMBER", NULL );+ if ( str_is_empty( &pages ) && articlenumber ) {+ str_strcpy( &pages, articlenumber );+ }++ if ( str_has_value( &pages ) ) {+ fstatus = fields_add( out, nbibtag, str_cstr( &pages ), LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }++ str_free( &pages );+}++/* location identifier */+static void+append_lid( fields *in, char *nbibtag, int level, fields *out, int *status )+{+ str *doi, *pii, *isi;+ int fstatus;+ str lid;++ str_init( &lid );++ doi = fields_findv( in, level, FIELDS_STRP, "DOI" );+ if ( doi ) {+ str_strcpy( &lid, doi );+ str_strcatc( &lid, " [doi]" );+ fstatus = fields_add( out, nbibtag, str_cstr( &lid ), LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }++ pii = fields_findv( in, level, FIELDS_STRP, "PII" );+ if ( pii ) {+ str_strcpy( &lid, pii );+ str_strcatc( &lid, " [pii]" );+ fstatus = fields_add( out, nbibtag, str_cstr( &lid ), LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }++ isi = fields_findv( in, level, FIELDS_STRP, "ISIREFNUM" );+ if ( isi ) {+ str_strcpy( &lid, isi );+ str_strcatc( &lid, " [isi]" );+ fstatus = fields_add( out, nbibtag, str_cstr( &lid ), LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }++++ str_free( &lid );+}++static void+append_date( fields *in, char *nbibtag, int level, fields *out, int *status )+{+ str *day, *month, *year;+ int fstatus;+ str date;++ str_init( &date );++ year = fields_findv_firstof( in, level, FIELDS_STRP, "PARTDATE:YEAR", "DATE:YEAR", NULL );+ if ( year ) {+ str_strcpy( &date, year );+ }++ month = fields_findv_firstof( in, level, FIELDS_STRP, "PARTDATE:MONTH", "DATE:MONTH", NULL );+ if ( month ) {+ if ( str_has_value( &date ) ) str_addchar( &date, ' ' );+ str_strcat( &date, month );+ }++ day = fields_findv_firstof( in, level, FIELDS_STRP, "PARTDATE:DAY", "DATE:DAY", NULL );+ if ( day ) {+ if ( str_has_value( &date ) ) str_addchar( &date, ' ' );+ str_strcat( &date, day );+ }++ if ( str_has_value( &date ) ) {+ fstatus = fields_add( out, nbibtag, str_cstr( &date ), LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }+ + str_free( &date );+}++static void+append_lang( fields *in, char *nbibtag, int level, fields *out, int *status )+{+ int fstatus;+ str *lang;+ char *code;++ lang = fields_findv( in, level, FIELDS_STRP, "LANGUAGE" );+ if ( lang ) {+ code = iso639_3_from_name( str_cstr( lang ) );+ if ( !code ) code = str_cstr( lang );+ fstatus = fields_add( out, nbibtag, code, LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }+}++static void+append_keywords( fields *in, char *nbibtag, int level, fields *out, int *status )+{+ vplist keywords;+ int fstatus;+ char *kw;+ int i;++ vplist_init( &keywords );++ fields_findv_each( in, level, FIELDS_CHRP, &keywords, "KEYWORD" );+ for ( i=0; i<keywords.n; ++i ) {+ kw = vplist_get( &keywords, i );+ fstatus = fields_add( out, nbibtag, kw, LEVEL_MAIN );+ if ( fstatus!=FIELDS_OK ) *status = BIBL_ERR_MEMERR;+ }+ +}++static int+append_data( fields *in, fields *out )+{+ int status = BIBL_OK;++ append_easy ( in, "PMID", "PMID", LEVEL_ANY, out, &status );+ append_easyall( in, "ISSN", "IS", LEVEL_ANY, out, &status );+ append_easy ( in, "VOLUME", "VI", LEVEL_ANY, out, &status );+ append_easy ( in, "ISSUE", "IP", LEVEL_ANY, out, &status );+ append_easy ( in, "NUMBER", "IP", LEVEL_ANY, out, &status );+ append_date ( in, "DP", LEVEL_ANY, out, &status );+ append_title( in, "TI", LEVEL_MAIN, out, &status );+ append_pages( in, "PG", LEVEL_ANY, out, &status );+ append_lid ( in, "LID", LEVEL_MAIN, out, &status );+ append_easy ( in, "ABSTRACT", "AB", LEVEL_MAIN, out, &status );+ append_people ( in, "AUTHOR", "FAU", "AU", LEVEL_MAIN, out, &status );+ append_easyall( in, "AUTHOR:CORP", "FAU", LEVEL_MAIN, out, &status );+ append_easyall( in, "AUTHOR:ASIS", "FAU", LEVEL_MAIN, out, &status );+ append_lang ( in, "LA", LEVEL_ANY, out, &status );+ append_type ( in, out, &status );+ append_easy( in, "ADDRESS", "PL", LEVEL_MAIN, out, &status );+ append_abbrtitle( in, "TA", LEVEL_HOST, out, &status );+ append_title( in, "JT", LEVEL_HOST, out, &status );+ append_easy ( in, "PMC", "PMC", LEVEL_ANY, out, &status );+ append_keywords( in, "OT", LEVEL_ANY, out, &status );+ return status;+}++static void+output_verbose( fields *f, const char *type, unsigned long refnum )+{+ char *tag, *value;+ int i, n, level;++ fprintf( stderr, "REF #%lu %s---\n", refnum+1, type );++ n = fields_num( f );+ for ( i=0; i<n; ++i ) {+ tag = fields_tag( f, i, FIELDS_CHRP_NOUSE );+ value = fields_value( f, i, FIELDS_CHRP_NOUSE );+ level = fields_level( f, i );+ fprintf( stderr, "\t'%s'\t'%s'\t%d\n", tag, value, level );+ }++ fflush( stderr );+}++static void+output_tag( FILE *fp, char *p )+{+ int i = 0;++ while ( i < 4 && p && *p ) {+ fprintf( fp, "%c", *p );+ i++;+ p++;+ }++ for ( ; i<4; ++i )+ fprintf( fp, " " );+ fprintf( fp, "- " );+}++static void+output_value( FILE *fp, str *value )+{+ char *p, *q, *lastws;+ int n;++ if ( value->len < 82 ) {+ fprintf( fp, "%s", str_cstr( value ) );+ return;+ }++ p = str_cstr( value );+ while ( p && *p ) {+ n = 0;+ q = p;+ lastws = NULL;+ while ( n < 82 && *q ) {+ if ( is_ws( *q ) ) lastws = q;+ q++;+ n++;+ }+ if ( *q && lastws ) {+ while ( p!=lastws ) {+ fprintf( fp, "%c", *p );+ p++;+ }+ p++; /* skip ws separator */+ }+ else {+ while ( p!=q ) {+ fprintf( fp, "%c", *p );+ p++;+ }+ p = q;+ }+ if ( *p ) {+ fprintf( fp, "\n" );+ fprintf( fp, " " );+ }+ }+}++static void+output_reference( FILE *fp, fields *out )+{+ int i;++ for ( i=0; i<out->n; ++i ) {++ output_tag( fp, ( char * ) fields_tag( out, i, FIELDS_CHRP ) );+ output_value( fp, ( str * ) fields_value( out, i, FIELDS_STRP ) );+ fprintf( fp, "\n" );+ }++ fprintf( fp, "\n\n" );+ fflush( fp );+}++static int+nbibout_write( fields *in, FILE *fp, param *p, unsigned long refnum )+{+ int status;+ fields out;++ fields_init( &out );++ if ( p->format_opts & BIBL_FORMAT_VERBOSE )+ output_verbose( in, "IN", refnum );++ status = append_data( in, &out );++ if ( status==BIBL_OK ) output_reference( fp, &out );++ if ( p->format_opts & BIBL_FORMAT_VERBOSE )+ output_verbose( &out, "OUT", refnum );++ fields_free( &out );++ return status;+}++static void+nbibout_writeheader( FILE *outptr, param *p )+{+ if ( p->utf8bom ) utf8_writebom( outptr );+}
bibutils/nbibtypes.c view
@@ -29,8 +29,8 @@ { "AB", "ABSTRACT", SIMPLE, LEVEL_MAIN }, { "FAU", "AUTHOR", PERSON, LEVEL_MAIN }, { "AU", "", SKIP, LEVEL_MAIN },- { "AD", "", SKIP, LEVEL_MAIN },- { "LA", "", SKIP, LEVEL_MAIN },+ { "AD", "ADDRESS:AUTHOR", SIMPLE, LEVEL_MAIN },+ { "LA", "LANGUAGE", SIMPLE, LEVEL_MAIN }, { "GR", "", SKIP, LEVEL_MAIN }, { "DEP", "", SKIP, LEVEL_MAIN }, /* a date */ { "PL", "ADDRESS", SIMPLE, LEVEL_MAIN }, /* Publisher location */@@ -39,6 +39,7 @@ { "JID", "", SKIP, LEVEL_HOST }, /* Journal ID? */ { "SB", "", SKIP, LEVEL_MAIN }, { "MH", "KEYWORD", SIMPLE, LEVEL_MAIN },+ { "OT", "KEYWORD", SIMPLE, LEVEL_MAIN }, { "PMC", "PMC", SIMPLE, LEVEL_MAIN }, { "OID", "", SKIP, LEVEL_MAIN }, { "EDAT", "", SKIP, LEVEL_MAIN },
hs-bibutils.cabal view
@@ -1,5 +1,5 @@ name: hs-bibutils-version: 6.5.0.0+version: 6.6.0.0 homepage: https://github.com/wilx/hs-bibutils synopsis: Haskell bindings to bibutils, the bibliography@@ -46,8 +46,8 @@ bibutils/marc_auth.c bibutils/marc_auth.h bibutils/medin.c bibutils/modsin.c bibutils/modsout.c bibutils/modstypes.c bibutils/modstypes.h bibutils/name.c bibutils/name.h- bibutils/nbibin.c bibutils/nbibtypes.c bibutils/notes.c- bibutils/notes.h bibutils/pages.c bibutils/pages.h+ bibutils/nbibin.c bibutils/nbibout.c bibutils/nbibtypes.c+ bibutils/notes.c bibutils/notes.h bibutils/pages.c bibutils/pages.h bibutils/reftypes.c bibutils/reftypes.h bibutils/risin.c bibutils/risout.c bibutils/ristypes.c bibutils/serialno.c bibutils/serialno.h bibutils/slist.c bibutils/slist.h bibutils/str.c@@ -83,13 +83,13 @@ bibutils/is_ws.c bibutils/latex.c bibutils/marc_auth.c bibutils/medin.c bibutils/modsin.c bibutils/modsout.c bibutils/modstypes.c bibutils/name.c bibutils/nbibin.c- bibutils/nbibtypes.c bibutils/notes.c bibutils/pages.c- bibutils/reftypes.c bibutils/risin.c bibutils/risout.c- bibutils/ristypes.c bibutils/serialno.c bibutils/slist.c- bibutils/str.c bibutils/str_conv.c bibutils/strsearch.c- bibutils/title.c bibutils/unicode.c bibutils/url.c bibutils/utf8.c- bibutils/vplist.c bibutils/wordin.c bibutils/wordout.c bibutils/xml.c- bibutils/xml_encoding.c+ bibutils/nbibout.c bibutils/nbibtypes.c bibutils/notes.c+ bibutils/pages.c bibutils/reftypes.c bibutils/risin.c+ bibutils/risout.c bibutils/ristypes.c bibutils/serialno.c+ bibutils/slist.c bibutils/str.c bibutils/str_conv.c+ bibutils/strsearch.c bibutils/title.c bibutils/unicode.c+ bibutils/url.c bibutils/utf8.c bibutils/vplist.c bibutils/wordin.c+ bibutils/wordout.c bibutils/xml.c bibutils/xml_encoding.c if impl(ghc >= 6.10) build-depends: base >= 4, syb
src/Text/Bibutils.hsc view
@@ -93,6 +93,7 @@ , isi_out , word2007_out , adsab_out+ , nbib_out -- * Options for Specific Output Formats , FormatOpt@@ -425,6 +426,7 @@ , isi_out = BIBL_ISIOUT , word2007_out = BIBL_WORD2007OUT , adsab_out = BIBL_ADSABSOUT+ , nbib_out = BIBL_NBIBOUT } newtype FormatOpt = FormatOpt { unFormatOpt :: CInt }