/* * nbibout.c * * Copyright (c) Chris Putnam 2018 * * Source code released under the GPL version 2 * */ #include #include #include #include #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; 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; } static void nbibout_writeheader( FILE *outptr, param *p ) { if ( p->utf8bom ) utf8_writebom( outptr ); }