/* bibl_copy() * * returns 1 on success, 0 on failure (memory error) */ int bibl_copy( bibl *bout, bibl *bin ) { fields *refin, *refout; int i, j, n, status, ok, level; char *tag, *value; for ( i=0; i<bin->nrefs; ++i ) { refin = bin->ref[i]; refout = fields_new(); if ( !refout ) return 0; n = fields_num( refin ); for ( j=0; j<n; ++j ) { tag = fields_tag( refin, j, FIELDS_CHRP ); value = fields_value( refin, j, FIELDS_CHRP ); level = fields_level( refin, j ); if ( tag && value ) { status = fields_add( refout, tag, value, level ); if ( status!=FIELDS_OK ) return 0; } } ok = bibl_addref( bout, refout ); if ( !ok ) return 0; } return 1; }
static int read_ref( FILE *fp, bibl *bin, char *filename, convert_rules *r, param *p ) { newstr reference, line; fields *ref; char buf[256]=""; int nrefs = 0, bufpos = 0, fcharset; newstr_init( &reference ); newstr_init( &line ); while ( r->readf( fp, buf, sizeof(buf), &bufpos, &line, &reference, &fcharset ) ) { if ( reference.len==0 ) continue; ref = fields_new(); if ( !ref ) return BIBL_ERR_MEMERR; if ( r->processf( ref, reference.data, filename, nrefs+1 )){ bibl_addref( bin, ref ); } else { fields_free( ref ); free( ref ); } newstr_empty( &reference ); if ( fcharset!=CHARSET_UNKNOWN ) { /* charset from file takes priority over default, but * not user-specified */ if ( p->charsetin_src!=BIBL_SRC_USER ) { p->charsetin_src = BIBL_SRC_FILE; p->charsetin = fcharset; if ( fcharset!=CHARSET_UNICODE ) p->utf8in = 0; } } } newstr_free( &line ); newstr_free( &reference ); return BIBL_OK; }
static int convert_ref( bibl *bin, char *fname, bibl *bout, convert_rules *r, param *p ) { fields *rin, *rout; long i; int reftype; if ( r->cleanf ) r->cleanf( bin, p ); for ( i=0; i<bin->nrefs; ++i ) { rin = bin->ref[i]; rout = fields_new(); if ( !rout ) return BIBL_ERR_MEMERR; if ( r->typef ) reftype = r->typef( rin, fname, i+1, p, r->all, r->nall ); else reftype = 0; r->convertf( rin, rout, reftype, p, r->all, r->nall ); if ( r->all ) process_alwaysadd( rout, reftype, r ); if ( p->verbose ) bibl_verbose1( rout, rin, fname, i+1 ); bibl_addref( bout, rout ); } uniqueify_citekeys( bout ); return BIBL_OK; }