static int get_type( fields *f ) { int type = TYPE_UNKNOWN, i, n, level; char *tag, *value; n = fields_num( f ); for ( i=0; i<n; ++i ) { tag = fields_tag( f, i, FIELDS_CHRP ); if ( strcasecmp( tag, "GENRE" ) && strcasecmp( tag, "NGENRE") ) continue; value = fields_value( f, i, FIELDS_CHRP ); level = fields_level( f, i ); if ( !strcasecmp( value, "periodical" ) || !strcasecmp( value, "academic journal" ) || !strcasecmp( value, "journal article" ) ) { type = TYPE_ARTICLE; } else if ( !strcasecmp( value, "book" ) ) { if ( level==0 ) type=TYPE_BOOK; else type=TYPE_INBOOK; } else if ( !strcasecmp( value, "book chapter" ) ) { type = TYPE_INBOOK; } } return type; }
int copacin_convertf( fields *copacin, fields *out, int reftype, param *p, variants *all, int nall ) { int process, level, i, n, nfields, ok, status = BIBL_OK; newstr *tag, *data; char *newtag; nfields = fields_num( copacin ); for ( i=0; i<nfields; ++i ) { tag = fields_tag( copacin, i, FIELDS_STRP ); n = translate_oldtag( tag->data, reftype, all, nall, &process, &level, &newtag ); if ( n==-1 ) { copacin_report_notag( p, tag->data ); continue; } if ( process == ALWAYS ) continue; /*add these later*/ data = fields_value( copacin, i, FIELDS_STRP ); switch ( process ) { case SIMPLE: status = copacin_simple( out, newtag, data->data, level ); break; case TITLE: ok = title_process( out, newtag, data->data, level, p->nosplittitle ); if ( ok ) status = BIBL_OK; else status = BIBL_ERR_MEMERR; break; case PERSON: status = copacin_addname( out, newtag, data, level, &(p->asis), &(p->corps) ); break; case SERIALNO: ok = addsn( out, data->data, level ); if ( ok ) status = BIBL_OK; else status = BIBL_ERR_MEMERR; break; default: fprintf(stderr,"%s: internal error -- " "illegal process value %d\n", p->progname, process ); status = BIBL_OK; break; } if ( status!=BIBL_OK ) return status; } return status; }
static int bibtexin_cleanref( fields *bibin, param *p ) { int i, n, status; newstr *t, *d; n = fields_num( bibin ); for ( i=0; i<n; ++i ) { t = fields_tag( bibin, i, FIELDS_STRP_NOUSE ); d = fields_value( bibin, i, FIELDS_STRP_NOUSE ); status = bibtex_cleandata( t, d, bibin, p ); if ( status!=BIBL_OK ) return status; } return BIBL_OK; }
static int url_exists( fields *f, char *urltag, newstr *doi_url ) { int i, n; if ( urltag ) { n = fields_num( f ); for ( i=0; i<n; ++i ) { if ( strcmp( fields_tag( f, i, FIELDS_CHRP ), urltag ) ) continue; if ( strcmp( fields_value( f, i, FIELDS_CHRP ), doi_url->data ) ) continue; return 1; } } return 0; }
static void output_verbose( fields *f, unsigned long refnum ) { char *tag, *value; int i, n, level; fprintf( stderr, "REF #%lu----\n", refnum+1 ); n = fields_num( f ); for ( i=0; i<n; ++i ) { tag = fields_tag( f, i, FIELDS_CHRP_NOUSE ); value = fields_value( f, i, FIELDS_CHRP_NOUSE ); level = fields_level( f, i ); fprintf( stderr, "\t'%s'\t'%s'\t%d\n", tag, value, level ); } }
static void output_people( FILE *fp, fields *info, char *tag, char *entag, int level ) { newstr oneperson; int i, n, flvl; char *ftag; newstr_init( &oneperson ); n = fields_num( info ); for ( i=0; i<n; ++i ) { flvl = fields_level( info, i ); if ( level!=LEVEL_ANY && flvl!=level ) continue; ftag = fields_tag( info, i, FIELDS_CHRP ); if ( !strcasecmp( ftag, tag ) ) { name_build_withcomma( &oneperson, fields_value( info, i, FIELDS_CHRP ) ); fprintf( fp, "%s %s\n", entag, oneperson.data ); } } newstr_free( &oneperson ); }
static void output_thesisdetails( fields *info, FILE *outptr, int type ) { char *tag; int i, n; if ( type==TYPE_PHDTHESIS ) output_fixed( outptr, "b:ThesisType", "Ph.D. Thesis", 0 ); else if ( type==TYPE_MASTERSTHESIS ) output_fixed( outptr, "b:ThesisType", "Masters Thesis", 0 ); n = fields_num( info ); for ( i=0; i<n; ++i ) { tag = fields_tag( info, i, FIELDS_CHRP ); if ( strcasecmp( tag, "DEGREEGRANTOR" ) && strcasecmp( tag, "DEGREEGRANTOR:ASIS") & strcasecmp( tag, "DEGREEGRANTOR:CORP")) continue; output_item( info, outptr, "b:Institution", "", i, 0 ); } }
/* look for thesis-type hint */ static int risin_thesis_hints( fields *bibin, int reftype, param *p, fields *bibout ) { int i, nfields, fstatus; char *tag, *value; if ( strcasecmp( p->all[reftype].type, "THES" ) ) return BIBL_OK; nfields = fields_num( bibin ); for ( i=0; i<nfields; ++i ) { tag = fields_tag( bibin, i, FIELDS_CHRP ); if ( strcasecmp( tag, "U1" ) ) continue; value = fields_value( bibin, i, FIELDS_CHRP ); if ( !strcasecmp(value,"Ph.D. Thesis")|| !strcasecmp(value,"Masters Thesis")|| !strcasecmp(value,"Diploma Thesis")|| !strcasecmp(value,"Doctoral Thesis")|| !strcasecmp(value,"Habilitation Thesis")) { fstatus = fields_add( bibout, "GENRE", value, 0 ); if ( fstatus!=FIELDS_OK ) return BIBL_ERR_MEMERR; } } return BIBL_OK; }
int bibtexin_convertf( fields *bibin, fields *info, int reftype, param *p, variants *all, int nall ) { int process, level, i, n, nfields, status; newstr *t, *d; char *outtag; nfields = fields_num( bibin ); for ( i=0; i<nfields; ++i ) { if ( fields_used( bibin, i ) ) continue; /* e.g. successful crossref */ if ( fields_nodata( bibin, i ) ) continue; t = fields_tag( bibin, i, FIELDS_STRP ); if ( t->len == 0 ) continue; /* Don't consider with null tags */ n = process_findoldtag( t->data, reftype, all, nall ); if ( n==-1 ) { bibtexin_notag( p, t->data ); continue; } d = fields_value( bibin, i, FIELDS_STRP ); process = ((all[reftype]).tags[n]).processingtype; level = ((all[reftype]).tags[n]).level; outtag = ((all[reftype]).tags[n]).newstr; switch( process ) { case SIMPLE: status = bibtex_simple( info, outtag, d, level ); break; case TITLE: status = bibtexin_title_process( info, "TITLE", bibin, t, d, level, p->nosplittitle ); break; case PERSON: status = bibtex_names( info, outtag, d, level, &(p->asis), &(p->corps) ); break; case PAGES: status = process_pages( info, d, level ); break; case KEYWORD: status = process_keywords( info, d, level ); break; case HOWPUBLISHED: status = process_howpublished( info, d, level ); break; case LINKEDFILE: status = process_file( info, d, level ); break; case BT_NOTE: status = process_note( info, d, level ); break; case BT_SENTE: status = process_sente( info, d, level ); break; case BT_URL: status = process_url( info, d, level ); break; case BT_ORG: status = process_organization( bibin, info, d, level ); break; default: status = BIBL_OK; break; } if ( status!=BIBL_OK ) return status; } return status; }
/* Try to determine type of reference from * <genre></genre> */ static int get_type_genre( fields *f, param *p ) { match_type match_genres[] = { { "academic journal", TYPE_ARTICLE }, { "article", 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 }, { "map", TYPE_MAP }, }; int nmatch_genres = sizeof( match_genres ) / sizeof( match_genres[0] ); int type, i, j; char *tag, *value; type = TYPE_UNKNOWN; for ( i=0; i<fields_num( f ); ++i ) { if ( !fields_match_tag( f, i, "GENRE" ) && !fields_match_tag( f, i, "NGENRE" ) ) continue; value = ( char * ) fields_value( f, i, FIELDS_CHRP ); for ( j=0; j<nmatch_genres; ++j ) if ( !strcasecmp( match_genres[j].name, value ) ) type = match_genres[j].type; if ( p->verbose ) { tag = ( char * ) fields_tag( f, i, FIELDS_CHRP ); if ( p->progname ) fprintf( stderr, "%s: ", p->progname ); fprintf( stderr, "Type from tag '%s' data '%s': ", tag, value ); write_type( stderr, type ); fprintf( stderr, "\n" ); } if ( type==TYPE_UNKNOWN ) { if ( !strcasecmp( value, "periodical" ) ) type = TYPE_ARTICLE; else if ( !strcasecmp( value, "thesis" ) ) type = TYPE_THESIS; else if ( !strcasecmp( value, "book" ) ) { if ( fields_level( f, i )==0 ) type=TYPE_BOOK; else type=TYPE_INBOOK; } else if ( !strcasecmp( value, "collection" ) ) { if ( fields_level( f, i )==0 ) type=TYPE_BOOK; else 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" ); } return type; }
int endin_convertf( fields *endin, fields *info, int reftype, param *p, variants *all, int nall ) { int i, level, n, process, nfields, ok; char *newtag, *t; newstr *d; nfields = fields_num( endin ); for ( i=0; i<nfields; ++i ) { /* Ensure that data exists */ d = fields_value( endin, i, FIELDS_STRP_NOUSE ); if ( d->len == 0 ) { fields_setused( endin, i ); continue; } /* * All refer format tags start with '%'. If we have one * that doesn't, assume that it comes from endx2xml * and just copy and paste to output */ t = fields_tag( endin, i, FIELDS_CHRP ); if ( t[0]!='%' ) { fields_add( info, t, d->data, endin->level[i] ); continue; } n = translate_oldtag( t, reftype, all, nall, &process, &level, &newtag ); if ( n==-1 ) { endin_notag( p, t, d->data ); continue; } if ( process == ALWAYS ) continue; /* add these later */ fields_setused( endin, i ); switch ( process ) { case SIMPLE: ok = fields_add( info, newtag, d->data, level ); break; case TYPE: ok = endin_addtype( info, d->data, level ); break; case TITLE: ok = title_process( info, newtag, d->data, level, p->nosplittitle ); break; case PERSON: ok = name_add( info, newtag, d->data, level, &(p->asis), &(p->corps) ); break; case DATE: ok = endin_adddate( info, t, newtag,d->data,level); break; case PAGES: ok = endin_addpage( info, d->data, level ); break; case SERIALNO: ok = addsn( info, d->data, level ); break; case NOTES: ok = endin_addnotes( info, newtag, d->data, level ); break; default: fprintf(stderr,"%s: internal error -- illegal process number %d\n", p->progname, process ); ok = 1; break; } if ( !ok ) return BIBL_ERR_MEMERR; } return BIBL_OK; }