/* * risout.c * * Copyright (c) Chris Putnam 2003-2012 * * Program and source code released under the GPL * */ #include #include #include #include #include "utf8.h" #include "newstr.h" #include "strsearch.h" #include "fields.h" #include "doi.h" #include "risout.h" void risout_initparams( param *p, const char *progname ) { p->writeformat = BIBL_RISOUT; p->format_opts = 0; p->charsetout = BIBL_CHARSET_DEFAULT; p->charsetout_src = BIBL_SRC_DEFAULT; p->latexout = 0; p->utf8out = 0; p->utf8bom = 0; p->xmlout = 0; 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 = risout_writeheader; p->footerf = NULL; p->writef = risout_write; } enum { TYPE_UNKNOWN, TYPE_STD, /* standard/generic */ TYPE_ABSTRACT, /* abstract */ TYPE_ARTICLE, /* article */ TYPE_BOOK, /* book */ TYPE_CASE, /* case */ TYPE_INBOOK, /* chapter */ TYPE_CONF, /* conference */ TYPE_ELEC, /* electronic */ TYPE_HEAR, /* hearing */ TYPE_MAGARTICLE, /* magazine article */ TYPE_NEWS, /* newspaper */ TYPE_MPCT, /* mpct */ TYPE_PAMP, /* pamphlet */ TYPE_PATENT, /* patent */ TYPE_PCOMM, /* personal communication */ TYPE_PROGRAM, /* program */ TYPE_REPORT, /* report */ TYPE_STATUTE, /* statute */ TYPE_THESIS, /* thesis */ TYPE_MASTERSTHESIS, /* thesis */ TYPE_PHDTHESIS, /* thesis */ TYPE_DIPLOMATHESIS, /* thesis */ TYPE_DOCTORALTHESIS, /* thesis */ TYPE_HABILITATIONTHESIS, /* thesis */ TYPE_UNPUBLISHED, /* unpublished */ }; typedef struct match_type { char *name; int type; } match_type; /* Try to determine type of reference from * */ static int get_type_genre( fields *f ) { match_type match_genres[] = { { "academic journal", TYPE_ARTICLE }, { "journal article", TYPE_ARTICLE }, { "magazine", TYPE_MAGARTICLE }, { "conference publication", TYPE_CONF }, { "newspaper", TYPE_NEWS }, { "legislation", TYPE_STATUTE }, { "communication", TYPE_PCOMM }, { "hearing", TYPE_HEAR }, { "electronic", TYPE_ELEC }, { "legal case and case notes", TYPE_CASE }, { "book chapter", TYPE_INBOOK }, { "Ph.D. thesis", TYPE_PHDTHESIS }, { "Masters thesis", TYPE_MASTERSTHESIS }, { "Diploma thesis", TYPE_DIPLOMATHESIS }, { "Doctoral thesis", TYPE_DOCTORALTHESIS }, { "Habilitation thesis", TYPE_HABILITATIONTHESIS }, { "report", TYPE_REPORT }, { "abstract or summary", TYPE_ABSTRACT }, { "patent", TYPE_PATENT }, { "unpublished", TYPE_UNPUBLISHED }, }; int nmatch_genres = sizeof( match_genres ) / sizeof( match_genres[0] ); int type, i, j; char *value; type = TYPE_UNKNOWN; for ( i=0; i */ static int get_type_resource( fields *f ) { match_type match_res[] = { { "software, multimedia", TYPE_PROGRAM }, }; int nmatch_res = sizeof( match_res ) / sizeof( match_res[0] ); int type, i, j; char *value; vplist a; type = TYPE_UNKNOWN; vplist_init( &a ); fields_findv_each( f, LEVEL_ANY, FIELDS_CHRP, &a, "RESOURCE" ); for ( i=0; i and */ /* */ static int get_type_issuance( fields *f ) { int type = TYPE_UNKNOWN; int i, monographic = 0, text = 0, monographic_level = 0; for ( i=0; in; ++i ) { if ( !strcasecmp( f->tag[i].data, "issuance" ) && !strcasecmp( f->data[i].data, "MONOGRAPHIC" ) ){ monographic = 1; monographic_level = f->level[i]; } if ( !strcasecmp( f->tag[i].data, "typeOfResource" ) && !strcasecmp( f->data[i].data,"text") ) { text = 1; } } if ( monographic && text ) { if ( monographic_level==0 ) type=TYPE_BOOK; else if ( monographic_level>0 ) type=TYPE_INBOOK; } return type; } static int get_type( fields *f ) { int type; type = get_type_genre( f ); if ( type==TYPE_UNKNOWN ) type = get_type_resource( f ); if ( type==TYPE_UNKNOWN ) type = get_type_issuance( f ); if ( type==TYPE_UNKNOWN ) type = TYPE_STD; return type; } static void output_type( FILE *fp, int type, param *p ) { match_type tyout[] = { { "STD", TYPE_STD }, { "ABST", TYPE_ABSTRACT }, { "JOUR", TYPE_ARTICLE }, { "BOOK", TYPE_BOOK }, { "CASE", TYPE_CASE }, { "CHAP", TYPE_INBOOK }, { "CONF", TYPE_CONF }, { "ELEC", TYPE_ELEC }, { "HEAR", TYPE_HEAR }, { "MGZN", TYPE_MAGARTICLE }, { "NEWS", TYPE_NEWS }, { "MPCT", TYPE_MPCT }, { "PAMP", TYPE_PAMP }, { "PAT", TYPE_PATENT }, { "PCOMM",TYPE_PCOMM }, { "COMP", TYPE_PROGRAM }, { "RPRT", TYPE_REPORT }, { "STAT", TYPE_STATUTE }, { "THES", TYPE_THESIS }, { "THES", TYPE_MASTERSTHESIS }, { "THES", TYPE_PHDTHESIS }, { "THES", TYPE_DIPLOMATHESIS }, { "THES", TYPE_DOCTORALTHESIS }, { "THES", TYPE_HABILITATIONTHESIS }, { "UNPB", TYPE_UNPUBLISHED } }; int ntyout = sizeof( tyout ) / sizeof( tyout[0] ); int i, found; fprintf( fp, "TY - " ); found = 0; for ( i=0; iprogname ) fprintf( stderr, "%s: ", p->progname ); fprintf( stderr, "Internal Error: Cannot identify type %d\n", type ); fprintf( fp, "STD" ); } fprintf( fp, "\n" ); } static void output_person ( FILE *fp, char *p ) { int nseps = 0, nch; while ( *p ) { nch = 0; if ( nseps==1 ) fprintf( fp, "," ); if ( nseps ) fprintf( fp, " " ); while ( *p && *p!='|' ) { fprintf( fp, "%c", *p++ ); nch++; } if ( *p=='|' ) p++; if ( nseps!=0 && nch==1 ) fprintf( fp, "." ); nseps++; } } static void output_people( FILE *fp, fields *f, char *tag, char *ristag, int level ) { vplist people; int i; vplist_init( &people ); fields_findv_each( f, level, FIELDS_CHRP, &people, tag ); for ( i=0; idata ); if ( subttl ) { if ( mainttl->len > 0 && mainttl->data[ mainttl->len - 1 ]!='?' ) fprintf( fp, ":" ); fprintf( fp, " %s", subttl->data ); } fprintf( fp, "\n" ); } static void output_title( FILE *fp, fields *f, char *ristag, int level ) { output_titlecore( fp, f, ristag, level, "TITLE", "SUBTITLE" ); } static void output_abbrtitle( FILE *fp, fields *f, char *ristag, int level ) { output_titlecore( fp, f, ristag, level, "SHORTTITLE", "SHORTSUBTITLE" ); } static void output_pages( FILE *fp, fields *f ) { char *sn = fields_findv( f, LEVEL_ANY, FIELDS_CHRP, "PAGESTART" ); char *en = fields_findv( f, LEVEL_ANY, FIELDS_CHRP, "PAGEEND" ); char *ar; if ( sn || en ) { if ( sn ) fprintf( fp, "SP - %s\n", sn ); if ( en ) fprintf( fp, "EP - %s\n", en ); } else { ar = fields_findv( f, LEVEL_ANY, FIELDS_CHRP, "ARTICLENUMBER" ); if ( ar ) fprintf( fp, "SP - %s\n", ar ); } } static void output_keywords( FILE *fp, fields *f ) { vplist vpl; int i; vplist_init( &vpl ); fields_findv_each( f, LEVEL_ANY, FIELDS_CHRP, &vpl, "KEYWORD" ); for ( i=0; iutf8bom ) utf8_writebom( outptr ); }