1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/******************************************************************************
** $Id: crossref.c,v 1.5 2012-01-26 19:54:20 gene Exp $
**=============================================================================
**
** This file is part of BibTool.
** It is distributed under the GNU General Public License.
** See the file COPYING for details.
**
** (c) 2007-2012 Gerd Neugebauer
**
** Net: gene@gerd-neugebauer.de
**
**-----------------------------------------------------------------------------
** Description:
** This module contains functions to expand crossref entries.
**
******************************************************************************/
#include <bibtool/general.h>
#include <bibtool/error.h>
#include <bibtool/crossref.h>
#include <bibtool/symbols.h>
#include <bibtool/s_parse.h>
#include <bibtool/database.h>
#include <bibtool/sbuffer.h>
#include <bibtool/rsc.h>
/*****************************************************************************/
/* Internal Programs */
/*===========================================================================*/
#ifdef __STDC__
#define _ARG(A) A
#else
#define _ARG(A) ()
#endif
int expand_crossref _ARG((DB db,Record rec));
/*****************************************************************************/
/* External Programs */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------
** Function: expand_crossref()
** Purpose: Expand all items inherited via a crossref.
** Arguments:
** db Database containing the entries.
** rec The record to expand
** Returns: ...
**___________________________________________________ */
int expand_crossref(db,rec) /* */
DB db; /* */
Record rec; /* */
{ register Uchar **hp; /* */
register int i; /* */
Uchar *t, *s; /* */
Record r = rec; /* */
int limit = rsc_xref_limit; /* */
/* */
DebugPrint1("expand_crossref"); /* */
/* */
while ( RecordIsXREF(r) && limit-->=0 ) /* */
{ /* */
for ( i=RecordFree(r), hp = RecordHeap(r); /* search crossref field */
i>0 && *hp != sym_crossref; /* */
i-=2, hp += 2 ) /* */
{ } /* */
if ( i <= 0 ) /* */
{ DebugPrint1("*** No crossref found."); /* */
return FALSE; /* */
} /* */
if (rec == r) { *hp = NULL; } /* Delete the first xref */
t = *++hp; /* */
t++; /* */
(void)sp_open(t); /* Try to extract */
if ( (s = SParseSymbol(&t)) == (Uchar*)0 ) /* the crossref as symbol*/
{ return FALSE; } /* */
/* */
if ( (r = db_find(db,s)) == (Record)NULL ) /* */
{ ERROR2("Crossref entry not found: ",(char*)s);/* */
return FALSE; /* */
} /* */
/* */
for ( i=RecordFree(r), hp = RecordHeap(r); /* visit all fields */
i>0; /* */
i-=2 ) /* */
{ /* */
s = *hp++; /* */
t = *hp++; /* */
if (t != (Uchar*)0) /* */
{ provide_to_record(rec,s,t); /* */
} /* */
} /* */
/* */
} /* */
/* */
return FALSE; /* */
} /*------------------------*/
|