/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.51 from the
 * contents of BibTeX.xs. Do not edit this file, edit BibTeX.xs instead.
 *
 *    ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "xscode/BibTeX.xs"
/* ------------------------------------------------------------------------
@NAME       : BibTeX.xs
@INPUT      : 
@OUTPUT     : 
@RETURNS    : 
@DESCRIPTION: Glue between my `btparse' library and the Perl module
              Text::BibTeX.  Provides the following functions to Perl:
                 Text::BibTeX::constant
                 Text::BibTeX::initialize
                 Text::BibTeX::cleanup
                 Text::BibTeX::split_list
                 Text::BibTeX::purify_string
                 Text::BibTeX::Entry::_parse_s
                 Text::BibTeX::Entry::_parse
                 Text::BibTeX::Name::split
                 Text::BibTeX::Name::free
                 Text::BibTeX::add_macro_text
                 Text::BibTeX::delete_macro
                 Text::BibTeX::delete_all_macros
                 Text::BibTeX::macro_length
                 Text::BibTeX::macro_text
@GLOBALS    : 
@CALLS      : 
@CREATED    : Jan/Feb 1997, Greg Ward
@MODIFIED   : 
@VERSION    : $Id: BibTeX.xs 7399 2009-06-01 21:22:51Z ambs $
-------------------------------------------------------------------------- */
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#define BT_DEBUG 0

#include "btparse.h"
#include "btxs_support.h"


#line 48 "xscode/BibTeX.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef dVAR
#  define dVAR		dNOOP
#endif


/* This stuff is not part of the API! You have been warned. */
#ifndef PERL_VERSION_DECIMAL
#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
#endif
#ifndef PERL_DECIMAL_VERSION
#  define PERL_DECIMAL_VERSION \
	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
#endif
#ifndef PERL_VERSION_GE
#  define PERL_VERSION_GE(r,v,s) \
	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
#endif
#ifndef PERL_VERSION_LE
#  define PERL_VERSION_LE(r,v,s) \
	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
#endif

/* XS_INTERNAL is the explicit static-linkage variant of the default
 * XS macro.
 *
 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
 * for anything but the BOOT XSUB.
 *
 * See XSUB.h in core!
 */


/* TODO: This might be compatible further back than 5.10.0. */
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
#  undef XS_EXTERNAL
#  undef XS_INTERNAL
#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
#    define XS_INTERNAL(name) STATIC XSPROTO(name)
#  endif
#  if defined(__SYMBIAN32__)
#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
#  endif
#  ifndef XS_EXTERNAL
#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
#    else
#      ifdef __cplusplus
#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
#        define XS_INTERNAL(name) static XSPROTO(name)
#      else
#        define XS_EXTERNAL(name) XSPROTO(name)
#        define XS_INTERNAL(name) STATIC XSPROTO(name)
#      endif
#    endif
#  endif
#endif

/* perl >= 5.10.0 && perl <= 5.15.1 */


/* The XS_EXTERNAL macro is used for functions that must not be static
 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
 * macro defined, the best we can do is assume XS is the same.
 * Dito for XS_INTERNAL.
 */
#ifndef XS_EXTERNAL
#  define XS_EXTERNAL(name) XS(name)
#endif
#ifndef XS_INTERNAL
#  define XS_INTERNAL(name) XS(name)
#endif

/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
 * internal macro that we're free to redefine for varying linkage due
 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
 */

#undef XS_EUPXS
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
#  define XS_EUPXS(name) XS_EXTERNAL(name)
#else
   /* default to internal */
#  define XS_EUPXS(name) XS_INTERNAL(name)
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(const CV *const cv, const char *const params)
{
    const GV *const gv = CvGV(cv);

    PERL_ARGS_ASSERT_CROAK_XS_USAGE;

    if (gv) {
        const char *const gvname = GvNAME(gv);
        const HV *const stash = GvSTASH(gv);
        const char *const hvname = stash ? HvNAME(stash) : NULL;

        if (hvname)
	    Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
        else
	    Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
	Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#define croak_xs_usage        S_croak_xs_usage

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#if PERL_VERSION_LE(5, 21, 5)
#  define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
#else
#  define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
#endif

#line 192 "xscode/BibTeX.c"

XS_EUPXS(XS_Text__BibTeX_constant); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_constant)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "name");
    {
	char *	name;
	SV *	RETVAL;

        SvGETMAGIC(ST(0));
        name = SvOK (ST(0)) ? (char *) SvPV_nomg(ST(0), PL_na) : NULL
;
#line 48 "xscode/BibTeX.xs"
	IV i;
	if (constant(name, &i))
	    ST(0) = sv_2mortal(newSViv(i));
	else
	    ST(0) = &PL_sv_undef;
#line 213 "xscode/BibTeX.c"
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Text__BibTeX_initialize); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_initialize)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {

	bt_initialize();
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Text__BibTeX_cleanup); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_cleanup)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {

	bt_cleanup();
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Text__BibTeX_isplit_list); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_isplit_list)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 5)
       croak_xs_usage(cv,  "string, delim, filename=NULL, line=0, description=NULL");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	char *	string;
	char *	delim;
	char *	filename;
	int	line;
	char *	description;
#line 85 "xscode/BibTeX.xs"
       bt_stringlist *
             names;
       int   i;
       SV *  sv_name;

#line 267 "xscode/BibTeX.c"

        SvGETMAGIC(ST(0));
        string = SvOK (ST(0)) ? (char *) SvPV_nomg(ST(0), PL_na) : NULL
;

        SvGETMAGIC(ST(1));
        delim = SvOK (ST(1)) ? (char *) SvPV_nomg(ST(1), PL_na) : NULL
;

	if (items < 3)
	    filename = NULL;
	else {
	SvGETMAGIC(ST(2));
	filename = SvOK (ST(2)) ? (char *) SvPV_nomg(ST(2), PL_na) : NULL
;
	}

	if (items < 4)
	    line = 0;
	else {
	    line = (int)SvIV(ST(3))
;
	}

	if (items < 5)
	    description = NULL;
	else {
	SvGETMAGIC(ST(4));
	description = SvOK (ST(4)) ? (char *) SvPV_nomg(ST(4), PL_na) : NULL
;
	}
#line 91 "xscode/BibTeX.xs"
       names = bt_split_list (string, delim, filename, line, description);
       if (names == NULL)
          XSRETURN_EMPTY;       /* return empty list to perl */

       EXTEND (sp, names->num_items);
       for (i = 0; i < names->num_items; i++)
       {
          if (names->items[i] == NULL)
             sv_name = &PL_sv_undef;
          else
             sv_name = sv_2mortal (newSVpv (names->items[i], 0));

          PUSHs (sv_name);
       }

       bt_free_list (names);
#line 316 "xscode/BibTeX.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Text__BibTeX_purify_string); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_purify_string)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 2)
       croak_xs_usage(cv,  "instr, options=0");
    {
	char *	instr;
	int	options;
	SV *	RETVAL;

        SvGETMAGIC(ST(0));
        instr = SvOK (ST(0)) ? (char *) SvPV_nomg(ST(0), PL_na) : NULL
;

	if (items < 2)
	    options = 0;
	else {
	    options = (int)SvIV(ST(1))
;
	}
#line 116 "xscode/BibTeX.xs"
       if (instr == NULL)               /* undef in, undef out */
          XSRETURN_EMPTY;
       RETVAL = newSVpv (instr, 0);
       bt_purify_string (SvPVX (RETVAL), (btshort) options);
       SvCUR_set (RETVAL, strlen (SvPVX (RETVAL))); /* reset SV's length */

#line 351 "xscode/BibTeX.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Text__BibTeX_change_case); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_change_case)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "transform, string, options=0");
    {
	char	transform = (char)*SvPV_nolen(ST(0))
;
	char *	string;
	int	options;
	SV *	RETVAL;

        SvGETMAGIC(ST(1));
        string = SvOK (ST(1)) ? (char *) SvPV_nomg(ST(1), PL_na) : NULL
;

	if (items < 3)
	    options = 0;
	else {
	    options = (int)SvIV(ST(2))
;
	}
#line 152 "xscode/BibTeX.xs"
       DBG_ACTION
          (1, printf ("XSUB change_case: transform=%c, string=%p (%s)\n",
                      transform, string, string))                  
       if (string == NULL)
          XSRETURN_EMPTY;
       RETVAL = newSVpv (string, 0);
       bt_change_case (transform, SvPVX (RETVAL), (btshort) options);

#line 391 "xscode/BibTeX.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Text__BibTeX__Entry__parse); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__Entry__parse)
{
    dVAR; dXSARGS;
    if (items < 3 || items > 4)
       croak_xs_usage(cv,  "entry_ref, filename, file, preserve=FALSE");
    {
	SV *	entry_ref = ST(0)
;
	char *	filename;
	FILE *	file = PerlIO_findFILE(IoIFP(sv_2io(ST(2))))
;
	boolean	preserve;
#line 184 "xscode/BibTeX.xs"
        btshort  options = 0;
        boolean status;
        AST *   top;

#line 417 "xscode/BibTeX.c"
	int	RETVAL;
	dXSTARG;

        SvGETMAGIC(ST(1));
        filename = SvOK (ST(1)) ? (char *) SvPV_nomg(ST(1), PL_na) : NULL
;

	if (items < 4)
	    preserve = FALSE;
	else {
	preserve = (SvOK (ST(3))) ? (int) SvIV (ST(3)) : 0
;
	}
#line 190 "xscode/BibTeX.xs"
        top = bt_parse_entry (file, filename, options, &status);
        DBG_ACTION 
           (2, dump_ast ("BibTeX.xs:parse: AST from bt_parse_entry():\n", top))

        if (!top)                  /* at EOF -- return false to perl */
        {
           XSRETURN_NO;
        }

        ast_to_hash (entry_ref, top, status, preserve);
        XSRETURN_YES;              /* OK -- return true to perl */
#line 443 "xscode/BibTeX.c"
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Text__BibTeX__Entry__reset_parse); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__Entry__reset_parse)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
#line 207 "xscode/BibTeX.xs"
        btshort  options = 0;
        boolean status;

#line 460 "xscode/BibTeX.c"
	int	RETVAL;
	dXSTARG;
#line 212 "xscode/BibTeX.xs"
        bt_parse_entry (NULL, NULL, options, &status);

        XSRETURN_NO;              /* cleanup -- return false to perl */
#line 467 "xscode/BibTeX.c"
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Text__BibTeX__Entry__parse_s); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__Entry__parse_s)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 3)
       croak_xs_usage(cv,  "entry_ref, text, preserve=FALSE");
    {
	SV *	entry_ref = ST(0)
;
	char *	text;
	boolean	preserve;
#line 224 "xscode/BibTeX.xs"
        btshort  options = 0;
        boolean status;
        AST *   top;

#line 489 "xscode/BibTeX.c"
	int	RETVAL;
	dXSTARG;

        SvGETMAGIC(ST(1));
        text = SvOK (ST(1)) ? (char *) SvPV_nomg(ST(1), PL_na) : NULL
;

	if (items < 3)
	    preserve = FALSE;
	else {
	preserve = (SvOK (ST(2))) ? (int) SvIV (ST(2)) : 0
;
	}
#line 230 "xscode/BibTeX.xs"
        top = bt_parse_entry_s (text, NULL, 1, options, &status);
        if (!top)                  /* no entry found -- return false to perl */
        {
           XSRETURN_NO;
        }

        ast_to_hash (entry_ref, top, status, preserve);
        XSRETURN_YES;              /* OK -- return true to perl */
#line 512 "xscode/BibTeX.c"
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Text__BibTeX__Entry__reset_parse_s); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__Entry__reset_parse_s)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {
#line 244 "xscode/BibTeX.xs"
        btshort  options = 0;
        boolean status;

#line 529 "xscode/BibTeX.c"
	int	RETVAL;
	dXSTARG;
#line 249 "xscode/BibTeX.xs"
        bt_parse_entry_s (NULL, NULL, 1, options, &status);

        XSRETURN_NO;              /* cleanup -- return false to perl */
#line 536 "xscode/BibTeX.c"
    }
    XSRETURN(1);
}

#if BT_DEBUG
#define XSubPPtmpAAAA 1


XS_EUPXS(XS_Text__BibTeX__Name_dump_name); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__Name_dump_name)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "hashref");
    {
	SV *	hashref = ST(0)
;
#line 268 "xscode/BibTeX.xs"
       HV *       hash;
       SV **      sv_name;
       bt_name  * name;

#line 559 "xscode/BibTeX.c"
#line 273 "xscode/BibTeX.xs"
       hash = (HV *) SvRV (hashref);
       sv_name = hv_fetch (hash, "_cstruct", 8, 0);
       if (! sv_name)
       {
          warn ("Name::dump: no _cstruct member in hash");
       }
       else
       { 
          name = (bt_name *) SvIV (*sv_name);
          dump_name (name);             /* currently in format_name.c */
       }
#line 572 "xscode/BibTeX.c"
    }
    XSRETURN_EMPTY;
}

#endif

XS_EUPXS(XS_Text__BibTeX__Name__split); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__Name__split)
{
    dVAR; dXSARGS;
    if (items != 6)
       croak_xs_usage(cv,  "name_hashref, name, filename, line, name_num, keep_cstruct");
    {
	SV *	name_hashref = ST(0)
;
	char *	name;
	char *	filename;
	int	line = (int)SvIV(ST(3))
;
	int	name_num = (int)SvIV(ST(4))
;
	int	keep_cstruct = (int)SvIV(ST(5))
;
#line 299 "xscode/BibTeX.xs"
       HV *      name_hash;
       SV *      sv_old_name;
       bt_name * old_name;
       bt_name * name_split;

#line 602 "xscode/BibTeX.c"

        SvGETMAGIC(ST(1));
        name = SvOK (ST(1)) ? (char *) SvPV_nomg(ST(1), PL_na) : NULL
;

        SvGETMAGIC(ST(2));
        filename = SvOK (ST(2)) ? (char *) SvPV_nomg(ST(2), PL_na) : NULL
;
#line 305 "xscode/BibTeX.xs"
       if (! (SvROK (name_hashref) && 
              SvTYPE (SvRV (name_hashref)) == SVt_PVHV))
          croak ("name_hashref is not a hash reference");
       name_hash = (HV *) SvRV (name_hashref);

       DBG_ACTION (1, 
       {
          printf ("XS Name::_split:\n");
          printf ("  name_hashref=%p, name_hash=%p\n", 
                  (void *) name_hashref, (void *) name_hash);
          printf ("  name=%p (%s), filename=%p (%s)\n",
                  name, name, filename, filename);
          printf ("  line=%d, name_num=%d, keep_cstruct=%d\n",
                  line, name_num, keep_cstruct);
       })

       sv_old_name = hv_delete (name_hash, "_cstruct", 8, 0);
       if (sv_old_name)
       {
          old_name = (bt_name *) SvIV (sv_old_name);
          DBG_ACTION
             (1, printf ("XS Name::_split: name hash had old C structure "
                         "(%d tokens, first was >%s<) -- freeing it\n",
                         old_name->tokens->num_items,
                         old_name->tokens->items[0]))
          bt_free_name (old_name);
       }

       name_split = bt_split_name (name, filename, line, name_num);
       DBG_ACTION (1, printf ("XS Name::_split: back from bt_split_name, "
                              "calling store_stringlist x 4\n"))

       store_stringlist (name_hash, "first", 
                         name_split->parts[BTN_FIRST],
                         name_split->part_len[BTN_FIRST]);
       store_stringlist (name_hash, "von", 
                         name_split->parts[BTN_VON],
                         name_split->part_len[BTN_VON]);
       store_stringlist (name_hash, "last", 
                         name_split->parts[BTN_LAST],
                         name_split->part_len[BTN_LAST]);
       store_stringlist (name_hash, "jr", 
                         name_split->parts[BTN_JR],
                         name_split->part_len[BTN_JR]);

       DBG_ACTION (1, 
       {
          char ** last = name_split->parts[BTN_LAST];
          char ** first = name_split->parts[BTN_FIRST];

          printf ("XS Name::_split: name has %d tokens; "
                 "last[0]=%s, first[0]=%s\n",
                 name_split->tokens->num_items,
                 last ? last[0] : "*no last name*",
                 first ? first[0] : "*no first name*");
       })

       if (keep_cstruct)
       {
          hv_store (name_hash, "_cstruct", 8, newSViv ((IV) name_split), 0);
          DBG_ACTION 
             (1, printf ("XS Name::_split: storing pointer to structure %p\n", 
                         name_split))
       }
       else
       {
          bt_free_name (name_split);
       }
#line 680 "xscode/BibTeX.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Text__BibTeX__Name_free); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__Name_free)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "name_hashref");
    {
	SV *	name_hashref = ST(0)
;
#line 380 "xscode/BibTeX.xs"
       HV *      name_hash;
       SV **     sv_name;
       bt_name * name;

#line 700 "xscode/BibTeX.c"
#line 385 "xscode/BibTeX.xs"
       name_hash = (HV *) SvRV (name_hashref);
       sv_name = hv_fetch (name_hash, "_cstruct", 8, 0);
       if (sv_name != NULL)
       {
          name = (bt_name *) SvIV (*sv_name);
          DBG_ACTION (1, printf ("XS Name::free: freeing name %p\n", name))
          bt_free_name (name);
       }
#if BT_DEBUG >= 1
       else
       {
          printf ("XS Name::free: no C structure to free!\n");
       }
#endif
#line 716 "xscode/BibTeX.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Text__BibTeX__NameFormat_create); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__NameFormat_create)
{
    dVAR; dXSARGS;
    if (items < 0 || items > 2)
       croak_xs_usage(cv,  "parts=\"fvlj\", abbrev_first=FALSE");
    {
	char *	parts;
	bool	abbrev_first;
#line 410 "xscode/BibTeX.xs"
#line 732 "xscode/BibTeX.c"
	IV	RETVAL;
	dXSTARG;

	if (items < 1)
	    parts = "fvlj";
	else {
	SvGETMAGIC(ST(0));
	parts = SvOK (ST(0)) ? (char *) SvPV_nomg(ST(0), PL_na) : NULL
;
	}

	if (items < 2)
	    abbrev_first = FALSE;
	else {
	abbrev_first = (SvOK (ST(1))) ? (int) SvIV (ST(1)) : 0
;
	}
#line 411 "xscode/BibTeX.xs"
       DBG_ACTION 
          (1, printf ("XS NameFormat::create: "
                      "creating name format: parts=\"%s\", abbrev=%d\n",
                      parts, abbrev_first));
       RETVAL = (IV) bt_create_name_format (parts, abbrev_first);

#line 757 "xscode/BibTeX.c"
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Text__BibTeX__NameFormat_free); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__NameFormat_free)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "format");
    {
	bt_name_format *        format = (bt_name_format *) SvIV (ST(0))
;
#line 426 "xscode/BibTeX.xs"
       bt_free_name_format ((bt_name_format *) format);
#line 776 "xscode/BibTeX.c"
    }
    XSRETURN_EMPTY;
}

#if BT_DEBUG
#define XSubPPtmpAAAB 1


XS_EUPXS(XS_Text__BibTeX__NameFormat_dump_format); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__NameFormat_dump_format)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "hashref");
    {
	SV *	hashref = ST(0)
;
#line 436 "xscode/BibTeX.xs"
       HV *             hash;
       SV **            sv_format;
       bt_name_format * format;

#line 799 "xscode/BibTeX.c"
#line 441 "xscode/BibTeX.xs"
       hash = (HV *) SvRV (hashref);
       sv_format = hv_fetch (hash, "_cstruct", 8, 0);
       if (! sv_format)
       {
          warn ("NameFormat::dump: no _cstruct member in hash");
       }
       else
       { 
          format = (bt_name_format *) SvIV (*sv_format);
          dump_format (format);         /* currently in format_name.c */
       }
#line 812 "xscode/BibTeX.c"
    }
    XSRETURN_EMPTY;
}

#endif

XS_EUPXS(XS_Text__BibTeX__NameFormat__set_text); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__NameFormat__set_text)
{
    dVAR; dXSARGS;
    if (items != 6)
       croak_xs_usage(cv,  "format, part, pre_part, post_part, pre_token, post_token");
    {
	bt_name_format *        format = (bt_name_format *) SvIV (ST(0))
;
	bt_namepart	part = (bt_namepart)SvIV(ST(1))
;
	char *	pre_part;
	char *	post_part;
	char *	pre_token;
	char *	post_token;

        SvGETMAGIC(ST(2));
        pre_part = SvOK (ST(2)) ? (char *) SvPV_nomg(ST(2), PL_na) : NULL
;

        SvGETMAGIC(ST(3));
        post_part = SvOK (ST(3)) ? (char *) SvPV_nomg(ST(3), PL_na) : NULL
;

        SvGETMAGIC(ST(4));
        pre_token = SvOK (ST(4)) ? (char *) SvPV_nomg(ST(4), PL_na) : NULL
;

        SvGETMAGIC(ST(5));
        post_token = SvOK (ST(5)) ? (char *) SvPV_nomg(ST(5), PL_na) : NULL
;
#line 466 "xscode/BibTeX.xs"
#if BT_DEBUG >= 2
    {
       static char * nameparts[] =
          { "first", "von", "last", "jr" };
       static char * joinmethods[] =
          {"may tie", "space", "force tie", "nothing"};

       printf ("XS NameFormat::_set_text:\n");
       printf ("  format=%p, namepart=%d (%s)\n", 
               format, part, nameparts[part]);
       printf ("  format currently is:\n");
       dump_format (format);
       printf ("  pre_part=%s, post_part=%s\n", pre_part, post_part);
       printf ("  pre_token=%s, post_token=%s\n", pre_token, post_token);
    }
#endif

       /*
        * No memory leak here -- just copy the pointers.  At first
        * blush, it might seem that we're opening ourselves up to
        * the possibility of dangling pointers if the Perl strings
        * that these char *'s refer to ever go away.  However, this
        * is taken care of at the Perl level -- see the comment
        * in BibTeX/NameFormat.pm, sub set_text.
        */

       bt_set_format_text (format, part,
                           pre_part, post_part, pre_token, post_token);
#if BT_DEBUG >= 2
       printf ("XS NameFormat::_set_text: after call, format is:\n");
       dump_format (format);
#endif
#line 883 "xscode/BibTeX.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Text__BibTeX__NameFormat__set_options); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__NameFormat__set_options)
{
    dVAR; dXSARGS;
    if (items != 5)
       croak_xs_usage(cv,  "format, part, abbrev, join_tokens, join_part");
    {
	bt_name_format *        format = (bt_name_format *) SvIV (ST(0))
;
	bt_namepart	part = (bt_namepart)SvIV(ST(1))
;
	bool        abbrev = (SvOK (ST(2))) ? (int) SvIV (ST(2)) : 0
;
	bt_joinmethod	join_tokens = (bt_joinmethod)SvIV(ST(3))
;
	bt_joinmethod	join_part = (bt_joinmethod)SvIV(ST(4))
;
#line 509 "xscode/BibTeX.xs"
       DBG_ACTION (2,
          printf ("XS _set_options: format=%p, part=%d, "
                  "abbrev=%d, join_tokens=%d, join_part=%d\n",
                  format, part, abbrev, join_tokens, join_part))
       bt_set_format_options (format, part, 
                              abbrev, join_tokens, join_part);
#line 913 "xscode/BibTeX.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Text__BibTeX__NameFormat_format_name); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX__NameFormat_format_name)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "name, format");
    {
	bt_name *        name = (bt_name *) SvIV (ST(0))
;
	bt_name_format *        format = (bt_name_format *) SvIV (ST(1))
;
	char *	RETVAL;
	dXSTARG;
#line 523 "xscode/BibTeX.xs"
       DBG_ACTION 
          (2, printf ("XS format_name: name=%p, format=%p\n", name, format))
       RETVAL = bt_format_name (name, format);
       DBG_ACTION
          (1, printf ("XS format_name: formatted name=%s\n", RETVAL))

#line 939 "xscode/BibTeX.c"
	sv_setpv(TARG, RETVAL);
	XSprePUSH;
	PUSHTARG;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Text__BibTeX_add_macro_text); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_add_macro_text)
{
    dVAR; dXSARGS;
    if (items < 2 || items > 4)
       croak_xs_usage(cv,  "macro, text, filename=NULL, line=0");
    {
	char *	macro;
	char *	text;
	char *	filename;
	int	line;

        SvGETMAGIC(ST(0));
        macro = SvOK (ST(0)) ? (char *) SvPV_nomg(ST(0), PL_na) : NULL
;

        SvGETMAGIC(ST(1));
        text = SvOK (ST(1)) ? (char *) SvPV_nomg(ST(1), PL_na) : NULL
;

	if (items < 3)
	    filename = NULL;
	else {
	SvGETMAGIC(ST(2));
	filename = SvOK (ST(2)) ? (char *) SvPV_nomg(ST(2), PL_na) : NULL
;
	}

	if (items < 4)
	    line = 0;
	else {
	    line = (int)SvIV(ST(3))
;
	}

	bt_add_macro_text(macro, text, filename, line);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Text__BibTeX_delete_macro); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_delete_macro)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "macro");
    {
	char *	macro;

        SvGETMAGIC(ST(0));
        macro = SvOK (ST(0)) ? (char *) SvPV_nomg(ST(0), PL_na) : NULL
;

	bt_delete_macro(macro);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Text__BibTeX_delete_all_macros); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_delete_all_macros)
{
    dVAR; dXSARGS;
    if (items != 0)
       croak_xs_usage(cv,  "");
    {

	bt_delete_all_macros();
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Text__BibTeX_macro_length); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_macro_length)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "macro");
    {
	char *	macro;
	int	RETVAL;
	dXSTARG;

        SvGETMAGIC(ST(0));
        macro = SvOK (ST(0)) ? (char *) SvPV_nomg(ST(0), PL_na) : NULL
;

	RETVAL = bt_macro_length(macro);
	XSprePUSH;
	PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Text__BibTeX_macro_text); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Text__BibTeX_macro_text)
{
    dVAR; dXSARGS;
    if (items < 1 || items > 3)
       croak_xs_usage(cv,  "macro, filename=NULL, line=0");
    {
	char *	macro;
	char *	filename;
	int	line;
	char *	RETVAL;
	dXSTARG;

        SvGETMAGIC(ST(0));
        macro = SvOK (ST(0)) ? (char *) SvPV_nomg(ST(0), PL_na) : NULL
;

	if (items < 2)
	    filename = NULL;
	else {
	SvGETMAGIC(ST(1));
	filename = SvOK (ST(1)) ? (char *) SvPV_nomg(ST(1), PL_na) : NULL
;
	}

	if (items < 3)
	    line = 0;
	else {
	    line = (int)SvIV(ST(2))
;
	}

	RETVAL = bt_macro_text(macro, filename, line);
	sv_setpv(TARG, RETVAL);
	XSprePUSH;
	PUSHTARG;
    }
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C" {
#endif
XS_EXTERNAL(boot_Text__BibTeX); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Text__BibTeX)
{
#if PERL_VERSION_LE(5, 21, 5)
    dVAR; dXSARGS;
#else
    dVAR; dXSBOOTARGSXSAPIVERCHK;
#endif
#if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(file);

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#if PERL_VERSION_LE(5, 21, 5)
    XS_VERSION_BOOTCHECK;
#  ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#  endif
#endif

        newXS_deffile("Text::BibTeX::constant", XS_Text__BibTeX_constant);
        newXS_deffile("Text::BibTeX::initialize", XS_Text__BibTeX_initialize);
        newXS_deffile("Text::BibTeX::cleanup", XS_Text__BibTeX_cleanup);
        newXS_deffile("Text::BibTeX::isplit_list", XS_Text__BibTeX_isplit_list);
        newXS_deffile("Text::BibTeX::purify_string", XS_Text__BibTeX_purify_string);
        newXS_deffile("Text::BibTeX::change_case", XS_Text__BibTeX_change_case);
        newXS_deffile("Text::BibTeX::Entry::_parse", XS_Text__BibTeX__Entry__parse);
        newXS_deffile("Text::BibTeX::Entry::_reset_parse", XS_Text__BibTeX__Entry__reset_parse);
        newXS_deffile("Text::BibTeX::Entry::_parse_s", XS_Text__BibTeX__Entry__parse_s);
        newXS_deffile("Text::BibTeX::Entry::_reset_parse_s", XS_Text__BibTeX__Entry__reset_parse_s);
#if XSubPPtmpAAAA
        newXS_deffile("Text::BibTeX::Name::dump_name", XS_Text__BibTeX__Name_dump_name);
#endif
        newXS_deffile("Text::BibTeX::Name::_split", XS_Text__BibTeX__Name__split);
        newXS_deffile("Text::BibTeX::Name::free", XS_Text__BibTeX__Name_free);
        newXS_deffile("Text::BibTeX::NameFormat::create", XS_Text__BibTeX__NameFormat_create);
        newXS_deffile("Text::BibTeX::NameFormat::free", XS_Text__BibTeX__NameFormat_free);
#if XSubPPtmpAAAB
        newXS_deffile("Text::BibTeX::NameFormat::dump_format", XS_Text__BibTeX__NameFormat_dump_format);
#endif
        newXS_deffile("Text::BibTeX::NameFormat::_set_text", XS_Text__BibTeX__NameFormat__set_text);
        newXS_deffile("Text::BibTeX::NameFormat::_set_options", XS_Text__BibTeX__NameFormat__set_options);
        newXS_deffile("Text::BibTeX::NameFormat::format_name", XS_Text__BibTeX__NameFormat_format_name);
        newXS_deffile("Text::BibTeX::add_macro_text", XS_Text__BibTeX_add_macro_text);
        newXS_deffile("Text::BibTeX::delete_macro", XS_Text__BibTeX_delete_macro);
        newXS_deffile("Text::BibTeX::delete_all_macros", XS_Text__BibTeX_delete_all_macros);
        newXS_deffile("Text::BibTeX::macro_length", XS_Text__BibTeX_macro_length);
        newXS_deffile("Text::BibTeX::macro_text", XS_Text__BibTeX_macro_text);

    /* Initialisation Section */

#if XSubPPtmpAAAA
#endif
#if XSubPPtmpAAAB
#endif
#line 568 "xscode/BibTeX.xs"
    bt_set_stringopts (BTE_MACRODEF, 0);
    bt_set_stringopts (BTE_REGULAR, 0);
    bt_set_stringopts (BTE_COMMENT, 0);
    bt_set_stringopts (BTE_PREAMBLE, 0);

#line 1154 "xscode/BibTeX.c"

    /* End of Initialisation Section */

#if PERL_VERSION_LE(5, 21, 5)
#  if PERL_VERSION_GE(5, 9, 0)
    if (PL_unitcheckav)
        call_list(PL_scopestack_ix, PL_unitcheckav);
#  endif
    XSRETURN_YES;
#else
    Perl_xs_boot_epilog(aTHX_ ax);
#endif
}

#ifdef __cplusplus
}
#endif
