/* * nbibout.c * * Copyright (c) Chris Putnam 2018-2020 * * Source code released under the GPL version 2 * */ #include #include #include #include #include "utf8.h" #include "str.h" #include "is_ws.h" #include "fields.h" #include "generic.h" #include "iso639_3.h" #include "title.h" #include "bibutils.h" #include "bibformats.h" /***************************************************** PUBLIC: int nbibout_initparams() *****************************************************/ static int nbibout_write( fields *info, FILE *fp, param *p, unsigned long refnum ); int nbibout_initparams( param *pm, const char *progname ) { pm->writeformat = BIBL_NBIBOUT; pm->format_opts = 0; pm->charsetout = BIBL_CHARSET_DEFAULT; pm->charsetout_src = BIBL_SRC_DEFAULT; pm->latexout = 0; pm->utf8out = BIBL_CHARSET_UTF8_DEFAULT; pm->utf8bom = BIBL_CHARSET_BOM_DEFAULT; pm->xmlout = BIBL_XMLOUT_FALSE; pm->nosplittitle = 0; pm->verbose = 0; pm->addcount = 0; pm->singlerefperfile = 0; if ( pm->charsetout == BIBL_CHARSET_UNICODE ) { pm->utf8out = pm->utf8bom = 1; } pm->headerf = generic_writeheader; pm->footerf = NULL; pm->writef = nbibout_write; if ( !pm->progname ) { if ( !progname ) pm->progname = NULL; else { pm->progname = strdup( progname ); if ( !pm->progname ) return BIBL_ERR_MEMERR; } } return BIBL_OK; } /***************************************************** PUBLIC: int 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; ilen < 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; in; ++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; }