/* output article number as pages if true pages aren't found */ static void output_articlenumber( FILE *fp, fields *info, unsigned long refnum, int format_opts ) { int ar = fields_find( info, "ARTICLENUMBER", -1 ); if ( ar!=-1 ) { newstr pages; newstr_init( &pages ); newstr_strcat( &pages, info->data[ar].data ); output_element( fp, "pages", pages.data, format_opts ); fields_setused( info, ar ); newstr_free( &pages ); } }
static void output_description( fields *f, FILE *outptr, int level ) { char *val; int n; n = fields_find( f, "DESCRIPTION", level ); if ( n!=-1 ) { val = ( char * ) fields_value( f, n, FIELDS_CHRP ); output_tag( outptr, lvl2indent(level), "physicalDescription", NULL, TAG_OPEN, TAG_NEWLINE, NULL ); output_tag( outptr, lvl2indent(incr_level(level,1)), "note", val, TAG_OPENCLOSE, TAG_NEWLINE, NULL ); output_tag( outptr, lvl2indent(level), "physicalDescription", NULL, TAG_CLOSE, TAG_NEWLINE, NULL ); } }
static void output_head( fields *f, FILE *outptr, int dropkey, unsigned long numrefs ) { int n; fprintf( outptr, "<mods"); if ( !dropkey ) { n = fields_find( f, "REFNUM", 0 ); if ( n!=-1 ) { fprintf( outptr, " ID=\""); output_refnum( f, n, outptr ); fprintf( outptr, "\""); } } fprintf( outptr, ">\n" ); }
static int medin_journal2( xml *node, fields *info ) { int fstatus, status = BIBL_OK; if ( xml_tagwithdata( node, "MedlineTA" ) && fields_find( info, "TITLE", 1 )==-1 ) { fstatus = fields_add( info, "TITLE", xml_data( node ), 1 ); if ( fstatus!=FIELDS_OK ) return BIBL_ERR_MEMERR; } if ( node->down ) { status = medin_journal2( node->down, info ); if ( status!=BIBL_OK ) return status; } if ( node->next ) status = medin_journal2( node->next, info ); return status; }
static int medin_journal2( xml *node, fields *info ) { int fstatus, status = BIBL_OK; if ( xml_tag_matches_has_value( node, "MedlineTA" ) && fields_find( info, "TITLE", LEVEL_HOST )==FIELDS_NOTFOUND ) { fstatus = fields_add( info, "TITLE", xml_value_cstr( node ), 1 ); if ( fstatus!=FIELDS_OK ) return BIBL_ERR_MEMERR; } if ( node->down ) { status = medin_journal2( node->down, info ); if ( status!=BIBL_OK ) return status; } if ( node->next ) status = medin_journal2( node->next, info ); return status; }
static void get_citekeys( bibl *b, list *citekeys ) { fields *info; int i, n; for ( i=0; i<b->nrefs; ++i ) { info = b->ref[i]; n = fields_find( info, "REFNUM", -1 ); if ( n==-1 ) n = generate_citekey( info, i ); if ( n!=-1 && info->data[n].data ) list_add( citekeys, info->data[n].data ); else list_add( citekeys, "" ); } }
/* output_resource() * * <typeOfResource>text</typeOfResource> */ static void output_resource( fields *f, FILE *outptr, int level ) { char *value; int n; n = fields_find( f, "RESOURCE", level ); if ( n!=-1 ) { value = fields_value( f, n, FIELDS_CHRP ); if ( marc_findresource( value )!=-1 ) { output_fil( outptr, lvl2indent(level), "typeOfResource", f, n, TAG_OPENCLOSE, TAG_NEWLINE, NULL ); } else { fprintf( stderr, "Illegal typeofResource = '%s'\n", value ); } } }
static int get_journalabbr( fields *f ) { char *jrnl; int n, j; n = fields_find( f, "TITLE", LEVEL_HOST ); if ( n!=-1 ) { jrnl = fields_value( f, n, FIELDS_CHRP ); for ( j=0; j<njournals; j++ ) { if ( !strcasecmp( jrnl, journals[j]+6 ) ) return j; } } return -1; }
static void bibl_checkrefid( bibl *b, param *p ) { fields *ref; long i; char buf[512]; int n; for ( i=0; i<b->nrefs; ++i ) { ref = b->ref[i]; n = fields_find( ref, "REFNUM", 0 ); if ( n==-1 ) n = build_refnum( ref, i+1 ); if ( p->addcount ) { sprintf( buf, "_%ld", i+1 ); newstr_strcat( &(ref->data[n]), buf ); } } }
static void output_sn( fields *f, FILE *outptr, int level ) { convert sn_types[] = { { "isbn", "ISBN", 0, 0 }, { "isbn", "ISBN13", 0, 0 }, { "lccn", "LCCN", 0, 0 }, { "issn", "ISSN", 0, 0 }, { "citekey", "REFNUM", 0, 0 }, { "doi", "DOI", 0, 0 }, { "eid", "EID", 0, 0 }, { "eprint", "EPRINT", 0, 0 }, { "eprinttype","EPRINTTYPE",0, 0 }, { "pubmed", "PMID", 0, 0 }, { "medline", "MEDLINE", 0, 0 }, { "pii", "PII", 0, 0 }, { "arXiv", "ARXIV", 0, 0 }, { "isi", "ISIREFNUM", 0, 0 }, { "accessnum", "ACCESSNUM", 0, 0 }, { "jstor", "JSTOR", 0, 0 }, { "isrn", "ISRN", 0, 0 }, }; int ntypes = sizeof( sn_types ) / sizeof( sn_types[0] ); int i, n; /* output call number */ n = fields_find( f, "CALLNUMBER", level ); output_fil( outptr, lvl2indent(level), "classification", f, n, TAG_OPENCLOSE, TAG_NEWLINE, NULL ); /* output specialized serialnumber */ convert_findallfields( f, sn_types, ntypes, level ); for ( i=0; i<ntypes; ++i ) { if ( sn_types[i].pos==-1 ) continue; output_fil( outptr, lvl2indent(level), "identifier", f, sn_types[i].pos, TAG_OPENCLOSE, TAG_NEWLINE, "type", sn_types[i].mods, NULL ); } /* output _all_ elements of type SERIALNUMBER */ n = fields_num( f ); for ( i=0; i<n; ++i ) { if ( f->level[i]!=level ) continue; if ( strcasecmp( f->tag[i].data, "SERIALNUMBER" ) ) continue; output_fil( outptr, lvl2indent(level), "identifier", f, i, TAG_OPENCLOSE, TAG_NEWLINE, "type", "serial number", NULL ); } }
/* Endnote defaults if no %0 * * if %J & %V - journal article * if %B - book section * if %R & !%T - report * if %I & !%B & !%J & !%R - book * if !%B & !%J & !%R & !%I - journal article */ int endin_typef( fields *endin, char *filename, int nrefs, param *p, variants *all, int nall ) { char *refnum = ""; int n, reftype, nrefnum, nj, nv, nb, nr, nt, ni; n = fields_find( endin, "%0", 0 ); nrefnum = fields_find( endin, "%F", 0 ); if ( nrefnum!=-1 ) refnum = endin->data[nrefnum].data; if ( n!=-1 ) reftype = get_reftype( endin->data[n].data, nrefs, p->progname, all, nall, refnum ); else { nj = fields_find( endin, "%J", 0 ); nv = fields_find( endin, "%V", 0 ); nb = fields_find( endin, "%B", 0 ); nr = fields_find( endin, "%R", 0 ); nt = fields_find( endin, "%T", 0 ); ni = fields_find( endin, "%I", 0 ); if ( nj!=-1 && nv!=-1 ) { reftype = get_reftype( "Journal Article", nrefs, p->progname, all, nall, refnum ); } else if ( nb!=-1 ) { reftype = get_reftype( "Book Section", nrefs, p->progname, all, nall, refnum ); } else if ( nr!=-1 && nt==-1 ) { reftype = get_reftype( "Report", nrefs, p->progname, all, nall, refnum ); } else if ( ni!=-1 && nb==-1 && nj==-1 && nr==-1 ) { reftype = get_reftype( "Book", nrefs, p->progname, all, nall, refnum ); } else if ( nb==-1 && nj==-1 && nr==-1 && ni==-1 ) { reftype = get_reftype( "Journal Article", nrefs, p->progname, all, nall, refnum ); } else { reftype = get_reftype( "", nrefs, p->progname, all, nall, refnum ); /* default */ } } return reftype; }
static void output_citekey( FILE *fp, fields *info, unsigned long refnum, int format_opts ) { int n = fields_find( info, "REFNUM", -1 ); char *p; if ( n!=-1 ) { p = info->data[n].data; while ( p && *p && *p!='|' ) { if ( format_opts & BIBOUT_STRICTKEY ) { if ( isdigit((unsigned char)*p) || (*p>='A' && *p<='Z') || (*p>='a' && *p<='z' ) ) fprintf( fp, "%c", *p ); } else { if ( *p!=' ' && *p!='\t' ) { fprintf( fp, "%c", *p ); } } p++; } } }
static int bibtexin_crossref( bibl *bin, param *p ) { int i, n, ncross, status = BIBL_OK; fields *bibref, *bibcross; for ( i=0; i<bin->nrefs; ++i ) { bibref = bin->ref[i]; n = fields_find( bibref, "CROSSREF", -1 ); if ( n==-1 ) continue; fields_setused( bibref, n ); ncross = bibtexin_findref( bin, (char*) fields_value( bibref, n, FIELDS_CHRP ) ); if ( ncross==-1 ) { bibtexin_nocrossref( bin, i, n, p ); continue; } bibcross = bin->ref[ncross]; status = bibtexin_crossref_oneref( bibref, bibcross ); if ( status!=BIBL_OK ) goto out; } out: return status; }
static int bibtexout_type( fields *info, char *filename, int refnum, param *p ) { char *genre; int type = TYPE_UNKNOWN, i, maxlevel, n, level; /* determine bibliography type */ for ( i=0; i<info->nfields; ++i ) { if ( strcasecmp( info->tag[i].data, "GENRE" ) && strcasecmp( info->tag[i].data, "NGENRE" ) ) continue; genre = info->data[i].data; level = info->level[i]; if ( !strcasecmp( genre, "periodical" ) || !strcasecmp( genre, "academic journal" ) || !strcasecmp( genre, "magazine" ) || !strcasecmp( genre, "newspaper" ) || !strcasecmp( genre, "article" ) ) type = TYPE_ARTICLE; else if ( !strcasecmp( genre, "instruction" ) ) type = TYPE_MANUAL; else if ( !strcasecmp( genre, "unpublished" ) ) type = TYPE_UNPUBLISHED; else if ( !strcasecmp( genre, "conference publication" ) ) { if ( level==0 ) type=TYPE_PROCEEDINGS; else type = TYPE_INPROCEEDINGS; } else if ( !strcasecmp( genre, "collection" ) ) { if ( level==0 ) type=TYPE_COLLECTION; else type = TYPE_INCOLLECTION; } else if ( !strcasecmp( genre, "report" ) ) type = TYPE_REPORT; else if ( !strcasecmp( genre, "book" ) ) { if ( level==0 ) type=TYPE_BOOK; else type=TYPE_INBOOK; } else if ( !strcasecmp( genre, "thesis" ) ) { if ( type==TYPE_UNKNOWN ) type=TYPE_PHDTHESIS; } else if ( !strcasecmp( genre, "Ph.D. thesis" ) ) type = TYPE_PHDTHESIS; else if ( !strcasecmp( genre, "Masters thesis" ) ) type = TYPE_MASTERSTHESIS; else if ( !strcasecmp( genre, "electronic" ) ) type = TYPE_ELECTRONIC; } if ( type==TYPE_UNKNOWN ) { for ( i=0; i<info->nfields; ++i ) { if ( strcasecmp( info->tag[i].data, "ISSUANCE" ) ) continue; if ( !strcasecmp( info->data[i].data, "monographic" ) ) { if ( info->level[i]==0 ) type = TYPE_BOOK; else if ( info->level[i]==1 ) type=TYPE_INBOOK; } } } /* default to BOOK type */ if ( type==TYPE_UNKNOWN ) { maxlevel = fields_maxlevel( info ); if ( maxlevel > 0 ) type = TYPE_INBOOK; else { if ( p->progname ) fprintf( stderr, "%s: ", p->progname ); fprintf( stderr, "Cannot identify TYPE " "in reference %d ", refnum+1 ); n = fields_find( info, "REFNUM", -1 ); if ( n!=-1 ) fprintf( stderr, " %s", info->data[n].data); fprintf( stderr, " (defaulting to @Misc)\n" ); type = TYPE_MISC; } } return type; }
static int get_type( fields *info, param *p, unsigned long refnum ) { /* Comment out TYPE_GENERIC entries as that is default, but * keep in source as record of mapping decision. */ match_type match_genres[] = { /* MARC Authority elements */ { "art original", TYPE_ARTWORK }, { "art reproduction", TYPE_ARTWORK }, { "article", TYPE_ARTICLE }, { "atlas", TYPE_MAP }, { "autobiography", TYPE_BOOK }, /* { "bibliography", TYPE_GENERIC },*/ { "biography", TYPE_BOOK }, { "book", TYPE_BOOK }, /* { "calendar", TYPE_GENERIC },*/ /* { "catalog", TYPE_GENERIC },*/ { "chart", TYPE_CHARTTABLE }, /* { "comic or graphic novel", TYPE_GENERIC },*/ /* { "comic strip", TYPE_GENERIC },*/ { "conference publication", TYPE_PROCEEDINGS }, { "database", TYPE_ONLINEDATABASE }, /* { "dictionary", TYPE_GENERIC },*/ { "diorama", TYPE_ARTWORK }, /* { "directory", TYPE_GENERIC },*/ { "discography", TYPE_AUDIOVISUAL }, /* { "drama", TYPE_GENERIC },*/ { "encyclopedia", TYPE_BOOK }, /* { "essay", TYPE_GENERIC }, */ /* { "festschrift", TYPE_GENERIC },*/ { "fiction", TYPE_BOOK }, { "filmography", TYPE_FILMBROADCAST }, { "filmstrip", TYPE_FILMBROADCAST }, /* { "finding aid", TYPE_GENERIC },*/ /* { "flash card", TYPE_GENERIC },*/ { "folktale", TYPE_CLASSICALWORK }, { "font", TYPE_ELECTRONIC }, /* { "game", TYPE_GENERIC },*/ { "government publication", TYPE_GOVERNMENT }, { "graphic", TYPE_FIGURE }, { "globe", TYPE_MAP }, /* { "handbook", TYPE_GENERIC },*/ { "history", TYPE_BOOK }, { "hymnal", TYPE_BOOK }, /* { "humor, satire", TYPE_GENERIC },*/ /* { "index", TYPE_GENERIC },*/ /* { "instruction", TYPE_GENERIC },*/ /* { "interview", TYPE_GENERIC },*/ { "issue", TYPE_ARTICLE }, { "journal", TYPE_ARTICLE }, /* { "kit", TYPE_GENERIC },*/ /* { "language instruction", TYPE_GENERIC },*/ /* { "law report or digest", TYPE_GENERIC },*/ /* { "legal article", TYPE_GENERIC },*/ { "legal case and case notes", TYPE_CASE }, { "legislation", TYPE_BILL }, { "letter", TYPE_COMMUNICATION }, { "loose-leaf", TYPE_GENERIC }, { "map", TYPE_MAP }, /* { "memoir", TYPE_GENERIC },*/ /* { "microscope slide", TYPE_GENERIC },*/ /* { "model", TYPE_GENERIC },*/ { "motion picture", TYPE_AUDIOVISUAL }, { "multivolume monograph", TYPE_BOOK }, { "newspaper", TYPE_NEWSARTICLE }, { "novel", TYPE_BOOK }, /* { "numeric data", TYPE_GENERIC },*/ /* { "offprint", TYPE_GENERIC },*/ { "online system or service", TYPE_ELECTRONIC }, { "patent", TYPE_PATENT }, { "periodical", TYPE_MAGARTICLE }, { "picture", TYPE_ARTWORK }, /* { "poetry", TYPE_GENERIC },*/ { "programmed text", TYPE_PROGRAM }, /* { "realia", TYPE_GENERIC },*/ { "rehearsal", TYPE_AUDIOVISUAL }, /* { "remote sensing image", TYPE_GENERIC },*/ /* { "reporting", TYPE_GENERIC },*/ /* { "review", TYPE_GENERIC },*/ /* { "script", TYPE_GENERIC },*/ /* { "series", TYPE_GENERIC },*/ /* { "short story", TYPE_GENERIC },*/ /* { "slide", TYPE_GENERIC },*/ { "sound", TYPE_AUDIOVISUAL }, /* { "speech", TYPE_GENERIC },*/ /* { "standard or specification", TYPE_GENERIC },*/ /* { "statistics", TYPE_GENERIC },*/ /* { "survey of literature", TYPE_GENERIC },*/ { "technical drawing", TYPE_ARTWORK }, { "techincal report", TYPE_REPORT }, { "thesis", TYPE_THESIS }, /* { "toy", TYPE_GENERIC },*/ /* { "transparency", TYPE_GENERIC },*/ /* { "treaty", TYPE_GENERIC },*/ { "videorecording", TYPE_AUDIOVISUAL }, { "web site", TYPE_ELECTRONIC }, /* Non-MARC Authority elements */ { "academic journal", TYPE_ARTICLE }, { "magazine", TYPE_MAGARTICLE }, { "hearing", TYPE_HEARING }, { "Ph.D. thesis", TYPE_PHDTHESIS }, { "Masters thesis", TYPE_MASTERSTHESIS }, { "Diploma thesis", TYPE_DIPLOMATHESIS }, { "Doctoral thesis", TYPE_DOCTORALTHESIS }, { "Habilitation thesis", TYPE_HABILITATIONTHESIS }, { "communication", TYPE_COMMUNICATION }, { "manuscript", TYPE_MANUSCRIPT }, { "report", TYPE_REPORT }, { "unpublished", TYPE_UNPUBLISHED }, }; int nmatch_genres = sizeof( match_genres ) / sizeof( match_genres[0] ); int i, j, n, maxlevel, type = TYPE_UNKNOWN; char *tag, *data; /* Determine type from genre information */ for ( i=0; i<info->n; ++i ) { tag = info->tag[i].data; if ( strcasecmp( tag, "GENRE" )!=0 && strcasecmp( tag, "NGENRE" )!=0 ) continue; data = info->data[i].data; for ( j=0; j<nmatch_genres; ++j ) { if ( !strcasecmp( data, match_genres[j].name ) ) { type = match_genres[j].type; fields_setused( info, i ); } } if ( p->verbose ) { if ( p->progname ) fprintf( stderr, "%s: ", p->progname ); fprintf( stderr, "Type from tag '%s' data '%s': ", info->tag[i].data, info->data[i].data ); write_type( stderr, type ); fprintf( stderr, "\n" ); } if ( type==TYPE_UNKNOWN ) { if ( !strcasecmp( data, "periodical" ) ) type = TYPE_ARTICLE; else if ( !strcasecmp( data, "thesis" ) ) type = TYPE_THESIS; else if ( !strcasecmp( data, "book" ) ) { if ( info->level[i]==0 ) type = TYPE_BOOK; else type = TYPE_INBOOK; } else if ( !strcasecmp( data, "collection" ) ) { if ( info->level[i]==0 ) type = TYPE_BOOK; else type = TYPE_INBOOK; } if ( type!=TYPE_UNKNOWN ) fields_setused( info, i ); } /* the inbook type should be defined if 'book' in host */ if ( type==TYPE_BOOK && info->level[i]>0 ) type = TYPE_INBOOK; } if ( p->verbose ) { if ( p->progname ) fprintf( stderr, "%s: ", p->progname ); fprintf( stderr, "Type from genre element: " ); write_type( stderr, type ); fprintf( stderr, "\n" ); } /* Determine from resource information */ if ( type==TYPE_UNKNOWN ) { for ( i=0; i<info->n; ++i ) { if ( strcasecmp( info->tag[i].data, "RESOURCE" ) ) continue; data = info->data[i].data; if ( !strcasecmp( data, "moving image" ) ) type = TYPE_FILMBROADCAST; else if ( !strcasecmp( data, "software, multimedia" ) ) type = TYPE_PROGRAM; if ( type!=TYPE_UNKNOWN ) fields_setused( info, i ); } if ( p->verbose ) { if ( p->progname ) fprintf( stderr, "%s: ", p->progname ); fprintf( stderr, "Type from resource element: " ); write_type( stderr, type ); fprintf( stderr, "\n" ); } } /* Determine from issuance information */ if ( type==TYPE_UNKNOWN ) { for ( i=0; i<info->n; ++i ) { if ( strcasecmp( info->tag[i].data, "ISSUANCE" ) ) continue; data = info->data[i].data; if ( !strcasecmp( data, "monographic" ) ) { if ( info->level[i]==0 ) type = TYPE_BOOK; else type = TYPE_INBOOK; } } if ( p->verbose ) { if ( p->progname ) fprintf( stderr, "%s: ", p->progname ); fprintf( stderr, "Type from issuance element: " ); write_type( stderr, type ); fprintf( stderr, "\n" ); } } /* default to generic or book chapter, depending on maxlevel */ if ( type==TYPE_UNKNOWN ) { maxlevel = fields_maxlevel( info ); if ( maxlevel > 0 ) type = TYPE_INBOOK; else { if ( p->progname ) fprintf( stderr, "%s: ", p->progname ); fprintf( stderr, "Cannot identify TYPE in reference %lu ", refnum+1 ); n = fields_find( info, "REFNUM", -1 ); if ( n!=-1 ) fprintf( stderr, " %s", info->data[n].data ); fprintf( stderr, " (defaulting to generic)\n" ); type = TYPE_GENERIC; } } if ( p->verbose ) { if ( p->progname ) fprintf( stderr, "%s: ", p->progname ); fprintf( stderr, "Final type: " ); write_type( stderr, type ); fprintf( stderr, "\n" ); } return type; }