/* * isiout.c * * Copyright (c) Chris Putnam 2008-2018 * * Source code released under the GPL version 2 * */ #include #include #include #include #include "utf8.h" #include "str.h" #include "strsearch.h" #include "fields.h" #include "title.h" #include "bibutils.h" #include "bibformats.h" static int isiout_write( fields *info, FILE *fp, param *p, unsigned long refnum ); static void isiout_writeheader( FILE *outptr, param *p ); void isiout_initparams( param *p, const char *progname ) { p->writeformat = BIBL_ISIOUT; 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 = isiout_writeheader; p->footerf = NULL; p->writef = isiout_write; } enum { TYPE_UNKNOWN = 0, TYPE_ARTICLE = 1, TYPE_INBOOK = 2, TYPE_BOOK = 3, }; static int get_type( fields *in ) { int type = TYPE_UNKNOWN, i, n, level; char *tag, *value; n = fields_num( in ); for ( i=0; i0 ) str_strcatc( &keywords, "; " ); str_strcat( &keywords, (str *) vplist_get( &kw, i ) ); } if ( str_memerr( &keywords ) ) { *status = BIBL_ERR_MEMERR; goto out; } fstatus = fields_add( out, "DE", str_cstr( &keywords ), LEVEL_MAIN ); if ( fstatus!=FIELDS_OK ) { *status = BIBL_ERR_MEMERR; goto out; } } out: vplist_free( &kw ); str_free( &keywords ); } static void process_person( str *person, char *name ) { str family, given, suffix; char *p = name; str_empty( person ); strs_init( &family, &given, &suffix, NULL ); while ( *p && *p!='|' ) str_addchar( &family, *p++ ); 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 ) ) str_strcatc( person, ", " ); str_strcat( person, &given ); } strs_free( &family, &given, &suffix, NULL ); } static void append_people( fields *f, char *tag, char *isitag, 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; in; ++i ) { fprintf( fp, "%s %s\n", ( char * ) fields_tag ( out, i, FIELDS_CHRP ), ( char * ) fields_value( out, i, FIELDS_CHRP ) ); } fprintf( fp, "ER\n\n" ); fflush( fp ); } static int isiout_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( fp, &out ); if ( p->format_opts & BIBL_FORMAT_VERBOSE ) output_verbose( &out, "OUT", refnum ); fields_free( &out ); return status; } static void isiout_writeheader( FILE *outptr, param *p ) { if ( p->utf8bom ) utf8_writebom( outptr ); }