LaTeX-BibTeX
view release on metacpan or search on metacpan
btxs_support.c view on Meta::CPAN
@GLOBALS :
@CREATED : 1997/11/16, Greg Ward (from code in BibTeX.xs)
@MODIFIED :
@VERSION : $Id: btxs_support.c,v 1.8 2000/05/20 02:45:15 greg Exp $
@COPYRIGHT : Copyright (c) 1997-2000 by Gregory P. Ward. All rights reserved.
-------------------------------------------------------------------------- */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#define BT_DEBUG 0
#include "btparse.h"
#include "btxs_support.h"
static char *nodetype_names[] =
{
"entry", "macrodef", "text", "key", "field", "string", "number", "macro"
};
/* ----------------------------------------------------------------------
* Miscellaneous stuff
*/
int
constant (char * name, IV * arg)
{
int ok = FALSE;
DBG_ACTION (1, printf ("constant: name=%s\n", name));
if (! (name[0] == 'B' && name[1] == 'T')) /* should not happen! */
croak ("Illegal constant name \"%s\"", name);
switch (name[2])
{
case 'E': /* entry metatypes */
if (strEQ (name, "BTE_UNKNOWN")) { *arg = BTE_UNKNOWN; ok = TRUE; }
if (strEQ (name, "BTE_REGULAR")) { *arg = BTE_REGULAR; ok = TRUE; }
if (strEQ (name, "BTE_COMMENT")) { *arg = BTE_COMMENT; ok = TRUE; }
if (strEQ (name, "BTE_PREAMBLE")) { *arg = BTE_PREAMBLE; ok = TRUE; }
if (strEQ (name, "BTE_MACRODEF")) { *arg = BTE_MACRODEF; ok = TRUE; }
break;
case 'A': /* AST nodetypes (not all of them) */
if (strEQ (name, "BTAST_STRING")) { *arg = BTAST_STRING; ok = TRUE; }
if (strEQ (name, "BTAST_NUMBER")) { *arg = BTAST_NUMBER; ok = TRUE; }
if (strEQ (name, "BTAST_MACRO")) { *arg = BTAST_MACRO; ok = TRUE; }
break;
case 'N': /* name parts */
if (strEQ (name, "BTN_FIRST")) { *arg = BTN_FIRST; ok = TRUE; }
if (strEQ (name, "BTN_VON")) { *arg = BTN_VON; ok = TRUE; }
if (strEQ (name, "BTN_LAST")) { *arg = BTN_LAST; ok = TRUE; }
if (strEQ (name, "BTN_JR")) { *arg = BTN_JR; ok = TRUE; }
if (strEQ (name, "BTN_NONE")) { *arg = BTN_NONE; ok = TRUE; }
break;
case 'J': /* token join methods */
if (strEQ (name, "BTJ_MAYTIE")) { *arg = BTJ_MAYTIE; ok = TRUE; }
if (strEQ (name, "BTJ_SPACE")) { *arg = BTJ_SPACE; ok = TRUE; }
if (strEQ (name, "BTJ_FORCETIE")) { *arg = BTJ_FORCETIE; ok = TRUE; }
if (strEQ (name, "BTJ_NOTHING")) { *arg = BTJ_NOTHING; ok = TRUE; }
break;
default:
break;
}
return ok;
}
/* ----------------------------------------------------------------------
* Stuff for converting a btparse entry AST to a Perl structure:
* convert_value() [private]
* convert_assigned_entry() [private]
* convert_value_entry() [private]
* ast_to_hash()
*/
static SV *
convert_value (char * field_name, AST * field, boolean preserve)
{
AST * value;
bt_nodetype
nodetype;
char * text;
SV * sv_field_value;
value = bt_next_value (field, NULL, &nodetype, &text);
if (preserve)
{
HV * val_stash; /* stash for LaTeX::BibTeX::Value pkg */
HV * sval_stash; /* and for LaTeX::BibTeX::SimpleValue */
AV * compound_value; /* list of simple values */
SV * sval_contents[2]; /* type and text */
AV * simple_value; /* list of (type, text) */
SV * simple_value_ref; /* ref to simple_value */
/*
* Get the stashes for the two classes into which we'll be
* blessing things.
*/
val_stash = gv_stashpv ("LaTeX::BibTeX::Value", TRUE);
sval_stash = gv_stashpv ("LaTeX::BibTeX::SimpleValue", TRUE);
if (val_stash == NULL || sval_stash == NULL)
{
croak ("unable to get stash for one or both of "
"LaTeX::BibTeX::Value or LaTeX::BibTeX::SimpleValue");
}
/* Start the compound value as an empty list */
compound_value = newAV ();
/* Walk the list of simple values */
while (value)
{
/*
* Convert the nodetype and text to SVs and save them in what will
* soon become a LaTeX::BibTeX::SimpleValue object.
*/
sval_contents[0] = newSViv ((IV) nodetype);
( run in 1.702 second using v1.01-cache-2.11-cpan-5837b0d9d2c )