python-bibtex-1.2.5/0000775000076400007640000000000011416711604013370 5ustar zkotazkotapython-bibtex-1.2.5/biblex.c0000664000076400007640000014701511416711346015014 0ustar zkotazkota #line 3 "lex.bibtex_parser_.c" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ #define yy_create_buffer bibtex_parser__create_buffer #define yy_delete_buffer bibtex_parser__delete_buffer #define yy_flex_debug bibtex_parser__flex_debug #define yy_init_buffer bibtex_parser__init_buffer #define yy_flush_buffer bibtex_parser__flush_buffer #define yy_load_buffer_state bibtex_parser__load_buffer_state #define yy_switch_to_buffer bibtex_parser__switch_to_buffer #define yyin bibtex_parser_in #define yyleng bibtex_parser_leng #define yylex bibtex_parser_lex #define yylineno bibtex_parser_lineno #define yyout bibtex_parser_out #define yyrestart bibtex_parser_restart #define yytext bibtex_parser_text #define yywrap bibtex_parser_wrap #define yyalloc bibtex_parser_alloc #define yyrealloc bibtex_parser_realloc #define yyfree bibtex_parser_free #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 #define YY_FLEX_SUBMINOR_VERSION 35 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ #include #include #include #include /* end standard C headers. */ /* flex integer type definitions */ #ifndef FLEXINT_H #define FLEXINT_H /* C99 systems have . Non-C99 systems may or may not. */ #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 #endif #include typedef int8_t flex_int8_t; typedef uint8_t flex_uint8_t; typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; #endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN #define INT8_MIN (-128) #endif #ifndef INT16_MIN #define INT16_MIN (-32767-1) #endif #ifndef INT32_MIN #define INT32_MIN (-2147483647-1) #endif #ifndef INT8_MAX #define INT8_MAX (127) #endif #ifndef INT16_MAX #define INT16_MAX (32767) #endif #ifndef INT32_MAX #define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX #define UINT8_MAX (255U) #endif #ifndef UINT16_MAX #define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX #define UINT32_MAX (4294967295U) #endif #endif /* ! FLEXINT_H */ #ifdef __cplusplus /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST #else /* ! __cplusplus */ /* C99 requires __STDC__ to be defined as 1. */ #if defined (__STDC__) #define YY_USE_CONST #endif /* defined (__STDC__) */ #endif /* ! __cplusplus */ #ifdef YY_USE_CONST #define yyconst const #else #define yyconst #endif /* Returned upon end-of-file. */ #define YY_NULL 0 /* Promotes a possibly negative, possibly signed char to an unsigned * integer for use as an array index. If the signed char is negative, * we want to instead treat it as an 8-bit unsigned char, hence the * double cast. */ #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ #define BEGIN (yy_start) = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ #define YY_START (((yy_start) - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ #define YY_NEW_FILE bibtex_parser_restart(bibtex_parser_in ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ #ifndef YY_BUF_SIZE #define YY_BUF_SIZE 16384 #endif /* The state buf must be large enough to hold one state per character in the main buffer. */ #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif extern int bibtex_parser_leng; extern FILE *bibtex_parser_in, *bibtex_parser_out; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 #define YY_LESS_LINENO(n) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ do \ { \ /* Undo effects of setting up bibtex_parser_text. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ *yy_cp = (yy_hold_char); \ YY_RESTORE_YY_MORE_OFFSET \ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up bibtex_parser_text again */ \ } \ while ( 0 ) #define unput(c) yyunput( c, (yytext_ptr) ) #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T typedef size_t yy_size_t; #endif #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state { FILE *yy_input_file; char *yy_ch_buf; /* input buffer */ char *yy_buf_pos; /* current position in input buffer */ /* Size of input buffer in bytes, not including room for EOB * characters. */ yy_size_t yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. */ int yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to * delete it. */ int yy_is_our_buffer; /* Whether this is an "interactive" input source; if so, and * if we're using stdio for input, then we want to use getc() * instead of fread(), to make sure we stop fetching input after * each newline. */ int yy_is_interactive; /* Whether we're considered to be at the beginning of a line. * If so, '^' rules will be active on the next match, otherwise * not. */ int yy_at_bol; int yy_bs_lineno; /**< The line count. */ int yy_bs_column; /**< The column count. */ /* Whether to try to fill the input buffer when we reach the * end of it. */ int yy_fill_buffer; int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 /* When an EOF's been seen but there's still some text to process * then we mark the buffer as YY_EOF_PENDING, to indicate that we * shouldn't try reading from the input source any more. We might * still have a bunch of tokens to match, though, because of * possible backing-up. * * When we actually see the EOF, we change the status to "new" * (via bibtex_parser_restart()), so that the user can continue scanning by * just pointing bibtex_parser_in at a new input file. */ #define YY_BUFFER_EOF_PENDING 2 }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* Stack of input buffers. */ static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". * * Returns the top of the stack, or NULL. */ #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] /* yy_hold_char holds the character lost when bibtex_parser_text is formed. */ static char yy_hold_char; static int yy_n_chars; /* number of characters read into yy_ch_buf */ int bibtex_parser_leng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; static int yy_init = 0; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ /* Flag which is used to allow bibtex_parser_wrap()'s to do buffer switches * instead of setting up a fresh bibtex_parser_in. A bit of a hack ... */ static int yy_did_buffer_switch_on_eof; void bibtex_parser_restart (FILE *input_file ); void bibtex_parser__switch_to_buffer (YY_BUFFER_STATE new_buffer ); YY_BUFFER_STATE bibtex_parser__create_buffer (FILE *file,int size ); void bibtex_parser__delete_buffer (YY_BUFFER_STATE b ); void bibtex_parser__flush_buffer (YY_BUFFER_STATE b ); void bibtex_parser_push_buffer_state (YY_BUFFER_STATE new_buffer ); void bibtex_parser_pop_buffer_state (void ); static void bibtex_parser_ensure_buffer_stack (void ); static void bibtex_parser__load_buffer_state (void ); static void bibtex_parser__init_buffer (YY_BUFFER_STATE b,FILE *file ); #define YY_FLUSH_BUFFER bibtex_parser__flush_buffer(YY_CURRENT_BUFFER ) YY_BUFFER_STATE bibtex_parser__scan_buffer (char *base,yy_size_t size ); YY_BUFFER_STATE bibtex_parser__scan_string (yyconst char *yy_str ); YY_BUFFER_STATE bibtex_parser__scan_bytes (yyconst char *bytes,int len ); void *bibtex_parser_alloc (yy_size_t ); void *bibtex_parser_realloc (void *,yy_size_t ); void bibtex_parser_free (void * ); #define yy_new_buffer bibtex_parser__create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ bibtex_parser_ensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ bibtex_parser__create_buffer(bibtex_parser_in,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ bibtex_parser_ensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ bibtex_parser__create_buffer(bibtex_parser_in,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) /* Begin user sect3 */ #define bibtex_parser_wrap(n) 1 #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; FILE *bibtex_parser_in = (FILE *) 0, *bibtex_parser_out = (FILE *) 0; typedef int yy_state_type; extern int bibtex_parser_lineno; int bibtex_parser_lineno = 1; extern char *bibtex_parser_text; #define yytext_ptr bibtex_parser_text static yy_state_type yy_get_previous_state (void ); static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); static int yy_get_next_buffer (void ); static void yy_fatal_error (yyconst char msg[] ); /* Done after the current pattern has been matched and before the * corresponding action - sets up bibtex_parser_text. */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ bibtex_parser_leng = (size_t) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; #define YY_NUM_RULES 10 #define YY_END_OF_BUFFER 11 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info { flex_int32_t yy_verify; flex_int32_t yy_nxt; }; static yyconst flex_int16_t yy_acclist[43] = { 0, 11, 10, 3, 10, 2, 10, 3, 10, 1, 3, 10, 5, 8, 9, 10, 6, 9, 10, 6, 10, 9, 10, 5, 9, 10, 5, 7, 8, 9, 10, 9, 10, 1, 5, 8, 5, 6, 5, 7, 8, 4, 4 } ; static yyconst flex_int16_t yy_accept[30] = { 0, 1, 1, 1, 1, 1, 1, 1, 2, 3, 5, 7, 9, 12, 16, 19, 21, 23, 26, 31, 33, 33, 34, 36, 37, 38, 41, 42, 43, 43 } ; static yyconst flex_int32_t yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 5, 6, 1, 6, 1, 1, 1, 1, 1, 1, 6, 1, 1, 1, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 1, 1, 6, 1, 1, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 1, 10, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 1, 5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ; static yyconst flex_int32_t yy_meta[11] = { 0, 1, 2, 2, 2, 3, 1, 1, 1, 1, 3 } ; static yyconst flex_int16_t yy_base[35] = { 0, 0, 0, 20, 0, 8, 0, 22, 50, 50, 50, 17, 50, 20, 0, 0, 50, 0, 28, 12, 0, 50, 32, 0, 0, 0, 50, 11, 50, 40, 43, 4, 2, 0, 46 } ; static yyconst flex_int16_t yy_def[35] = { 0, 29, 29, 30, 30, 28, 5, 28, 28, 28, 28, 28, 28, 31, 32, 32, 28, 33, 28, 34, 11, 28, 31, 33, 32, 18, 28, 28, 0, 28, 28, 28, 28, 28, 28 } ; static yyconst flex_int16_t yy_nxt[61] = { 0, 23, 11, 10, 24, 22, 28, 28, 12, 13, 14, 15, 14, 16, 17, 18, 17, 13, 19, 20, 27, 27, 28, 10, 28, 21, 23, 28, 23, 22, 28, 28, 28, 28, 23, 25, 23, 22, 23, 28, 23, 8, 8, 8, 9, 9, 9, 26, 26, 26, 7, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28 } ; static yyconst flex_int16_t yy_chk[61] = { 0, 33, 4, 4, 32, 31, 0, 0, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 11, 27, 19, 7, 3, 0, 11, 13, 0, 13, 18, 0, 0, 0, 0, 18, 18, 18, 18, 22, 0, 22, 29, 29, 29, 30, 30, 30, 34, 34, 34, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28 } ; extern int bibtex_parser__flex_debug; int bibtex_parser__flex_debug = 0; static yy_state_type *yy_state_buf=0, *yy_state_ptr=0; static char *yy_full_match; static int yy_lp; #define REJECT \ { \ *yy_cp = (yy_hold_char); /* undo effects of setting up bibtex_parser_text */ \ yy_cp = (yy_full_match); /* restore poss. backed-over text */ \ ++(yy_lp); \ goto find_rule; \ } #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *bibtex_parser_text; #line 1 "biblex.l" #line 2 "biblex.l" /* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: biblex.l,v 1.1.2.2 2003/09/02 14:35:33 fredgo Exp $ */ /* #include "parsername.h" */ #include #include "bibtex.h" #include "bibparse.h" static BibtexSource * current_source; gboolean bibtex_parser_is_content; extern void bibtex_next_line (void); #define YY_USER_ACTION current_source->offset += bibtex_parser_leng; #line 543 "lex.bibtex_parser_.c" #define INITIAL 0 #define comment 1 #define entry 2 #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way * down here because we want the user's section 1 to have been scanned first. * The user has a chance to override it with an option. */ #include #endif #ifndef YY_EXTRA_TYPE #define YY_EXTRA_TYPE void * #endif static int yy_init_globals (void ); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ int bibtex_parser_lex_destroy (void ); int bibtex_parser_get_debug (void ); void bibtex_parser_set_debug (int debug_flag ); YY_EXTRA_TYPE bibtex_parser_get_extra (void ); void bibtex_parser_set_extra (YY_EXTRA_TYPE user_defined ); FILE *bibtex_parser_get_in (void ); void bibtex_parser_set_in (FILE * in_str ); FILE *bibtex_parser_get_out (void ); void bibtex_parser_set_out (FILE * out_str ); int bibtex_parser_get_leng (void ); char *bibtex_parser_get_text (void ); int bibtex_parser_get_lineno (void ); void bibtex_parser_set_lineno (int line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. */ #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus extern "C" int bibtex_parser_wrap (void ); #else extern int bibtex_parser_wrap (void ); #endif #endif static void yyunput (int c,char *buf_ptr ); #ifndef yytext_ptr static void yy_flex_strncpy (char *,yyconst char *,int ); #endif #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * ); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void ); #else static int input (void ); #endif #endif /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE #define YY_READ_BUF_SIZE 8192 #endif /* Copy whatever the last rule matched to the standard output. */ #ifndef ECHO /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ #define ECHO fwrite( bibtex_parser_text, bibtex_parser_leng, 1, bibtex_parser_out ) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT #define YY_INPUT(buf,result,max_size) \ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ unsigned n; \ for ( n = 0; n < max_size && \ (c = getc( bibtex_parser_in )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ if ( c == '\n' ) \ buf[n++] = (char) c; \ if ( c == EOF && ferror( bibtex_parser_in ) ) \ YY_FATAL_ERROR( "input in flex scanner failed" ); \ result = n; \ } \ else \ { \ errno=0; \ while ( (result = fread(buf, 1, max_size, bibtex_parser_in))==0 && ferror(bibtex_parser_in)) \ { \ if( errno != EINTR) \ { \ YY_FATAL_ERROR( "input in flex scanner failed" ); \ break; \ } \ errno=0; \ clearerr(bibtex_parser_in); \ } \ }\ \ #endif /* No semi-colon after return; correct usage is to write "yyterminate();" - * we don't want an extra ';' after the "return" because that will cause * some compilers to complain about unreachable statements. */ #ifndef yyterminate #define yyterminate() return YY_NULL #endif /* Number of entries by which start-condition stack grows. */ #ifndef YY_START_STACK_INCR #define YY_START_STACK_INCR 25 #endif /* Report a fatal error. */ #ifndef YY_FATAL_ERROR #define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) #endif /* end tables serialization structures and prototypes */ /* Default declaration of generated scanner - a define so the user can * easily add parameters. */ #ifndef YY_DECL #define YY_DECL_IS_OURS 1 extern int bibtex_parser_lex (void); #define YY_DECL int bibtex_parser_lex (void) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after bibtex_parser_text and bibtex_parser_leng * have been set up. */ #ifndef YY_USER_ACTION #define YY_USER_ACTION #endif /* Code executed at the end of each rule. */ #ifndef YY_BREAK #define YY_BREAK break; #endif #define YY_RULE_SETUP \ if ( bibtex_parser_leng > 0 ) \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ (bibtex_parser_text[bibtex_parser_leng - 1] == '\n'); \ YY_USER_ACTION /** The main scanner function which does all the work. */ YY_DECL { register yy_state_type yy_current_state; register char *yy_cp, *yy_bp; register int yy_act; #line 50 "biblex.l" if (YY_START == INITIAL) { BEGIN(comment); } #line 734 "lex.bibtex_parser_.c" if ( !(yy_init) ) { (yy_init) = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif /* Create the reject buffer large enough to save one state per allowed character. */ if ( ! (yy_state_buf) ) (yy_state_buf) = (yy_state_type *)bibtex_parser_alloc(YY_STATE_BUF_SIZE ); if ( ! (yy_state_buf) ) YY_FATAL_ERROR( "out of dynamic memory in bibtex_parser_lex()" ); if ( ! (yy_start) ) (yy_start) = 1; /* first start state */ if ( ! bibtex_parser_in ) bibtex_parser_in = stdin; if ( ! bibtex_parser_out ) bibtex_parser_out = stdout; if ( ! YY_CURRENT_BUFFER ) { bibtex_parser_ensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = bibtex_parser__create_buffer(bibtex_parser_in,YY_BUF_SIZE ); } bibtex_parser__load_buffer_state( ); } while ( 1 ) /* loops until end-of-file is reached */ { yy_cp = (yy_c_buf_p); /* Support of bibtex_parser_text. */ *yy_cp = (yy_hold_char); /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; yy_current_state = (yy_start); yy_current_state += YY_AT_BOL(); (yy_state_ptr) = (yy_state_buf); *(yy_state_ptr)++ = yy_current_state; yy_match: do { register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 29 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; *(yy_state_ptr)++ = yy_current_state; ++yy_cp; } while ( yy_base[yy_current_state] != 50 ); yy_find_action: yy_current_state = *--(yy_state_ptr); (yy_lp) = yy_accept[yy_current_state]; find_rule: /* we branch to this label when backing up */ for ( ; ; ) /* until we find what rule we matched */ { if ( (yy_lp) && (yy_lp) < yy_accept[yy_current_state + 1] ) { yy_act = yy_acclist[(yy_lp)]; { (yy_full_match) = yy_cp; break; } } --yy_cp; yy_current_state = *--(yy_state_ptr); (yy_lp) = yy_accept[yy_current_state]; } YY_DO_BEFORE_ACTION; do_action: /* This label is used only to access EOF actions. */ switch ( yy_act ) { /* beginning of action switch */ case 1: YY_RULE_SETUP #line 53 "biblex.l" BEGIN(entry); return ('@'); /* Match begin of entry */ YY_BREAK case 2: /* rule 2 can match eol */ YY_RULE_SETUP #line 55 "biblex.l" bibtex_next_line (); /* Increment line number */ YY_BREAK case 3: YY_RULE_SETUP #line 57 "biblex.l" YY_BREAK case YY_STATE_EOF(comment): case YY_STATE_EOF(entry): #line 60 "biblex.l" { /* Indicate EOF */ return (end_of_file); } YY_BREAK case 4: /* rule 4 can match eol */ YY_RULE_SETUP #line 65 "biblex.l" { /* Gestion du caractere \ */ bibtex_parser_lval.text = g_strdup (bibtex_parser_text); bibtex_tmp_string (bibtex_parser_lval.text); return (L_COMMAND); } YY_BREAK case 5: YY_RULE_SETUP #line 74 "biblex.l" { if (bibtex_parser_is_content) { /* Word in the text */ bibtex_parser_lval.text = bibtex_tmp_string (g_strdup (bibtex_parser_text)); return L_BODY; } /* Don't parse it if we are not inside a text field */ current_source->offset -= bibtex_parser_leng; REJECT; } YY_BREAK case 6: /* rule 6 can match eol */ YY_RULE_SETUP #line 88 "biblex.l" { /* Spaces handling */ char * tmp = bibtex_parser_text; while (* tmp) { if (* tmp == '\n') bibtex_next_line (); tmp ++; } if (bibtex_parser_is_content) { /* Is it an unbreakable space ? */ if (strcmp (bibtex_parser_text, "~") == 0) { return L_UBSPACE; } return L_SPACE; } } YY_BREAK case 7: YY_RULE_SETUP #line 107 "biblex.l" { /* Lecture d'un nombre */ bibtex_parser_lval.text = g_strdup (bibtex_parser_text); bibtex_tmp_string (bibtex_parser_lval.text); return (L_DIGIT); } YY_BREAK case 8: YY_RULE_SETUP #line 117 "biblex.l" { /* Lecture d'un nom simple */ bibtex_parser_lval.text = g_strdup (bibtex_parser_text); bibtex_tmp_string (bibtex_parser_lval.text); return (L_NAME); } YY_BREAK case 9: YY_RULE_SETUP #line 126 "biblex.l" { return bibtex_parser_text [0]; } YY_BREAK case 10: YY_RULE_SETUP #line 129 "biblex.l" ECHO; YY_BREAK #line 938 "lex.bibtex_parser_.c" case YY_STATE_EOF(INITIAL): yyterminate(); case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ *yy_cp = (yy_hold_char); YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) { /* We're scanning a new file or input source. It's * possible that this happened because the user * just pointed bibtex_parser_in at a new source and called * bibtex_parser_lex(). If so, then we have to assure * consistency between YY_CURRENT_BUFFER and our * globals. Here is the right place to do so, because * this is the first action (other than possibly a * back-up) that will match for the new input source. */ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; YY_CURRENT_BUFFER_LVALUE->yy_input_file = bibtex_parser_in; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } /* Note that here we test for yy_c_buf_p "<=" to the position * of the first EOB in the buffer, since yy_c_buf_p will * already have been incremented past the NUL character * (since all states make transitions on EOB to the * end-of-buffer state). Contrast this with the test * in input(). */ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) { /* This was really a NUL. */ yy_state_type yy_next_state; (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; yy_current_state = yy_get_previous_state( ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have * yy_get_previous_state() go ahead and do it * for us because it doesn't know how to deal * with the possibility of jamming (and we don't * want to build jamming into it because then it * will run more slowly). */ yy_next_state = yy_try_NUL_trans( yy_current_state ); yy_bp = (yytext_ptr) + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ yy_cp = ++(yy_c_buf_p); yy_current_state = yy_next_state; goto yy_match; } else { yy_cp = (yy_c_buf_p); goto yy_find_action; } } else switch ( yy_get_next_buffer( ) ) { case EOB_ACT_END_OF_FILE: { (yy_did_buffer_switch_on_eof) = 0; if ( bibtex_parser_wrap( ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up * bibtex_parser_text, we can now set up * yy_c_buf_p so that if some total * hoser (like flex itself) wants to * call the scanner after we return the * YY_NULL, it'll still work - another * YY_NULL will get returned. */ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; } else { if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; yy_current_state = yy_get_previous_state( ); yy_cp = (yy_c_buf_p); yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: (yy_c_buf_p) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; yy_current_state = yy_get_previous_state( ); yy_cp = (yy_c_buf_p); yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_find_action; } break; } default: YY_FATAL_ERROR( "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ } /* end of bibtex_parser_lex */ /* yy_get_next_buffer - try to read in a new buffer * * Returns a code representing an action: * EOB_ACT_LAST_MATCH - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ static int yy_get_next_buffer (void) { register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; register char *source = (yytext_ptr); register int number_to_move, i; int ret_val; if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. */ return EOB_ACT_END_OF_FILE; } else { /* We matched some text prior to the EOB, first * process it. */ return EOB_ACT_LAST_MATCH; } } /* Try to read more data. */ /* First move last chars to start of buffer. */ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; else { int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) { /* Not enough room in the buffer - grow it. */ YY_FATAL_ERROR( "input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); } if ( num_to_read > YY_READ_BUF_SIZE ) num_to_read = YY_READ_BUF_SIZE; /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), (yy_n_chars), (size_t) num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } if ( (yy_n_chars) == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; bibtex_parser_restart(bibtex_parser_in ); } else { ret_val = EOB_ACT_LAST_MATCH; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; } } else ret_val = EOB_ACT_CONTINUE_SCAN; if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) bibtex_parser_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } (yy_n_chars) += number_to_move; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ static yy_state_type yy_get_previous_state (void) { register yy_state_type yy_current_state; register char *yy_cp; yy_current_state = (yy_start); yy_current_state += YY_AT_BOL(); (yy_state_ptr) = (yy_state_buf); *(yy_state_ptr)++ = yy_current_state; for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 29 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; *(yy_state_ptr)++ = yy_current_state; } return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character * * synopsis * next_state = yy_try_NUL_trans( current_state ); */ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { register int yy_is_jam; register YY_CHAR yy_c = 1; while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 29 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_is_jam = (yy_current_state == 28); if ( ! yy_is_jam ) *(yy_state_ptr)++ = yy_current_state; return yy_is_jam ? 0 : yy_current_state; } static void yyunput (int c, register char * yy_bp ) { register char *yy_cp; yy_cp = (yy_c_buf_p); /* undo effects of setting up bibtex_parser_text */ *yy_cp = (yy_hold_char); if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ register int number_to_move = (yy_n_chars) + 2; register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; register char *source = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) *--dest = *--source; yy_cp += (int) (dest - source); yy_bp += (int) (dest - source); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) YY_FATAL_ERROR( "flex scanner push-back overflow" ); } *--yy_cp = (char) c; (yytext_ptr) = yy_bp; (yy_hold_char) = *yy_cp; (yy_c_buf_p) = yy_cp; } #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void) #else static int input (void) #endif { int c; *(yy_c_buf_p) = (yy_hold_char); if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) /* This was really a NUL. */ *(yy_c_buf_p) = '\0'; else { /* need more input */ int offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() * sees that we've accumulated a * token and flags that we need to * try matching the token before * proceeding. But for input(), * there's no matching to consider. * So convert the EOB_ACT_LAST_MATCH * to EOB_ACT_END_OF_FILE. */ /* Reset buffer status. */ bibtex_parser_restart(bibtex_parser_in ); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { if ( bibtex_parser_wrap( ) ) return EOF; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; #ifdef __cplusplus return yyinput(); #else return input(); #endif } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + offset; break; } } } c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ *(yy_c_buf_p) = '\0'; /* preserve bibtex_parser_text */ (yy_hold_char) = *++(yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); return c; } #endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. * * @note This function does not reset the start condition to @c INITIAL . */ void bibtex_parser_restart (FILE * input_file ) { if ( ! YY_CURRENT_BUFFER ){ bibtex_parser_ensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = bibtex_parser__create_buffer(bibtex_parser_in,YY_BUF_SIZE ); } bibtex_parser__init_buffer(YY_CURRENT_BUFFER,input_file ); bibtex_parser__load_buffer_state( ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. * */ void bibtex_parser__switch_to_buffer (YY_BUFFER_STATE new_buffer ) { /* TODO. We should be able to replace this entire function body * with * bibtex_parser_pop_buffer_state(); * bibtex_parser_push_buffer_state(new_buffer); */ bibtex_parser_ensure_buffer_stack (); if ( YY_CURRENT_BUFFER == new_buffer ) return; if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } YY_CURRENT_BUFFER_LVALUE = new_buffer; bibtex_parser__load_buffer_state( ); /* We don't actually know whether we did this switch during * EOF (bibtex_parser_wrap()) processing, but the only time this flag * is looked at is after bibtex_parser_wrap() is called, so it's safe * to go ahead and always set it. */ (yy_did_buffer_switch_on_eof) = 1; } static void bibtex_parser__load_buffer_state (void) { (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; bibtex_parser_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file; (yy_hold_char) = *(yy_c_buf_p); } /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. * * @return the allocated buffer state. */ YY_BUFFER_STATE bibtex_parser__create_buffer (FILE * file, int size ) { YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) bibtex_parser_alloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in bibtex_parser__create_buffer()" ); b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (char *) bibtex_parser_alloc(b->yy_buf_size + 2 ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in bibtex_parser__create_buffer()" ); b->yy_is_our_buffer = 1; bibtex_parser__init_buffer(b,file ); return b; } /** Destroy the buffer. * @param b a buffer created with bibtex_parser__create_buffer() * */ void bibtex_parser__delete_buffer (YY_BUFFER_STATE b ) { if ( ! b ) return; if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) bibtex_parser_free((void *) b->yy_ch_buf ); bibtex_parser_free((void *) b ); } #ifndef __cplusplus extern int isatty (int ); #endif /* __cplusplus */ /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a bibtex_parser_restart() or at EOF. */ static void bibtex_parser__init_buffer (YY_BUFFER_STATE b, FILE * file ) { int oerrno = errno; bibtex_parser__flush_buffer(b ); b->yy_input_file = file; b->yy_fill_buffer = 1; /* If b is the current buffer, then bibtex_parser__init_buffer was _probably_ * called from bibtex_parser_restart() or through yy_get_next_buffer. * In that case, we don't want to reset the lineno or column. */ if (b != YY_CURRENT_BUFFER){ b->yy_bs_lineno = 1; b->yy_bs_column = 0; } b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. * */ void bibtex_parser__flush_buffer (YY_BUFFER_STATE b ) { if ( ! b ) return; b->yy_n_chars = 0; /* We always need two end-of-buffer characters. The first causes * a transition to the end-of-buffer state. The second causes * a jam in that state. */ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; b->yy_buf_pos = &b->yy_ch_buf[0]; b->yy_at_bol = 1; b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) bibtex_parser__load_buffer_state( ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. * */ void bibtex_parser_push_buffer_state (YY_BUFFER_STATE new_buffer ) { if (new_buffer == NULL) return; bibtex_parser_ensure_buffer_stack(); /* This block is copied from bibtex_parser__switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) (yy_buffer_stack_top)++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from bibtex_parser__switch_to_buffer. */ bibtex_parser__load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * */ void bibtex_parser_pop_buffer_state (void) { if (!YY_CURRENT_BUFFER) return; bibtex_parser__delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; if ((yy_buffer_stack_top) > 0) --(yy_buffer_stack_top); if (YY_CURRENT_BUFFER) { bibtex_parser__load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ static void bibtex_parser_ensure_buffer_stack (void) { int num_to_alloc; if (!(yy_buffer_stack)) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; (yy_buffer_stack) = (struct yy_buffer_state**)bibtex_parser_alloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in bibtex_parser_ensure_buffer_stack()" ); memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; } if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)bibtex_parser_realloc ((yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state*) ); if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in bibtex_parser_ensure_buffer_stack()" ); /* zero only the new slots.*/ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; } } /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE bibtex_parser__scan_buffer (char * base, yy_size_t size ) { YY_BUFFER_STATE b; if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ return 0; b = (YY_BUFFER_STATE) bibtex_parser_alloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in bibtex_parser__scan_buffer()" ); b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; b->yy_input_file = 0; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; bibtex_parser__switch_to_buffer(b ); return b; } /** Setup the input buffer state to scan a string. The next call to bibtex_parser_lex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * bibtex_parser__scan_bytes() instead. */ YY_BUFFER_STATE bibtex_parser__scan_string (yyconst char * yystr ) { return bibtex_parser__scan_bytes(yystr,strlen(yystr) ); } /** Setup the input buffer state to scan the given bytes. The next call to bibtex_parser_lex() will * scan from a @e copy of @a bytes. * @param bytes the byte buffer to scan * @param len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE bibtex_parser__scan_bytes (yyconst char * yybytes, int _yybytes_len ) { YY_BUFFER_STATE b; char *buf; yy_size_t n; int i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; buf = (char *) bibtex_parser_alloc(n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in bibtex_parser__scan_bytes()" ); for ( i = 0; i < _yybytes_len; ++i ) buf[i] = yybytes[i]; buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; b = bibtex_parser__scan_buffer(buf,n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in bibtex_parser__scan_bytes()" ); /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. */ b->yy_is_our_buffer = 1; return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif static void yy_fatal_error (yyconst char* msg ) { (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless #define yyless(n) \ do \ { \ /* Undo effects of setting up bibtex_parser_text. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ bibtex_parser_text[bibtex_parser_leng] = (yy_hold_char); \ (yy_c_buf_p) = bibtex_parser_text + yyless_macro_arg; \ (yy_hold_char) = *(yy_c_buf_p); \ *(yy_c_buf_p) = '\0'; \ bibtex_parser_leng = yyless_macro_arg; \ } \ while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ /** Get the current line number. * */ int bibtex_parser_get_lineno (void) { return bibtex_parser_lineno; } /** Get the input stream. * */ FILE *bibtex_parser_get_in (void) { return bibtex_parser_in; } /** Get the output stream. * */ FILE *bibtex_parser_get_out (void) { return bibtex_parser_out; } /** Get the length of the current token. * */ int bibtex_parser_get_leng (void) { return bibtex_parser_leng; } /** Get the current token. * */ char *bibtex_parser_get_text (void) { return bibtex_parser_text; } /** Set the current line number. * @param line_number * */ void bibtex_parser_set_lineno (int line_number ) { bibtex_parser_lineno = line_number; } /** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. * * @see bibtex_parser__switch_to_buffer */ void bibtex_parser_set_in (FILE * in_str ) { bibtex_parser_in = in_str ; } void bibtex_parser_set_out (FILE * out_str ) { bibtex_parser_out = out_str ; } int bibtex_parser_get_debug (void) { return bibtex_parser__flex_debug; } void bibtex_parser_set_debug (int bdebug ) { bibtex_parser__flex_debug = bdebug ; } static int yy_init_globals (void) { /* Initialization is the same as for the non-reentrant scanner. * This function is called from bibtex_parser_lex_destroy(), so don't allocate here. */ (yy_buffer_stack) = 0; (yy_buffer_stack_top) = 0; (yy_buffer_stack_max) = 0; (yy_c_buf_p) = (char *) 0; (yy_init) = 0; (yy_start) = 0; (yy_state_buf) = 0; (yy_state_ptr) = 0; (yy_full_match) = 0; (yy_lp) = 0; /* Defined in main.c */ #ifdef YY_STDINIT bibtex_parser_in = stdin; bibtex_parser_out = stdout; #else bibtex_parser_in = (FILE *) 0; bibtex_parser_out = (FILE *) 0; #endif /* For future reference: Set errno on error, since we are called by * bibtex_parser_lex_init() */ return 0; } /* bibtex_parser_lex_destroy is for both reentrant and non-reentrant scanners. */ int bibtex_parser_lex_destroy (void) { /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ bibtex_parser__delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; bibtex_parser_pop_buffer_state(); } /* Destroy the stack itself. */ bibtex_parser_free((yy_buffer_stack) ); (yy_buffer_stack) = NULL; bibtex_parser_free ( (yy_state_buf) ); (yy_state_buf) = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * bibtex_parser_lex() is called, initialization will occur. */ yy_init_globals( ); return 0; } /* * Internal utility routines. */ #ifndef yytext_ptr static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) { register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * s ) { register int n; for ( n = 0; s[n]; ++n ) ; return n; } #endif void *bibtex_parser_alloc (yy_size_t size ) { return (void *) malloc( size ); } void *bibtex_parser_realloc (void * ptr, yy_size_t size ) { /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter * because both ANSI C and C++ allow castless assignment from * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ return (void *) realloc( (char *) ptr, size ); } void bibtex_parser_free (void * ptr ) { free( (char *) ptr ); /* see bibtex_parser_realloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" #line 129 "biblex.l" /* Start the parser on the specified source */ void bibtex_parser_initialize (BibtexSource * source) { g_return_if_fail (source != NULL); /* Destroy old buffer */ if (source->buffer) { bibtex_parser__delete_buffer ((YY_BUFFER_STATE) source->buffer); } switch (source->type) { case BIBTEX_SOURCE_FILE: source->buffer = (gpointer) bibtex_parser__create_buffer (source->source.file, 1024); break; case BIBTEX_SOURCE_STRING: source->buffer = (gpointer) bibtex_parser__scan_string (source->source.string); break; default: g_warning ("scanning nothing !"); source->buffer = NULL; } } /* Continue parsing on the next entry */ void bibtex_parser_continue (BibtexSource * source) { g_return_if_fail (source != NULL); current_source = source; bibtex_parser__switch_to_buffer ((YY_BUFFER_STATE) source->buffer); BEGIN (INITIAL); } /* Parsing is over */ void bibtex_parser_finish (BibtexSource * source) { g_return_if_fail (source != NULL); if (source->buffer) { bibtex_parser__delete_buffer ((YY_BUFFER_STATE) source->buffer); source->buffer = NULL; } } python-bibtex-1.2.5/author.c0000664000076400007640000003233211336332226015041 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: author.c,v 1.1.2.2 2003/09/02 14:35:33 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "bibtex.h" /* -------------------------------------------------- Simple allocation / desallocation mechanism -------------------------------------------------- */ BibtexAuthorGroup * bibtex_author_group_new (void) { return g_array_new (FALSE, FALSE, sizeof (BibtexAuthor)); } void bibtex_author_group_destroy (BibtexAuthorGroup * group) { int i; BibtexAuthor * field; g_return_if_fail (group != NULL); for (i = 0; i < group->len; i++) { field = & g_array_index (group, BibtexAuthor, i); if (field->last) { g_free (field->last); } if (field->first) { g_free (field->first); } if (field->lineage) { g_free (field->lineage); } if (field->honorific) { g_free (field->honorific); } } g_array_free (group, TRUE); } BibtexAuthor * bibtex_author_new (void) { BibtexAuthor * field; field = g_new (BibtexAuthor, 1); field->last = NULL; field->first = NULL; field->lineage = NULL; field->honorific = NULL; return field; } void bibtex_author_destroy (BibtexAuthor * field) { g_return_if_fail (field != NULL); if (field->last) { g_free (field->last); } if (field->first) { g_free (field->first); } if (field->lineage) { g_free (field->lineage); } if (field->honorific) { g_free (field->honorific); } g_free (field); } /* -------------------------------------------------- Here comes the ugly code that decyphers and capitalizes an author group... still needs some work ! -------------------------------------------------- */ typedef struct { gchar * text; guint level; } BTGroup; static GMemChunk * chunk = NULL; static BTGroup * btgroup_new (gchar * text, guint level) { BTGroup * group; if (chunk == NULL) { chunk = g_mem_chunk_new ("BTGroup", sizeof (BTGroup), sizeof (BTGroup) * 16, G_ALLOC_AND_FREE); } group = g_chunk_new (BTGroup, chunk); group->text = text; group->level = level; return group; } static void btgroup_destroy (BTGroup * group) { g_chunk_free (group, chunk); } /* this function adds the comma separated blocks to the token list */ static GList * split_spaces (GList * tokens, gchar * data, guint level) { gchar * text, * courant, sep; gboolean one = TRUE; text = data; courant = data; while ((text = strchr (text, ',')) != NULL) { one = FALSE; sep = * text; * text = '\0'; if (strlen (courant) > 0) { tokens = g_list_append (tokens, btgroup_new (g_strdup (courant), level)); } tokens = g_list_append (tokens, btgroup_new (g_strdup (","), level)); * text = sep; text ++; courant = text; } if (strlen (courant) > 0) { tokens = g_list_append (tokens, btgroup_new (g_strdup (courant), level)); } return tokens; } /* This function takes a BibtexStruct and splits it into pieces (separate words, ponctuation, sub-groups...) */ static GList * tokenify (GList * tokens, BibtexStruct * s, guint level, GHashTable * dico) { GList * tmp; gchar * text, * courant; BibtexStruct * tmp_s; /* Aux niveaux plus élevés, on considère les données d'un bloc */ if (level > 1) { text = bibtex_struct_as_string (s, BIBTEX_OTHER, dico, NULL); tokens = g_list_append (tokens, btgroup_new (text, level)); return tokens; } switch (s->type) { case BIBTEX_STRUCT_LIST: tmp = s->value.list; while (tmp != NULL) { tmp_s = (BibtexStruct *) tmp->data; tmp = tmp->next; /* Deal with eventual commands */ switch (tmp_s->type) { case BIBTEX_STRUCT_COMMAND: courant = bibtex_accent_string (tmp_s, & tmp, NULL); tokens = split_spaces (tokens, courant, level); g_free (courant); break; default: tokens = tokenify (tokens, tmp_s, level, dico); break; } } break; case BIBTEX_STRUCT_TEXT: tokens = split_spaces (tokens, s->value.text, level); break; case BIBTEX_STRUCT_SPACE: tokens = g_list_append (tokens, btgroup_new (g_strdup (" "), level)); break; case BIBTEX_STRUCT_REF: tmp_s = (BibtexStruct *) g_hash_table_lookup (dico, s->value.ref); if (tmp_s) { tokens = tokenify (tokens, tmp_s, level, dico); } break; case BIBTEX_STRUCT_SUB: tokens = tokenify (tokens, s->value.sub->content, level + 1, dico); break; case BIBTEX_STRUCT_COMMAND: /* Normally, commands have been considered in STRUCT_LIST */ return NULL; break; default: g_assert_not_reached (); break; } return tokens; } static void text_free (gpointer data, gpointer user) { BTGroup * group; group = (BTGroup *) data; g_free (group->text); btgroup_destroy (group); } void extract_author (BibtexAuthorGroup * authors, GList * aut_elem) { #define SECTION_LENGTH 4 GList * tmp; gchar * text; BibtexAuthor * author; gint i; gint sections, comas; GPtrArray * section [SECTION_LENGTH], * array; BTGroup * group; gint lastname_section; /* Room for the new author */ g_array_set_size (authors, authors->len + 1); author = & g_array_index (authors, BibtexAuthor, authors->len - 1); author->first = NULL; author->last = NULL; author->honorific = NULL; author->lineage = NULL; for (i = 0; i < SECTION_LENGTH; i ++) { section [i] = g_ptr_array_new (); } /* count the , */ tmp = aut_elem; comas = 0; while (tmp) { group = (BTGroup *) tmp->data; text = group->text; tmp = tmp->next; /* Check for , syntax */ if (strcmp (",", text) == 0) { comas ++; } } /* g_message ("%d comas", comas); */ /* Parse the list into several groups */ tmp = aut_elem; array = section [0]; sections = 0; lastname_section = -1; while (tmp) { group = (BTGroup *) tmp->data; text = group->text; tmp = tmp->next; /* Check for , syntax */ if (strcmp (",", text) == 0) { /* skip eventual empty sections */ if (array->len) { sections ++; /* only consider the 3 first sections */ if (sections < SECTION_LENGTH) array = section [sections]; } lastname_section = -1; continue; } /* If we have the particule in lowercase */ if (group->level == 1 && comas == 0 && islower (text [0]) && sections > 0 && lastname_section == -1) { if (array->len) { sections ++; /* only consider the 3 first sections */ if (sections < SECTION_LENGTH) array = section [sections]; } lastname_section = sections; g_strdown (text); g_ptr_array_add (array, text); continue; } /* default, add new text */ g_ptr_array_add (array, text); } /* Compact the sections to skip the empty ones. Intermediate sections are already compressed. we only have to check the last one. */ if (array->len == 0) { sections --; comas --; } if (sections < comas) { comas = sections; } if (sections < 0) { /* no definition here, skip this author */ bibtex_warning ("empty author definition"); for (i = 0; i < SECTION_LENGTH; i ++) { g_ptr_array_free (section [i], TRUE); } g_array_set_size (authors, authors->len - 1); return; } switch (comas) { case 1: /* Format: , */ g_ptr_array_add (section [0], NULL); g_ptr_array_add (section [1], NULL); author->last = g_strjoinv (" ", (gchar **) section [0]->pdata); if (section [1]->len > 1) { author->first = g_strjoinv (" ", (gchar **) section [1]->pdata); } break; case 0: /* Format: [von|de|du|del] */ /* If there is no lowercase word indicating the last name */ if (lastname_section == -1) { /* simply take the last word of the first sequence */ g_ptr_array_add(section[1], g_ptr_array_index(section[0], section[0]->len-1)); g_ptr_array_index(section[0], section[0]->len-1) = NULL; lastname_section = 1; } else { g_ptr_array_add(section[0], NULL); } g_ptr_array_add(section[1], NULL); if (section[0]->len > 1) { author->first = g_strjoinv(" ", (gchar**)section[0]->pdata); } author->last = g_strjoinv(" ", (gchar**)section[lastname_section]->pdata); break; case 2: /* Format: , , */ g_ptr_array_add (section [0], NULL); g_ptr_array_add (section [1], NULL); g_ptr_array_add (section [2], NULL); author->last = g_strjoinv (" ", (gchar **) section [0]->pdata); author->lineage = g_strjoinv (" ", (gchar **) section [1]->pdata); author->first = g_strjoinv (" ", (gchar **) section [2]->pdata); break; default: /* too many comas... */ bibtex_warning ("too many comas in author definition"); g_ptr_array_add (section [0], NULL); g_ptr_array_add (section [1], NULL); author->last = g_strjoinv (" ", (gchar **) section [0]->pdata); if (section [1]->len > 1) { author->first = g_strjoinv (" ", (gchar **) section [1]->pdata); } break; } for (i = 0; i < SECTION_LENGTH; i ++) { g_ptr_array_free (section [i], TRUE); } } BibtexAuthorGroup * bibtex_author_parse (BibtexStruct * s, GHashTable * dico) { GList * list = NULL, * toremove; BibtexAuthorGroup * authors; GList * tokens, * aut_elem; gchar * text; gboolean skip; GList * target; BTGroup * group, * tmp_g; gboolean compact, first_pass; g_return_val_if_fail (s != NULL, NULL); authors = bibtex_author_group_new (); /* -------------------------------------------------- Split into elementary tokens -------------------------------------------------- */ tokens = tokenify (NULL, s, 0, dico); list = tokens; while (list) { group = (BTGroup *) list->data; list = list->next; } /* -------------------------------------------------- Compact the strings as much as possible -------------------------------------------------- */ compact = FALSE; first_pass = TRUE; while (! compact) { compact = TRUE; list = tokens; toremove = NULL; skip = TRUE; target = NULL; /* For every token... */ while (list) { group = (BTGroup *) list->data; text = group->text; /* Skip and remove spaces */ if (strcmp (" ", text) == 0) { skip = TRUE; list = list->next; continue; } /* Skip commas */ if (strcmp (",", text) == 0) { skip = TRUE; list = list->next; continue; } /* Merge non separated entries */ if (! skip) { compact = FALSE; toremove = g_list_append (toremove, group); g_assert (target != NULL); /* Update data */ tmp_g = (BTGroup *) target->data; target->data = btgroup_new (g_strconcat (tmp_g->text, text, NULL), group->level); btgroup_destroy (tmp_g); list = list->next; } else { /* Get next entry */ skip = FALSE; target = list; list = list->next; } } /* If there has been no compacting, remove spaces */ if (compact) { list = tokens; /* For every token... */ while (list) { group = (BTGroup *) list->data; text = group->text; if (strcmp (" ", text) == 0) { toremove = g_list_append (toremove, group); } list = list->next; } } /* Remove items no more used */ list = toremove; while (list) { /* Remove current from list */ tokens = g_list_remove (tokens, list->data); text_free (list->data, NULL); list = list->next; } g_list_free (toremove); /* ...and eventually start again */ first_pass = FALSE; } /* -------------------------------------------------- Heuristic to extract authors... -------------------------------------------------- */ aut_elem = NULL; list = tokens; while (list) { group = (BTGroup *) list->data; text = group->text; list = list->next; if (g_strcasecmp (text, "and") == 0) { if (aut_elem == NULL) { bibtex_warning ("double `and' in author field"); } else { extract_author (authors, aut_elem); g_list_free (aut_elem); aut_elem = NULL; } } else { aut_elem = g_list_append (aut_elem, group); } } /* Extract last author */ if (aut_elem == NULL) { bibtex_warning ("`and' at end of author field"); } else { extract_author (authors, aut_elem); g_list_free (aut_elem); } g_list_foreach (tokens, text_free, NULL); g_list_free (tokens); return authors; } python-bibtex-1.2.5/PKG-INFO0000664000076400007640000000112511416711604014464 0ustar zkotazkotaMetadata-Version: 1.0 Name: python-bibtex Version: 1.2.5 Summary: A Python extension to parse BibTeX files Home-page: http://pybliographer.org/ Author: Frederic Gobry Author-email: gobry@pybliographer.org License: GPL Description: This module contains two extensions needed for pybliographer: - a bibtex parser - a simple binding to GNU Recode It requires the following libraries to be installed: - Glib-2.0 (and its development headers) - GNU Recode 3.5 (and its development headers) Platform: UNKNOWN python-bibtex-1.2.5/accents.c0000664000076400007640000001623711336332226015165 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: accents.c,v 1.1.2.2 2003/09/02 14:35:33 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "bibtex.h" typedef struct { gchar c; gchar m; } CharMapping; typedef struct { gchar * c; gchar * m; } StringMapping; CharMapping acute [] = { {'A', 'Á'}, {'E', 'É'}, {'I', 'Í'}, {'O', 'Ó'}, {'U', 'Ú'}, {'Y', 'Ý'}, {'a', 'á'}, {'e', 'é'}, {'i', 'í'}, {'o', 'ó'}, {'u', 'ú'}, {'y', 'ý'}, {0, 0} }; CharMapping grave [] = { {'A', 'À'}, {'E', 'È'}, {'I', 'Ì'}, {'O', 'Ò'}, {'U', 'Ù'}, {'a', 'à'}, {'e', 'è'}, {'i', 'ì'}, {'o', 'ò'}, {'u', 'ù'}, {0, 0} }; CharMapping hat [] = { {'A', 'Â'}, {'E', 'Ê'}, {'I', 'Î'}, {'O', 'Ô'}, {'U', 'Û'}, {'a', 'â'}, {'e', 'ê'}, {'i', 'î'}, {'o', 'ô'}, {'u', 'û'}, {0, 0} }; CharMapping trema [] = { {'A', 'Ä'}, {'E', 'Ë'}, {'I', 'Ï'}, {'O', 'Ö'}, {'U', 'Ü'}, {'a', 'ä'}, {'e', 'ë'}, {'i', 'ï'}, {'o', 'ö'}, {'u', 'ü'}, {'y', 'ÿ'}, {0, 0} }; CharMapping cedilla [] = { {'C', 'Ç'}, {'c', 'ç'}, {0, 0} }; CharMapping tilda [] = { {'A', 'Ã'}, {'O', 'Õ'}, {'a', 'ã'}, {'o', 'õ'}, {'n', 'ñ'}, {'N', 'Ñ'}, {0, 0} }; StringMapping commands [] = { {"backslash", "\\"}, {"S", "§"}, {"ss", "ß"}, {"DH", "Ð"}, {"dh", "ð"}, {"AE", "Æ"}, {"ae", "æ"}, {"O", "Ø"}, {"o", "ø"}, {"TH", "Þ"}, {"th", "þ"}, {"aa", "å"}, {"AA", "Å"}, {"guillemotleft", "«"}, {"guillemotright", "»"}, {"flqq", "«"}, {"frqq", "»"}, {"guilsingleft", "<"}, {"guilsingright", ">"}, {"textquestiondown", "¿"}, {"textexclamdown", "¡"}, {"copyright", "©"}, {"pound", "£"}, {"neg", "¬"}, {"-", "­"}, {"cdotp", "·"}, {",", "¸"}, {NULL, NULL} }; static gchar * initialize_table (CharMapping * map, char empty) { gchar * table; g_return_val_if_fail (map != NULL, NULL); table = g_new0 (gchar, 256); while (map->c != '\0') { table [(int) map->c] = map->m; map ++; } table [0] = empty; return table; } static GHashTable * initialize_mapping (StringMapping * map) { GHashTable * dico; dico = g_hash_table_new (g_str_hash, g_str_equal); while (map->c != NULL) { g_hash_table_insert (dico, map->c, map->m); map ++; } return dico; } static gchar * eat_as_string (GList ** flow, gint qtt, gboolean * loss) { BibtexStruct * tmp_s; gchar * tmp, * text = g_strdup (""); g_return_val_if_fail (qtt > 0, text); if (flow == NULL) { return text; } while (qtt > 0 && (* flow)) { tmp = text; tmp_s = (BibtexStruct *) ((* flow)->data); * flow = (* flow)->next; if (tmp_s->type == BIBTEX_STRUCT_SPACE) continue; qtt --; text = g_strconcat (text, bibtex_struct_as_string (tmp_s, BIBTEX_OTHER, NULL, loss), NULL); g_free (tmp); } return text; } gchar * bibtex_accent_string (BibtexStruct * s, GList ** flow, gboolean * loss) { static gchar * acute_table = NULL; static gchar * grave_table = NULL; static gchar * hat_table = NULL; static gchar * trema_table = NULL; static gchar * cedilla_table = NULL; static gchar * tilda_table = NULL; static GHashTable * commands_table = NULL; gchar * text, * tmp, accent; g_return_val_if_fail (s != NULL, NULL); g_return_val_if_fail (s->type == BIBTEX_STRUCT_COMMAND, NULL); if (acute_table == NULL) { /* Initialize accent table if necessary */ acute_table = initialize_table (acute, '´'); grave_table = initialize_table (grave, '\0'); hat_table = initialize_table (hat, '\0'); trema_table = initialize_table (trema, '¨'); cedilla_table = initialize_table (cedilla, '\0'); tilda_table = initialize_table (tilda, '\0'); commands_table = initialize_mapping (commands); } /* traiter les codes de 1 de long */ if (strlen (s->value.com) == 1) { accent = s->value.com [0]; if (accent == 'i') { return g_strdup ("i"); } /* Is it a known accent ? */ if (accent == '\'' || accent == '^' || accent == '`' || accent == '"' || accent == '~' || accent == 'c') { text = eat_as_string (flow, 1, loss); tmp = NULL; switch (accent) { case '\'': tmp = acute_table; break; case '`': tmp = grave_table; break; case '^': tmp = hat_table; break; case '"': tmp = trema_table; break; case 'c': tmp = cedilla_table; break; case '~': tmp = tilda_table; break; default: g_assert_not_reached (); break; } /* We know how to convert */ if (tmp [(int) text [0]] != 0) { if (text [0]) { text [0] = tmp [(int) text [0]]; } else { tmp = g_strdup_printf ("%c", tmp [(int)text [0]]); g_free (text); text = tmp; } } else { if (loss) * loss = TRUE; } return text; } else { /* return the single symbol */ if (! isalnum (s->value.com [0])) { return g_strdup (s->value.com); } } } /* if not found, use dictionnary to eventually map */ text = g_hash_table_lookup (commands_table, s->value.com); if (text) { return g_strdup (text); } if (loss) * loss = TRUE; bibtex_warning ("unable to convert `\\%s'", s->value.com); return g_strdup (s->value.com); } void bibtex_capitalize (gchar * text, gboolean is_noun, gboolean at_start) { gboolean begin_of_sentence; gchar * current; g_return_if_fail (text != NULL); /* Put everything lowercase */ if (is_noun) { g_strdown (text); } current = text; begin_of_sentence = at_start; /* Parse the whole text */ while (* current) { switch (* current) { case ' ': /* Skip whitespace */ break; case '-': /* Composed names */ if (is_noun) { begin_of_sentence = TRUE; } break; case '.': /* New sentence */ begin_of_sentence = TRUE; break; default: if (isalpha (* current) && begin_of_sentence) { * current = toupper (* current); begin_of_sentence = FALSE; } break; } current ++; } } python-bibtex-1.2.5/biblex.l0000664000076400007640000000763511336332226015025 0ustar zkotazkota%{ /* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: biblex.l,v 1.1.2.2 2003/09/02 14:35:33 fredgo Exp $ */ /* #include "parsername.h" */ #include #include "bibtex.h" #include "bibparse.h" static BibtexSource * current_source; gboolean bibtex_parser_is_content; extern void bibtex_next_line (void); #define YY_USER_ACTION current_source->offset += bibtex_parser_leng; %} DIGIT [0-9]+ NAME [^ \\\t{}\"@,=%#\n\r~]+ BODY [^{}\\\" \n\t\r~]+ %option noyywrap %x comment entry %% if (YY_START == INITIAL) { BEGIN(comment); } ^[ \t]*@ BEGIN(entry); return ('@'); /* Match begin of entry */ \n bibtex_next_line (); /* Increment line number */ . <> { /* Indicate EOF */ return (end_of_file); } \\([a-zA-Z]+|[^a-zA-Z]) { /* Gestion du caractere \ */ bibtex_parser_lval.text = g_strdup (bibtex_parser_text); bibtex_tmp_string (bibtex_parser_lval.text); return (L_COMMAND); } {BODY} { if (bibtex_parser_is_content) { /* Word in the text */ bibtex_parser_lval.text = bibtex_tmp_string (g_strdup (bibtex_parser_text)); return L_BODY; } /* Don't parse it if we are not inside a text field */ current_source->offset -= bibtex_parser_leng; REJECT; } [ \t\n\r~]+ { /* Spaces handling */ char * tmp = bibtex_parser_text; while (* tmp) { if (* tmp == '\n') bibtex_next_line (); tmp ++; } if (bibtex_parser_is_content) { /* Is it an unbreakable space ? */ if (strcmp (bibtex_parser_text, "~") == 0) { return L_UBSPACE; } return L_SPACE; } } {DIGIT} { /* Lecture d'un nombre */ bibtex_parser_lval.text = g_strdup (bibtex_parser_text); bibtex_tmp_string (bibtex_parser_lval.text); return (L_DIGIT); } {NAME} { /* Lecture d'un nom simple */ bibtex_parser_lval.text = g_strdup (bibtex_parser_text); bibtex_tmp_string (bibtex_parser_lval.text); return (L_NAME); } . { return bibtex_parser_text [0]; } %% /* Start the parser on the specified source */ void bibtex_parser_initialize (BibtexSource * source) { g_return_if_fail (source != NULL); /* Destroy old buffer */ if (source->buffer) { bibtex_parser__delete_buffer ((YY_BUFFER_STATE) source->buffer); } switch (source->type) { case BIBTEX_SOURCE_FILE: source->buffer = (gpointer) bibtex_parser__create_buffer (source->source.file, 1024); break; case BIBTEX_SOURCE_STRING: source->buffer = (gpointer) bibtex_parser__scan_string (source->source.string); break; default: g_warning ("scanning nothing !"); source->buffer = NULL; } } /* Continue parsing on the next entry */ void bibtex_parser_continue (BibtexSource * source) { g_return_if_fail (source != NULL); current_source = source; bibtex_parser__switch_to_buffer ((YY_BUFFER_STATE) source->buffer); BEGIN (INITIAL); } /* Parsing is over */ void bibtex_parser_finish (BibtexSource * source) { g_return_if_fail (source != NULL); if (source->buffer) { bibtex_parser__delete_buffer ((YY_BUFFER_STATE) source->buffer); source->buffer = NULL; } } python-bibtex-1.2.5/logging.h0000664000076400007640000000343611336332226015175 0ustar zkotazkota#ifndef __logging_h__ #define __logging_h__ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #define BIB_LEVEL_ERROR (1 << (G_LOG_LEVEL_USER_SHIFT + 0)) #define BIB_LEVEL_WARNING (1 << (G_LOG_LEVEL_USER_SHIFT + 1)) #define BIB_LEVEL_MESSAGE (1 << (G_LOG_LEVEL_USER_SHIFT + 2)) #ifdef __GNUC__ #define bibtex_error(format, args...) g_log (G_LOG_DOMAIN, \ BIB_LEVEL_ERROR, \ format, ##args) #define bibtex_message(format, args...) g_log (G_LOG_DOMAIN, \ BIB_LEVEL_MESSAGE, \ format, ##args) #define bibtex_warning(format, args...) g_log (G_LOG_DOMAIN, \ BIB_LEVEL_WARNING, \ format, ##args) #else /* !__GNUC__ */ static inline void bibtex_error (const gchar *format, ...) { va_list args; va_start (args, format); g_logv (G_LOG_DOMAIN, BIB_LEVEL_ERROR, format, args); va_end (args); } static inline void bibtex_message (const gchar *format, ...) { va_list args; va_start (args, format); g_logv (G_LOG_DOMAIN, BIB_LEVEL_MESSAGE, format, args); va_end (args); } static inline void bibtex_warning (const gchar *format, ...) { va_list args; va_start (args, format); g_logv (G_LOG_DOMAIN, BIB_LEVEL_WARNING, format, args); va_end (args); } #endif /* !GNUC */ void bibtex_set_default_handler (void); void bibtex_message_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* logging.h */ python-bibtex-1.2.5/struct.c0000664000076400007640000002741211336332226015066 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: struct.c,v 1.1.2.2 2003/09/02 14:35:33 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "bibtex.h" static GMemChunk * struct_chunk = NULL; BibtexStruct * bibtex_struct_new (BibtexStructType type) { BibtexStruct * s; if (struct_chunk == NULL) { struct_chunk = g_mem_chunk_new ("BibtexStruct", sizeof (BibtexStruct), sizeof (BibtexStruct) * 16, G_ALLOC_AND_FREE); } s = g_chunk_new (BibtexStruct, struct_chunk); s->type = type; switch (type) { case BIBTEX_STRUCT_LIST: s->value.list = NULL; break; case BIBTEX_STRUCT_TEXT: s->value.text = NULL; break; case BIBTEX_STRUCT_REF: s->value.ref = NULL; break; case BIBTEX_STRUCT_COMMAND: s->value.com = NULL; break; case BIBTEX_STRUCT_SUB: s->value.sub = g_new (BibtexStructSub, 1); s->value.sub->content = NULL; s->value.sub->encloser = BIBTEX_ENCLOSER_BRACE; break; case BIBTEX_STRUCT_SPACE: s->value.unbreakable = FALSE; break; default: g_assert_not_reached (); } return s; } void bibtex_struct_destroy (BibtexStruct * s, gboolean remove_content) { GList * current; g_return_if_fail (s != NULL); switch (s->type) { case BIBTEX_STRUCT_TEXT: if (remove_content) g_free (s->value.text); break; case BIBTEX_STRUCT_REF: if (remove_content) g_free (s->value.ref); break; case BIBTEX_STRUCT_COMMAND: if (remove_content) g_free (s->value.com); break; case BIBTEX_STRUCT_LIST: if (remove_content) { current = s->value.list; while (current) { bibtex_struct_destroy ((BibtexStruct *) current->data, remove_content); current = current->next; } } g_list_free (s->value.list); break; case BIBTEX_STRUCT_SUB: if (remove_content) bibtex_struct_destroy ((BibtexStruct *) s->value.sub->content, remove_content); g_free (s->value.sub); break; case BIBTEX_STRUCT_SPACE: break; default: g_assert_not_reached (); break; } g_chunk_free (s, struct_chunk); } /* -------------------------------------------------- */ void bibtex_struct_display (BibtexStruct * source) { GList * list; g_return_if_fail (source != NULL); switch (source->type) { case BIBTEX_STRUCT_TEXT: printf ("Text(%s)", source->value.text); break; case BIBTEX_STRUCT_REF: printf ("Ref(%s)", source->value.ref); break; case BIBTEX_STRUCT_COMMAND: printf ("Command(%s)", source->value.com); break; case BIBTEX_STRUCT_SUB: printf ("Sub("); bibtex_struct_display (source->value.sub->content); printf (")"); break; case BIBTEX_STRUCT_LIST: printf ("List("); list = source->value.list; while (list) { bibtex_struct_display ((BibtexStruct *) list->data); list = list->next; } printf (")\n"); break; case BIBTEX_STRUCT_SPACE: printf ("Space()"); break; default: printf ("Argggg(%d)", source->type); } } BibtexStruct * bibtex_struct_copy (BibtexStruct * source) { BibtexStruct * target; GList * list; g_return_val_if_fail (source != NULL, NULL); target = bibtex_struct_new (source->type); switch (source->type) { case BIBTEX_STRUCT_TEXT: target->value.text = g_strdup (source->value.text); break; case BIBTEX_STRUCT_REF: target->value.ref = g_strdup (source->value.ref); break; case BIBTEX_STRUCT_COMMAND: target->value.com = g_strdup (source->value.com); break; case BIBTEX_STRUCT_SUB: target->value.sub->encloser = source->value.sub->encloser; target->value.sub->content = bibtex_struct_copy (source->value.sub->content); break; case BIBTEX_STRUCT_LIST: list = source->value.list; while (list) { target->value.list = g_list_append (target->value.list, bibtex_struct_copy ((BibtexStruct *) list->data)); list = list->next; } break; case BIBTEX_STRUCT_SPACE: target->value.unbreakable = source->value.unbreakable; break; default: g_assert_not_reached (); break; } return target; } BibtexStruct * bibtex_struct_append (BibtexStruct * s1, BibtexStruct * s2) { BibtexStruct * ret; gchar * tmp; if (s1 == NULL && s2 == NULL) return NULL; if (s1 == NULL) return s2; if (s2 == NULL) return s1; if (s1->type == BIBTEX_STRUCT_TEXT && s2->type == BIBTEX_STRUCT_TEXT) { /* Fusion de deux bouts de texte */ tmp = s1->value.text; s1->value.text = g_strconcat (s1->value.text, s2->value.text, NULL); g_free (tmp); bibtex_struct_destroy (s2, TRUE); return (s1); } if (s1->type == BIBTEX_STRUCT_LIST && s2->type == BIBTEX_STRUCT_LIST) { /* Fusion de deux listes simples */ s1->value.list = g_list_concat (s1->value.list, s2->value.list); bibtex_struct_destroy (s2, FALSE); return (s1); } /* One or the other is a list... */ if (s1->type == BIBTEX_STRUCT_LIST) { /* append the second to the first... */ s1->value.list = g_list_append (s1->value.list, s2); return (s1); } if (s2->type == BIBTEX_STRUCT_LIST) { /* append the second to the first... */ s2->value.list = g_list_prepend (s2->value.list, s1); return (s2); } /* Dans le cas general, creer une nouvelle liste contenant seulement les deux elements passes en entree */ ret = bibtex_struct_new (BIBTEX_STRUCT_LIST); ret->value.list = g_list_append (ret->value.list, s1); ret->value.list = g_list_append (ret->value.list, s2); return ret; } static gchar * bibtex_real_string (BibtexStruct * s, BibtexFieldType type, GHashTable * dico, gboolean as_bibtex, gint level, gboolean * loss, gboolean at_beginning, gboolean strip_first_layer, gboolean as_latex) { gchar * text = NULL, * tmp; GList * list; BibtexStruct * tmp_s; gboolean first; GString * string; g_return_val_if_fail (s != NULL, NULL); switch (s->type) { case BIBTEX_STRUCT_SPACE: if (as_bibtex || type == BIBTEX_VERBATIM) { if (s->value.unbreakable) { text = g_strdup ("~"); } else { text = g_strdup (" "); } } else { /* unbreakable spaces are lost */ if (s->value.unbreakable) { if (loss) * loss = TRUE; } text = g_strdup (" "); } break; case BIBTEX_STRUCT_COMMAND: if (as_bibtex) { text = g_strconcat ("\\", s->value.com, NULL); } else { text = bibtex_accent_string (s, NULL, loss); } break; case BIBTEX_STRUCT_TEXT: text = g_strdup (s->value.text); if ((! as_bibtex || as_latex) && level == 1 && type == BIBTEX_TITLE) { if (at_beginning) { text [0] = toupper (text [0]); g_strdown (text + 1); } else { g_strdown (text); } } break; case BIBTEX_STRUCT_REF: g_strdown (s->value.ref); if (as_bibtex && ! as_latex) { text = g_strdup (s->value.ref); } else { if (loss) * loss = TRUE; if (dico) { tmp_s = (BibtexStruct *) g_hash_table_lookup (dico, s->value.ref); if (tmp_s) { text = bibtex_real_string (tmp_s, type, dico, as_bibtex, level, loss, at_beginning, strip_first_layer, as_latex); } else { bibtex_warning ("reference `%s' undefined", s->value.text); text = g_strdup (""); } } else { text = g_strdup (""); } } break; case BIBTEX_STRUCT_LIST: string = g_string_new (""); list = s->value.list; first = TRUE; while (list != NULL) { tmp_s = (BibtexStruct *) list->data; list = list->next; if (! as_bibtex && tmp_s->type == BIBTEX_STRUCT_COMMAND) { /* Passer a la fonction le flot suivant */ tmp = bibtex_accent_string (tmp_s, & list, loss); g_string_append (string, tmp); g_free (tmp); } else { if (level == 0 && as_bibtex && ! first && ! as_latex) { g_string_append (string, " # "); } tmp = bibtex_real_string(tmp_s, type, dico, as_bibtex, level, loss, at_beginning && first, strip_first_layer, as_latex); g_string_append(string, tmp); g_free(tmp); } first = FALSE; } text = string->str; g_string_free (string, FALSE); break; case BIBTEX_STRUCT_SUB: if (as_bibtex) { tmp = bibtex_real_string (s->value.sub->content, type, dico, as_bibtex, /* climb one level if we are in pure bibtex, or if we are in latex and {} */ level + 1, loss, at_beginning, FALSE, as_latex); if (strip_first_layer) { text = tmp; } else { /* As bibtex, add the encloser */ switch (s->value.sub->encloser) { case BIBTEX_ENCLOSER_BRACE: text = g_strdup_printf ("{%s}", tmp); break; case BIBTEX_ENCLOSER_QUOTE: text = g_strdup_printf ("\"%s\"", tmp); break; default: g_assert_not_reached (); break; } g_free (tmp); } } else { /* As simple text, add nothing. */ text = bibtex_real_string (s->value.sub->content, type, dico, as_bibtex, level + 1, loss, at_beginning, FALSE, as_latex); } break; default: g_assert_not_reached (); break; } return text; } BibtexStruct * bibtex_struct_flatten (BibtexStruct * s) { GList * list, * newlist, * tmp; BibtexStruct * tmp_s; gboolean stable; g_return_val_if_fail (s != NULL, NULL); switch (s->type) { case BIBTEX_STRUCT_LIST: /* Aplanir une liste */ stable = FALSE; while (! stable) { stable = TRUE; list = s->value.list; newlist = NULL; while (list) { tmp_s = (BibtexStruct *) list->data; /* Si on trouve une liste dans la liste... */ if (tmp_s->type == BIBTEX_STRUCT_LIST) { /* Il faudra repasser un coup apres... */ stable = FALSE; tmp = tmp_s->value.list; /* Incorporer tous les elements de la deuxieme liste */ while (tmp) { newlist = g_list_append (newlist, tmp->data); tmp = tmp->next; } /* ...et detruire l'ancien element */ bibtex_struct_destroy (tmp_s, FALSE); } else { newlist = g_list_append (newlist, bibtex_struct_flatten (tmp_s)); } list = list->next; } g_list_free (s->value.list); s->value.list = newlist; } break; case BIBTEX_STRUCT_SUB: s->value.sub->content = bibtex_struct_flatten (s->value.sub->content); break; default: break; } return s; } gchar * bibtex_struct_as_string (BibtexStruct * s, BibtexFieldType type, GHashTable * dico, gboolean * loss) { g_return_val_if_fail (s != NULL, NULL); return bibtex_real_string (s, type, dico, FALSE, 0, loss, TRUE, FALSE, FALSE); } gchar * bibtex_struct_as_bibtex (BibtexStruct * s) { g_return_val_if_fail (s != NULL, NULL); return bibtex_real_string (s, BIBTEX_OTHER, NULL, TRUE, 0, NULL, TRUE, FALSE, FALSE); } gchar * bibtex_struct_as_latex (BibtexStruct * s, BibtexFieldType type, GHashTable * dico) { g_return_val_if_fail (s != NULL, NULL); return bibtex_real_string (s, type, dico, TRUE, 0, NULL, TRUE, TRUE, TRUE); } python-bibtex-1.2.5/reverse.c0000664000076400007640000002120411336332226015206 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: reverse.c,v 1.1.2.3 2003/09/10 07:49:58 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #ifdef HAVE_STDBOOL_H #include #else /* ! HAVE_STDBOOL_H */ /* stdbool.h for GNU. */ /* The type `bool' must promote to `int' or `unsigned int'. The constants `true' and `false' must have the value 0 and 1 respectively. */ typedef enum { false = 0, true = 1 } bool; /* The names `true' and `false' must also be made available as macros. */ #define false false #define true true /* Signal that all the definitions are present. */ #define __bool_true_false_are_defined 1 #endif /* HAVE_STDBOOL_H */ #include #include #include "bibtex.h" static BibtexStruct * text_to_struct (gchar * string) { BibtexEntry * entry; BibtexStruct * s; static BibtexSource * source = NULL; if (source == NULL) source = bibtex_source_new (); /* parse as a string */ if (! bibtex_source_string (source, "internal string", string)) { g_error ("can't create string"); } entry = bibtex_source_next_entry (source, FALSE); if (entry == NULL) { bibtex_error ("can't parse entry `%s'", string); return NULL; } s = bibtex_struct_copy (entry->preamble); bibtex_entry_destroy (entry, TRUE); return s; } static gboolean author_needs_quotes (gchar * string) { static gboolean initialized = FALSE; static regex_t and_re; if (! initialized) { initialized = regcomp (& and_re, "[^[:alnum:]]and[^[:alnum:]]", REG_ICASE | REG_EXTENDED) == 0; g_assert (initialized); } return (strpbrk (string, ",") != NULL) || (regexec (& and_re, string, 0,NULL, 0) == 0); } BibtexField * bibtex_reverse_field (BibtexField * field, gboolean use_braces, gboolean do_quote) { BibtexStruct * s = NULL; gchar * string, * tmp; gboolean is_upper, has_space, is_command, was_command; gint i; BibtexAuthor * author; static GString * st = NULL; static RECODE_OUTER outer = NULL; static RECODE_REQUEST request = NULL; g_return_val_if_fail (field != NULL, NULL); if (st == NULL) st = g_string_sized_new (16); if (outer == NULL) { outer = recode_new_outer (false); g_assert (outer != NULL); } if (request == NULL) { request = recode_new_request (outer); g_assert (request != NULL); if (! recode_scan_request (request, "latin1..latex")) { g_error ("can't create recoder"); } } if (field->structure) { bibtex_struct_destroy (field->structure, TRUE); field->structure = NULL; } field->loss = FALSE; switch (field->type) { case BIBTEX_OTHER: case BIBTEX_VERBATIM: g_return_val_if_fail (field->text != NULL, NULL); g_string_truncate (st, 0); if (! use_braces) { if (strchr (field->text, '"')) { use_braces = TRUE; } } if (use_braces) { g_string_append (st, "@preamble{{"); } else { g_string_append (st, "@preamble{\""); } if (do_quote) { tmp = recode_string (request, field->text); g_string_append (st, tmp); g_free (tmp); } else { g_string_append (st, field->text); } if (use_braces) { g_string_append (st, "}}"); } else { g_string_append (st, "\"}"); } s = text_to_struct (st->str); break; case BIBTEX_TITLE: g_return_val_if_fail (field->text != NULL, NULL); g_string_truncate (st, 0); if (! use_braces) { if (strchr (field->text, '"')) { use_braces = TRUE; } } tmp = recode_string (request, field->text); if (use_braces) { g_string_append (st, "@preamble{{"); } else { g_string_append (st, "@preamble{\""); } /* Put the first lower case between {} */ string = tmp; if (* tmp >= 'a' && * tmp <= 'z') { /* Put the beginning in lower cases */ g_string_append_c (st, '{'); g_string_append_c (st, * tmp); g_string_append_c (st, '}'); } else { /* The first character is done */ g_string_append_c (st, * tmp); } tmp ++; /* check for upper cases afterward */ is_upper = false; is_command = false; was_command = false; while (* tmp) { /* start a latex command */ if (* tmp == '\\') { /* eventually closes the bracket */ if (is_upper) { is_upper = false; g_string_append_c (st, '}'); } is_command = true; was_command = false; g_string_append_c (st, * tmp); tmp ++; continue; } if (is_command) { if (! ((* tmp >= 'a' && * tmp <= 'z') || (* tmp >= 'A' && * tmp <= 'Z'))) { is_command = false; was_command = true; } g_string_append_c (st, * tmp); tmp ++; continue; } if (* tmp >= 'A' && * tmp <= 'Z') { if (! is_upper) { g_string_append_c (st, '{'); g_string_append_c (st, * tmp); if (was_command) { g_string_append_c (st, '}'); } else { is_upper = true; } } else { g_string_append_c (st, * tmp); } } else { if (is_upper) { g_string_append_c (st, '}'); is_upper = false; } g_string_append_c (st, * tmp); } was_command = false; tmp ++; } /* eventually close the brackets */ if (is_upper) { g_string_append_c (st, '}'); is_upper = false; } g_free (string); if (use_braces) { g_string_append (st, "}}"); } else { g_string_append (st, "\"}"); } s = text_to_struct (st->str); break; case BIBTEX_AUTHOR: g_return_val_if_fail (field->field.author != NULL, NULL); g_string_truncate (st, 0); /* Create a simple preamble to parse */ if (! use_braces) { for (i = 0 ; i < field->field.author->len; i ++) { author = & g_array_index (field->field.author, BibtexAuthor, i); if (author->last && strchr (author->last, '"')) { use_braces = TRUE; break; } if (author->lineage && strchr (author->lineage, '"')) { use_braces = TRUE; break; } if (author->first && strchr (author->first, '"')) { use_braces = TRUE; break; } } } if (use_braces) { g_string_append (st, "@preamble{{"); } else { g_string_append (st, "@preamble{\""); } for (i = 0 ; i < field->field.author->len; i ++) { author = & g_array_index (field->field.author, BibtexAuthor, i); if (i != 0) { g_string_append (st, " and "); } if (author->last) { /* quotes if there is no first name */ has_space = author_needs_quotes (author->last) || (author->first == NULL && strpbrk (author->last, " \t") != NULL); if (has_space) { g_string_append_c (st, '{'); } tmp = recode_string (request, author->last); g_string_append (st, tmp); g_free (tmp); if (has_space) { g_string_append_c (st, '}'); } } if (author->lineage) { g_string_append (st, ", "); has_space = author_needs_quotes (author->lineage); if (has_space) { g_string_append_c (st, '{'); } tmp = recode_string (request, author->lineage); g_string_append (st, tmp); g_free (tmp); if (has_space) { g_string_append_c (st, '}'); } } if (author->first) { g_string_append (st, ", "); has_space = author_needs_quotes (author->first); if (has_space) { g_string_append_c (st, '{'); } tmp = recode_string (request, author->first); g_string_append (st, tmp); g_free (tmp); if (has_space) { g_string_append_c (st, '}'); } } } if (use_braces) { g_string_append (st, "}}"); } else { g_string_append (st, "\"}"); } s = text_to_struct (st->str); break; case BIBTEX_DATE: s = bibtex_struct_new (BIBTEX_STRUCT_TEXT); s->value.text = g_strdup_printf ("%d", field->field.date.year); break; default: g_assert_not_reached (); } field->structure = s; /* remove text field */ if (field->text) { g_free (field->text); field->text = NULL; field->converted = FALSE; } return field; } python-bibtex-1.2.5/NEWS0000664000076400007640000000070311416706661014076 0ustar zkotazkota-*- charset: utf-8 -*- Version 1.2.5 (2010-07-12) * fixed testsuite Version 1.2.4 (2007-04-23) * fixed bug in escaping non title fields Version 1.2.3 (2007-01-17) * fixed for python 2.5 * fixed parsing of standalone lowercase names, like "others" Version 1.2.2 (2005-10-06) * proper encoding of MÜSLI as M\"{U}{SLI} (closes bug #1224723) * allows handling of @preamble statements * better escaping of verbatim fields, like URLs python-bibtex-1.2.5/README0000664000076400007640000000300211336332226014243 0ustar zkotazkota-*- outline -*- This python extension contains a BibTeX parser and a simple binding to the GNU Recode library. They are intended to be used with pybliographer. This module requires the following libraries to be installed: - Glib-2.x (and its development headers) - GNU Recode 3.5 (and its development headers) * Compilation Run the following command: python setup.py build For additional options: python setup.py build --help * Installation python setup.py install For additional options: python setup.py install --help * Troubleshooting Here are listed some common problems while building the python-bibtex module. ** Glib-2.0 is not in a standard place Ensure that the path to glib-2.0.pc from your installation is available in the environment variable PKG_CONFIG_PATH. ** GNU Recode is not in a standard place To build, run: python setup.py build_ext -I /path/to/recode/include -L /path/to/recode/lib ** The installation fails with one of the following errors: *** "the _recode module is broken." This means that you are using an inadequate version of GNU Recode. You need to use either Recode 3.5, or Recode 3.6 with some extra patches. * The stock version of Recode 3.6 from any GNU mirror DOES NOT WORK. * *** "the recode library is probably broken." This means that GNU Recode has been compiled with a buggy version of gcc (gcc-3.3.2 seems to trigger this problem). You can recompile recode with the following option for configure: CFLAGS=-g ./configure --prefix=... python-bibtex-1.2.5/bibtex.h0000664000076400007640000001606711336332226015030 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: bibtex.h,v 1.1.2.1 2003/09/01 19:54:46 fredgo Exp $ */ #ifndef __bibtex_h__ #define __bibtex_h__ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #include #include #include #include #include "logging.h" /* General structure for BibTeX content storing */ typedef struct _BibtexStruct BibtexStruct; typedef enum { /* List holder */ BIBTEX_STRUCT_LIST, /* Text body */ BIBTEX_STRUCT_TEXT, /* Reference to alias */ BIBTEX_STRUCT_REF, /* Sublevel, enclosed in braces or quotes */ BIBTEX_STRUCT_SUB, /* \ like command */ BIBTEX_STRUCT_COMMAND, /* space */ BIBTEX_STRUCT_SPACE, } BibtexStructType; typedef enum { BIBTEX_ENCLOSER_BRACE, BIBTEX_ENCLOSER_QUOTE, BIBTEX_ENCLOSER_NONE } BibtexEncloserType; typedef struct { BibtexEncloserType encloser; BibtexStruct * content; } BibtexStructSub; struct _BibtexStruct { BibtexStructType type; union { GList * list; gchar * text; gchar * ref; gchar * com; BibtexStructSub * sub; gboolean unbreakable; } value; }; /* Available elementary field types */ typedef enum { BIBTEX_OTHER = 0, BIBTEX_AUTHOR, BIBTEX_TITLE, BIBTEX_DATE, BIBTEX_VERBATIM, } BibtexFieldType; /* Single author */ typedef struct { gchar * honorific; gchar * first; gchar * last; gchar * lineage; } BibtexAuthor; /* Group of authors */ typedef GArray BibtexAuthorGroup; /* Date */ typedef struct { gint16 year; gint16 month; gint16 day; } BibtexDateField; /* General field declaration */ typedef struct { gboolean converted; gboolean loss; BibtexFieldType type; BibtexStruct * structure; gchar * text; union { BibtexAuthorGroup * author; BibtexDateField date; } field; } BibtexField; /* Full BibTeX entry */ typedef struct { int length; int offset; int start_line; gchar * type; gchar * name; BibtexStruct * preamble; gchar * textual_preamble; GHashTable * table; } BibtexEntry; /* Full BibTeX database */ typedef enum { BIBTEX_SOURCE_NONE, BIBTEX_SOURCE_FILE, BIBTEX_SOURCE_STRING } BibtexSourceType; typedef struct { gboolean eof, error; gboolean strict; int line; int offset; int debug; BibtexSourceType type; gchar * name; union { FILE * file; gchar * string; } source; GHashTable * table; gpointer buffer; } BibtexSource; /* -------------------------------------------------- High level interface -------------------------------------------------- */ BibtexEntry * bibtex_entry_new (void); void bibtex_entry_destroy (BibtexEntry * entry, gboolean content); /* Source manipulation */ BibtexSource * bibtex_source_new (void); void bibtex_source_destroy (BibtexSource * source, gboolean free_data); gboolean bibtex_source_file (BibtexSource * source, gchar * filename); gboolean bibtex_source_string (BibtexSource * source, gchar * name, gchar * string); /* Manipulate @string definitions in that source */ BibtexStruct * bibtex_source_get_string (BibtexSource * source, gchar * key); void bibtex_source_set_string (BibtexSource * source, gchar * key, BibtexStruct * value); BibtexEntry * bibtex_source_next_entry (BibtexSource * file, gboolean filter); void bibtex_source_rewind (BibtexSource * file); gint bibtex_source_get_offset (BibtexSource * file); void bibtex_source_set_offset (BibtexSource * file, gint offset); /* Fields manipulation */ BibtexField * bibtex_field_new (BibtexFieldType type); void bibtex_field_destroy (BibtexField * field, gboolean content); BibtexField * bibtex_field_parse (BibtexField * field, GHashTable * dico); /* Authors manipulation */ BibtexAuthor * bibtex_author_new (void); void bibtex_author_destroy (BibtexAuthor * author); BibtexAuthorGroup * bibtex_author_group_new (void); void bibtex_author_group_destroy (BibtexAuthorGroup * authors); BibtexAuthorGroup * bibtex_author_parse (BibtexStruct * authors, GHashTable * dico); /* Structure allocation / manipulation */ BibtexStruct * bibtex_struct_new (BibtexStructType type); void bibtex_struct_destroy (BibtexStruct * structure, gboolean content); BibtexStruct * bibtex_struct_copy (BibtexStruct * source); void bibtex_struct_display (BibtexStruct * source); BibtexStruct * bibtex_struct_flatten (BibtexStruct * source); BibtexStruct * bibtex_struct_append (BibtexStruct *, BibtexStruct *); /* Structure conversions */ gchar * bibtex_struct_as_string (BibtexStruct * s, BibtexFieldType type, GHashTable * dico, gboolean * loss); gchar * bibtex_struct_as_bibtex (BibtexStruct * s); gchar * bibtex_struct_as_latex (BibtexStruct * s, BibtexFieldType type, GHashTable * dico); BibtexField * bibtex_struct_as_field (BibtexStruct * s, BibtexFieldType type); /* recreate structure after modifications */ BibtexField * bibtex_reverse_field (BibtexField * field, gboolean use_braces, gboolean do_quote); /* -------------------------------------------------- Low level function -------------------------------------------------- */ gchar * bibtex_accent_string (BibtexStruct * s, GList ** flow, gboolean * loss); void bibtex_capitalize (gchar * text, gboolean is_noun, gboolean at_start); /* Temporary strings */ gchar * bibtex_tmp_string (gchar *); void bibtex_tmp_string_free (void); /* Parse next entry */ BibtexEntry * bibtex_analyzer_parse (BibtexSource * file); /* analyser on a file */ void bibtex_analyzer_initialize (BibtexSource * file); void bibtex_analyzer_finish (BibtexSource * file); #ifdef __cplusplus } #endif /* __cplusplus */ #ifdef __DEBUGGING__ #include "debugging.h" #endif /* __DEBUGGING__ */ #endif /* bibtex.h */ python-bibtex-1.2.5/bibparse.y0000664000076400007640000003233711336332226015361 0ustar zkotazkota%{ /* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: bibparse.y,v 1.1.2.2 2003/09/02 14:35:33 fredgo Exp $ */ /* #include "parsername.h" */ #include #include "bibtex.h" extern void bibtex_parser_initialize (BibtexSource *); extern void bibtex_parser_continue (BibtexSource *); extern void bibtex_parser_finish (BibtexSource *); extern int bibtex_parser_lex (void); int bibtex_parser_parse (void); extern gboolean bibtex_parser_is_content; extern int bibtex_parser_debug; static BibtexEntry * entry = NULL; static int start_line, entry_start; static BibtexSource * current_source; static gchar * error_string = NULL; static gchar * warning_string = NULL; static GString * tmp_string = NULL; static void nop (void) { return ; } void bibtex_next_line (void) { entry->length ++; } void bibtex_analyzer_initialize (BibtexSource * source) { bibtex_parser_initialize (source); } void bibtex_analyzer_finish (BibtexSource * source) { g_return_if_fail (source != NULL); bibtex_parser_finish (source); current_source = NULL; } BibtexEntry * bibtex_analyzer_parse (BibtexSource * source) { int ret; gboolean is_comment; g_return_val_if_fail (source != NULL, NULL); if (! tmp_string) { tmp_string = g_string_new (NULL); } current_source = source; bibtex_parser_debug = source->debug; start_line = source->line; entry_start = source->line + 1; entry = bibtex_entry_new (); bibtex_parser_continue (source); bibtex_parser_is_content = FALSE; ret = bibtex_parser_parse (); entry->start_line = entry_start; bibtex_tmp_string_free (); is_comment = (entry->type && (strcasecmp (entry->type, "comment") == 0)); if (warning_string && ! is_comment) { bibtex_warning (warning_string); } if (ret != 0) { source->line += entry->length; if (error_string && ! is_comment) { bibtex_error (error_string); } bibtex_entry_destroy (entry, TRUE); entry = NULL; } if (error_string) { g_free (error_string); error_string = NULL; } if (warning_string) { g_free (warning_string); warning_string = NULL; } return entry; } void bibtex_parser_error (char * s) { if (error_string) { g_free (error_string); } if (current_source) { error_string = g_strdup_printf ("%s:%d: %s", current_source->name, start_line + entry->length, s); } else { error_string = g_strdup_printf ("%d: %s", start_line + entry->length, s); } } void bibtex_parser_warning (char * s) { if (current_source) { warning_string = g_strdup_printf ("%s:%d: %s", current_source->name, start_line + entry->length, s); } else { warning_string = g_strdup_printf ("%d: %s", start_line + entry->length, s); } } static void bibtex_parser_start_error (char * s) { if (error_string) { g_free (error_string); } if (current_source) { error_string = g_strdup_printf ("%s:%d: %s", current_source->name, entry_start, s); } else { error_string = g_strdup_printf ("%d: %s", entry_start, s); } } static void bibtex_parser_start_warning (char * s) { if (current_source) { warning_string = g_strdup_printf ("%s:%d: %s", current_source->name, entry_start, s); } else { warning_string = g_strdup_printf ("%d: %s", entry_start, s); } } %} %union{ gchar * text; BibtexStruct * body; } %token end_of_file %token L_NAME %token L_DIGIT %token L_COMMAND %token L_BODY %token L_SPACE %token L_UBSPACE %type entry %type values %type value %type content %type simple_content %type content_brace %type content_quote %type text_quote %type text_brace %type text_part %% /* Les deux types d'entrees */ /* ================================================== */ entry: '@' L_NAME '{' values '}' /* -------------------------------------------------- */ { entry->type = g_strdup ($2); g_strdown (entry->type); YYACCEPT; } /* -------------------------------------------------- */ | '@' L_NAME '(' values ')' /* -------------------------------------------------- */ { entry->type = g_strdup ($2); g_strdown (entry->type); YYACCEPT; } /* -------------------------------------------------- */ | end_of_file /* -------------------------------------------------- */ { current_source->eof = TRUE; YYABORT; } /* -------------------------------------------------- */ | '@' L_NAME '(' error ')' /* -------------------------------------------------- */ { if (strcasecmp ($2, "comment") == 0) { entry->type = g_strdup ($2); g_strdown (entry->type); yyclearin; YYACCEPT; } if (current_source->strict) { bibtex_parser_start_error ("perhaps a missing coma"); YYABORT; } else { bibtex_parser_start_warning ("perhaps a missing coma."); entry->type = g_strdup ($2); g_strdown (entry->type); yyclearin; YYACCEPT; } } /* -------------------------------------------------- */ | '@' L_NAME '{' error '}' /* -------------------------------------------------- */ { if (strcasecmp ($2, "comment") == 0) { entry->type = g_strdup ($2); g_strdown (entry->type); yyclearin; YYACCEPT; } if (current_source->strict) { bibtex_parser_start_error ("perhaps a missing coma"); YYABORT; } else { bibtex_parser_start_warning ("perhaps a missing coma"); entry->type = g_strdup ($2); g_strdown (entry->type); yyclearin; YYACCEPT; } } /* -------------------------------------------------- */ | '@' L_NAME '(' error end_of_file /* -------------------------------------------------- */ { bibtex_parser_start_error ("end of file during processing"); YYABORT; } /* -------------------------------------------------- */ | '@' L_NAME '{' error end_of_file /* -------------------------------------------------- */ { bibtex_parser_start_error ("end of file during processing"); YYABORT; } /* -------------------------------------------------- */ ; /* ================================================== */ /* La liste des valeurs */ /* -------------------------------------------------- */ values: value ',' values /* -------------------------------------------------- */ { nop (); } /* -------------------------------------------------- */ | value ',' /* -------------------------------------------------- */ { nop (); } /* -------------------------------------------------- */ | value /* -------------------------------------------------- */ { nop (); } ; /* Une valeur */ /* ================================================== */ value: L_NAME '=' content /* -------------------------------------------------- */ { char * name; BibtexField * field; BibtexFieldType type = BIBTEX_OTHER; g_strdown ($1); field = g_hash_table_lookup (entry->table, $1); /* Get a new instance of a field name */ if (field) { g_string_sprintf (tmp_string, "field `%s' is already defined", $1); bibtex_parser_warning (tmp_string->str); bibtex_field_destroy (field, TRUE); name = $1; } else { name = g_strdup ($1); } /* Search its type */ do { if (strcmp (name, "author") == 0) { type = BIBTEX_AUTHOR; break; } if (strcmp (name, "title") == 0) { type = BIBTEX_TITLE; break; } if (strcmp (name, "year") == 0) { type = BIBTEX_DATE; break; } } while (0); /* Convert into the right field */ field = bibtex_struct_as_field (bibtex_struct_flatten ($3), type); g_hash_table_insert (entry->table, name, field); } /* -------------------------------------------------- */ | content /* -------------------------------------------------- */ { entry_start = start_line + entry->length; if (entry->preamble) { bibtex_parser_start_error ("entry already contains a preamble or has an unexpected comma in its key"); YYABORT; } entry->preamble = $1; } /* -------------------------------------------------- */ ; /* ================================================== */ content: simple_content '#' content /* -------------------------------------------------- */ { $$ = bibtex_struct_append ($1, $3); } /* -------------------------------------------------- */ | simple_content /* -------------------------------------------------- */ { $$ = $1; } /* -------------------------------------------------- */ ; /* Definition du contenu d'un champ, encadre par des accolades */ /* ================================================== */ content_brace: '{' { bibtex_parser_is_content = TRUE; } text_brace '}' /* -------------------------------------------------- */ { bibtex_parser_is_content = FALSE; $$ = bibtex_struct_new (BIBTEX_STRUCT_SUB); $$->value.sub->encloser = BIBTEX_ENCLOSER_BRACE; $$->value.sub->content = $3; } ; /* Definition du contenu d'un champ encadre par des guillemets */ /* ================================================== */ content_quote: '"' { bibtex_parser_is_content = TRUE; } text_quote '"' /* -------------------------------------------------- */ { bibtex_parser_is_content = FALSE; $$ = bibtex_struct_new (BIBTEX_STRUCT_SUB); $$->value.sub->encloser = BIBTEX_ENCLOSER_QUOTE; $$->value.sub->content = $3; } ; /* ================================================== */ simple_content: L_DIGIT /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_TEXT); $$->value.text = g_strdup ($1); } /* -------------------------------------------------- */ | L_NAME /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_REF); $$->value.ref = g_strdup ($1); /* g_strdown ($$->value.ref); */ } /* -------------------------------------------------- */ | content_brace /* -------------------------------------------------- */ { $$ = $1; } /* -------------------------------------------------- */ | content_quote /* -------------------------------------------------- */ { $$ = $1; } /* -------------------------------------------------- */ ; /* ================================================== */ text_part: L_COMMAND /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_COMMAND); $$->value.com = g_strdup ($1 + 1); } /* -------------------------------------------------- */ | '{' text_brace '}' /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_SUB); $$->value.sub->encloser = BIBTEX_ENCLOSER_BRACE; $$->value.sub->content = $2; } /* -------------------------------------------------- */ | L_SPACE /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_SPACE); } /* -------------------------------------------------- */ | L_UBSPACE /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_SPACE); $$->value.unbreakable = TRUE; } /* -------------------------------------------------- */ | L_BODY /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_TEXT); $$->value.text = g_strdup ($1); } /* -------------------------------------------------- */ ; /* ================================================== */ text_brace: /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_TEXT); $$->value.text = g_strdup (""); } /* -------------------------------------------------- */ | '"' text_brace /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_TEXT); $$->value.text = g_strdup ("\""); $$ = bibtex_struct_append ($$, $2); } /* -------------------------------------------------- */ | text_part text_brace /* -------------------------------------------------- */ { $$ = bibtex_struct_append ($1, $2); } /* -------------------------------------------------- */ ; /* ================================================== */ text_quote: /* -------------------------------------------------- */ { $$ = bibtex_struct_new (BIBTEX_STRUCT_TEXT); $$->value.text = g_strdup (""); } /* -------------------------------------------------- */ | text_part text_quote /* -------------------------------------------------- */ { $$ = bibtex_struct_append ($1, $2); } /* -------------------------------------------------- */ ; %% python-bibtex-1.2.5/bibtex.c0000664000076400007640000001177311336332226015022 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: bibtex.c,v 1.1.2.2 2003/09/02 14:35:33 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include "bibtex.h" void bibtex_message_handler (const gchar *log_domain G_GNUC_UNUSED, GLogLevelFlags log_level, const gchar *message, gpointer user_data G_GNUC_UNUSED) { gchar * name = g_get_prgname (); if (name) { fprintf (stderr, "%s: ", name); } switch (log_level) { case BIB_LEVEL_ERROR: fprintf (stderr, "error: %s\n", message); break; case BIB_LEVEL_WARNING: fprintf (stderr, "warning: %s\n", message); break; case BIB_LEVEL_MESSAGE: printf ("%s\n", message); break; default: fprintf (stderr, ": %s\n", log_level, message); break; } } void bibtex_set_default_handler (void) { g_log_set_handler (G_LOG_DOMAIN, BIB_LEVEL_ERROR, bibtex_message_handler, NULL); g_log_set_handler (G_LOG_DOMAIN, BIB_LEVEL_WARNING, bibtex_message_handler, NULL); g_log_set_handler (G_LOG_DOMAIN, BIB_LEVEL_MESSAGE, bibtex_message_handler, NULL); } static void add_to_dico (gpointer key, gpointer value, gpointer user) { gchar * val = (gchar *) key; BibtexField * field; BibtexStruct * structure; if ((structure = g_hash_table_lookup ((GHashTable *) user, val)) == NULL) { val = g_strdup ((char *) key); } else { bibtex_struct_destroy (structure, TRUE); } field = (BibtexField *) value; g_strdown (val); g_hash_table_insert ((GHashTable *) user, val, field->structure); } BibtexEntry * bibtex_source_next_entry (BibtexSource * file, gboolean filter) { BibtexEntry * ent; int offset; g_return_val_if_fail (file != NULL, NULL); if (file->eof) return NULL; offset = file->offset; file->error = FALSE; do { ent = bibtex_analyzer_parse (file); if (ent) { /* Incrementer les numeros de ligne */ file->line += ent->length; ent->offset = offset; ent->length = file->offset - offset; /* Rajouter les definitions au dictionnaire, si necessaire */ if (ent->type) { if (strcasecmp (ent->type, "string") == 0) { g_hash_table_foreach (ent->table, add_to_dico, file->table); if (filter) { /* Return nothing, we store it as string database */ bibtex_entry_destroy (ent, FALSE); ent = NULL; } } else { do { if (strcasecmp (ent->type, "comment") == 0) { bibtex_entry_destroy (ent, TRUE); ent = NULL; break; } if (strcasecmp (ent->type, "preamble") == 0) { if (filter) { bibtex_warning ("%s:%d: skipping preamble", file->name, file->line); bibtex_entry_destroy (ent, TRUE); ent = NULL; } else { ent->textual_preamble = bibtex_struct_as_bibtex (ent->preamble); } break; } /* normal case; convert preamble into entry name */ if (ent->preamble) { switch (ent->preamble->type) { case BIBTEX_STRUCT_REF: /* alphanumeric identifiers */ ent->name = g_strdup (ent->preamble->value.ref); break; case BIBTEX_STRUCT_TEXT: /* numeric identifiers */ ent->name = g_strdup (ent->preamble->value.text); break; default: if (file->strict) { bibtex_error ("%s:%d: entry has a weird name", file->name, file->line); bibtex_entry_destroy (ent, TRUE); file->error = TRUE; return NULL; } else { bibtex_warning ("%s:%d: entry has a weird name", file->name, file->line); bibtex_struct_destroy (ent->preamble, TRUE); ent->preamble = NULL; ent->name = NULL; } break; } } else { if (file->strict) { bibtex_error ("%s:%d: entry has no identifier", file->name, file->line); bibtex_entry_destroy (ent, TRUE); file->error = TRUE; return NULL; } else { bibtex_warning ("%s:%d: entry has no identifier", file->name, file->line); } } } while (0); } } } else { /* No ent, there has been a problem */ return NULL; } } while (!ent); return ent; } python-bibtex-1.2.5/tests/0000775000076400007640000000000011416711604014532 5ustar zkotazkotapython-bibtex-1.2.5/tests/url.bib0000664000076400007640000000006311336332227016012 0ustar zkotazkota@article{withurl, url = {http://toto/~gronf/a} } python-bibtex-1.2.5/tests/simple.bib0000664000076400007640000000020211336332227016474 0ustar zkotazkota@Article{gobry03, author = {Fr\'ed\'eric Gobry}, title = {A simple example}, journal = {My diary}, year = 2003 } python-bibtex-1.2.5/tests/string.bib0000664000076400007640000000002511336332227016514 0ustar zkotazkota@string{a = "gronf"} python-bibtex-1.2.5/tests/paren.bib-ok0000664000076400007640000000010211336332227016716 0ustar zkotazkota('Ples:2001(031916)', 'article', 0, 1, {'title': (2, 0, 'Toto')}) python-bibtex-1.2.5/tests/authors.bib-ok0000664000076400007640000000037011336332227017305 0ustar zkotazkota('weird', 'article', 0, 1, {'author': (1, 0, 'Gobry, Frederic and Grederic Fobry and Nostradamus and others', [(None, 'Frederic', 'Gobry', None), (None, 'Grederic', 'Fobry', None), (None, None, 'Nostradamus', None), (None, None, 'others', None)])})python-bibtex-1.2.5/tests/simple-2.bib-ok0000664000076400007640000000034711336332227017254 0ustar zkotazkota('entry', ('gobry03', 'article', 0, 1, {'journal': (0, 0, 'My diary'), 'year': (3, 0, '2003', 2003, 0, 0), 'author': (1, 0, 'Fr\xe9d\xe9ric Gobry', [(None, 'Fr\xe9d\xe9ric', 'Gobry', None)]), 'title': (2, 0, 'A simple example')})) python-bibtex-1.2.5/tests/eof.bib-ok0000664000076400007640000000001411336332227016364 0ustar zkotazkotaParserError python-bibtex-1.2.5/tests/authors.bib0000664000076400007640000000014211336332227016673 0ustar zkotazkota@Article{weird, author = {Gobry, Frederic and Grederic Fobry and {Nostradamus} and others} } python-bibtex-1.2.5/tests/simple.bib-ok0000664000076400007640000000033411336332227017111 0ustar zkotazkota('gobry03', 'article', 0, 1, {'journal': (0, 0, 'My diary'), 'year': (3, 0, '2003', 2003, 0, 0), 'author': (1, 0, 'Fr\xe9d\xe9ric Gobry', [(None, 'Fr\xe9d\xe9ric', 'Gobry', None)]), 'title': (2, 0, 'A simple example')}) python-bibtex-1.2.5/tests/string.bib-ok0000664000076400007640000000001411336332227017121 0ustar zkotazkota('string',) python-bibtex-1.2.5/tests/preamble.bib-ok0000664000076400007640000000004411336332227017405 0ustar zkotazkota('preamble', '"A simple preamble"') python-bibtex-1.2.5/tests/eof.bib0000664000076400007640000000003611336332227015761 0ustar zkotazkota@article{ author = "gronf", python-bibtex-1.2.5/tests/simple-2.bib0000664000076400007640000000020211336332227016633 0ustar zkotazkota@Article{gobry03, author = {Fr\'ed\'eric Gobry}, title = {A simple example}, journal = {My diary}, year = 2003 } python-bibtex-1.2.5/tests/preamble.bib0000664000076400007640000000004011336332227016772 0ustar zkotazkota@preamble{"A simple preamble"} python-bibtex-1.2.5/tests/url.bib-ok0000664000076400007640000000010511336332227016416 0ustar zkotazkota('withurl', 'article', 0, 1, {'url': (4, 0, 'http://toto/~gronf/a')})python-bibtex-1.2.5/tests/paren.bib0000664000076400007640000000006311336332227016315 0ustar zkotazkota@Article{Ples:2001(031916), title = {toto}, } python-bibtex-1.2.5/recodemodule.c0000664000076400007640000001107111336332226016203 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: recodemodule.c,v 1.1.1.1.2.5 2003/08/13 21:56:11 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef HAVE_STDBOOL_H #include #else /* ! HAVE_STDBOOL_H */ /* stdbool.h for GNU. */ /* The type `bool' must promote to `int' or `unsigned int'. The constants `true' and `false' must have the value 0 and 1 respectively. */ typedef enum { false = 0, true = 1 } bool; /* The names `true' and `false' must also be made available as macros. */ #define false false #define true true /* Signal that all the definitions are present. */ #define __bool_true_false_are_defined 1 #endif /* HAVE_STDBOOL_H */ #include #include #include static RECODE_OUTER outer; char * program_name = "pyrecode"; typedef struct { PyObject_HEAD RECODE_REQUEST obj; } PyRecodeRequest_Object; /* Destructor of BibtexFile */ static void py_delete_recoder (PyRecodeRequest_Object * self) { recode_delete_request (self->obj); PyObject_DEL (self); } static char PyRecodeRequest_Type__doc__[] = "This is the type of a recoder"; static PyTypeObject PyRecodeRequest_Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "RecodeRequest", /*tp_name*/ sizeof(PyRecodeRequest_Object), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor)py_delete_recoder, /*tp_dealloc*/ (printfunc)0, /*tp_print*/ (getattrfunc)0, /*tp_getattr*/ (setattrfunc)0, /*tp_setattr*/ (cmpfunc)0, /*tp_compare*/ (reprfunc)0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ (hashfunc)0, /*tp_hash*/ (ternaryfunc)0, /*tp_call*/ (reprfunc)0, /*tp_str*/ 0L,0L,0L,0L, PyRecodeRequest_Type__doc__ }; static PyObject * py_new_recoder (PyObject * self, PyObject * args) { PyRecodeRequest_Object * ret; char * string; RECODE_REQUEST request; if (! PyArg_ParseTuple(args, "s:request", & string)) return NULL; request = recode_new_request (outer); if (request == NULL) { PyErr_SetString (PyExc_RuntimeError, "can't initialize new request"); return NULL; } if (! recode_scan_request (request, string)) { recode_delete_request (request); PyErr_SetString (PyExc_TypeError, "can't initialize request"); return NULL; } /* Create a new object */ ret = (PyRecodeRequest_Object *) PyObject_NEW (PyRecodeRequest_Object, & PyRecodeRequest_Type); ret->obj = request; return (PyObject *) ret; } static PyObject * py_recode (PyObject * self, PyObject * args) { char * string; int length; RECODE_REQUEST request; PyObject * tmp; PyRecodeRequest_Object * req_obj; if (! PyArg_ParseTuple(args, "O!s:recode", & PyRecodeRequest_Type, & req_obj, & string)) return NULL; request = req_obj->obj; length = strlen (string); if (length == 0) { return PyString_FromString (""); } string = recode_string (request, string); if (string == NULL) { PyErr_SetString (PyExc_RuntimeError, "can't convert"); return NULL; } tmp = PyString_FromString (string); free (string); return tmp; } static PyMethodDef recodeMeth [] = { { "request", py_new_recoder, METH_VARARGS }, { "recode", py_recode, METH_VARARGS }, {NULL, NULL, 0}, }; void init_recode (void) { PyRecodeRequest_Type.ob_type = & PyType_Type; outer = recode_new_outer (true); if (outer == NULL) { fprintf (stderr, "_recode: error: cannot initialize outer interface.\n"); return; } (void) Py_InitModule ("_recode", recodeMeth); } python-bibtex-1.2.5/bibtexmodule.c0000664000076400007640000004424711336332226016232 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: bibtexmodule.c,v 1.5.2.4 2003/07/31 13:18:55 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "bibtex.h" char program_name [] = "bibtexmodule"; typedef struct { PyObject_HEAD BibtexSource *obj; } PyBibtexSource_Object; typedef struct { PyObject_HEAD BibtexField *obj; } PyBibtexField_Object; /* Destructor of BibtexFile */ static void bibtex_py_close (PyBibtexSource_Object * self) { bibtex_source_destroy (self->obj, TRUE); PyObject_DEL (self); } /* Destructor of BibtexEntry */ static void destroy_field (PyBibtexField_Object * self) { bibtex_field_destroy (self->obj, TRUE); PyObject_DEL (self); } static char PyBibtexSource_Type__doc__[] = "This is the type of a BibTeX source"; static char PyBibtexField_Type__doc__[] = "This is the type of an internal BibTeX field"; static PyTypeObject PyBibtexSource_Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "BibtexSource", /*tp_name*/ sizeof(PyBibtexSource_Object), /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor)bibtex_py_close, /*tp_dealloc*/ (printfunc)0, /*tp_print*/ (getattrfunc)0, /*tp_getattr*/ (setattrfunc)0, /*tp_setattr*/ (cmpfunc)0, /*tp_compare*/ (reprfunc)0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ (hashfunc)0, /*tp_hash*/ (ternaryfunc)0, /*tp_call*/ (reprfunc)0, /*tp_str*/ 0L,0L,0L,0L, PyBibtexSource_Type__doc__ }; static PyTypeObject PyBibtexField_Type = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "BibtexField", /*tp_name*/ sizeof(PyBibtexField_Object) , /*tp_basicsize*/ 0, /*tp_itemsize*/ (destructor)destroy_field, /*tp_dealloc*/ (printfunc)0, /*tp_print*/ (getattrfunc)0, /*tp_getattr*/ (setattrfunc)0, /*tp_setattr*/ (cmpfunc)0, /*tp_compare*/ (reprfunc)0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ (hashfunc)0, /*tp_hash*/ (ternaryfunc)0, /*tp_call*/ (reprfunc)0, /*tp_str*/ 0L,0L,0L,0L, PyBibtexField_Type__doc__ }; static void py_message_handler (const gchar *log_domain G_GNUC_UNUSED, GLogLevelFlags log_level, const gchar *message, gpointer user_data G_GNUC_UNUSED) { PyErr_SetString (PyExc_IOError, message); } static PyObject * bib_open_file (PyObject * self, PyObject * args) { char * name; BibtexSource * file; gint strictness; PyBibtexSource_Object * ret; if (! PyArg_ParseTuple(args, "si", & name, & strictness)) return NULL; file = bibtex_source_new (); /* set the strictness */ file->strict = strictness; if (! bibtex_source_file (file, name)) { bibtex_source_destroy (file, TRUE); return NULL; } /* Create a new object */ ret = (PyBibtexSource_Object *) PyObject_NEW (PyBibtexSource_Object, & PyBibtexSource_Type); ret->obj = file; return (PyObject *) ret; } static PyObject * bib_open_string (PyObject * self, PyObject * args) { char * name, * string; BibtexSource * file; gint strictness; PyBibtexSource_Object * ret; if (! PyArg_ParseTuple(args, "ssi", & name, & string, & strictness)) return NULL; file = bibtex_source_new (); /* set the strictness */ file->strict = strictness; if (! bibtex_source_string (file, name, string)) { bibtex_source_destroy (file, TRUE); return NULL; } /* Create a new object */ ret = (PyBibtexSource_Object *) PyObject_NEW (PyBibtexSource_Object, & PyBibtexSource_Type); ret->obj = file; return (PyObject *) ret; } static PyObject * bib_expand (PyObject * self, PyObject * args) { PyObject * liste, * tmp, * auth [4]; BibtexFieldType type; BibtexField * field; BibtexSource * file; PyBibtexSource_Object * file_obj; PyBibtexField_Object * field_obj; BibtexAuthor * author; int i, j; if (! PyArg_ParseTuple(args, "O!O!i:expand", &PyBibtexSource_Type, & file_obj, &PyBibtexField_Type, & field_obj, & type)) return NULL; file = file_obj->obj; field = field_obj->obj; if (! field->converted) { if (type != -1) { field->type = type; } bibtex_field_parse(field, file->table); } switch (field->type) { case BIBTEX_TITLE: case BIBTEX_OTHER: case BIBTEX_VERBATIM: tmp = Py_BuildValue ("iis", field->type, field->loss, field->text); break; case BIBTEX_DATE: tmp = Py_BuildValue ("iisiii", field->type, field->loss, field->text, field->field.date.year, field->field.date.month, field->field.date.day); break; case BIBTEX_AUTHOR: liste = PyList_New (field->field.author->len); for (i = 0; i < field->field.author->len; i++) { author = & g_array_index (field->field.author, BibtexAuthor, i); if (author->honorific) { auth [0] = PyString_FromString (author->honorific); } else { auth [0] = Py_None; Py_INCREF (Py_None); } if (author->first) { auth [1] = PyString_FromString (author->first); } else { auth [1] = Py_None; Py_INCREF (Py_None); } if (author->last) { auth [2] = PyString_FromString (author->last); } else { auth [2] = Py_None; Py_INCREF (Py_None); } if (author->lineage) { auth [3] = PyString_FromString (author->lineage); } else { auth [3] = Py_None; Py_INCREF (Py_None); } PyList_SetItem (liste, i, Py_BuildValue ("OOOO", auth [0], auth [1], auth [2], auth [3])); for (j = 0; j < 4; j ++) { Py_DECREF (auth [j]); } } tmp = Py_BuildValue ("iisO", field->type, field->loss, field->text, liste); Py_DECREF (liste); break; default: tmp = Py_None; Py_INCREF (Py_None); } return tmp; } static PyObject * bib_get_native (PyObject * self, PyObject * args) { PyObject * tmp; BibtexField * field; PyBibtexField_Object * field_obj; gchar * text; if (! PyArg_ParseTuple(args, "O!:get_native", & PyBibtexField_Type, & field_obj)) return NULL; field = field_obj->obj; if (field->structure == NULL) { Py_INCREF (Py_None); return Py_None; } text = bibtex_struct_as_bibtex (field->structure); tmp = Py_BuildValue("s", text); g_free (text); return tmp; } static PyObject * bib_copy_field (PyObject * self, PyObject * args) { BibtexField * field; PyBibtexField_Object * field_obj, * new_obj; if (! PyArg_ParseTuple(args, "O!:get_native", & PyBibtexField_Type, & field_obj)) return NULL; field = field_obj->obj; new_obj = (PyBibtexField_Object *) PyObject_NEW (PyBibtexField_Object, & PyBibtexField_Type); new_obj->obj = bibtex_struct_as_field (bibtex_struct_copy (field->structure), field->type); return (PyObject *) new_obj; } static PyObject * bib_get_latex (PyObject * self, PyObject * args) { PyObject * tmp; BibtexField * field; PyBibtexField_Object * field_obj; BibtexFieldType type; BibtexSource * file; PyBibtexSource_Object * file_obj; gchar * text; if (! PyArg_ParseTuple(args, "O!O!i:get_latex", &PyBibtexSource_Type, & file_obj, & PyBibtexField_Type, & field_obj, & type )) return NULL; field = field_obj->obj; file = file_obj->obj; text = bibtex_struct_as_latex (field->structure, type, file->table); tmp = Py_BuildValue("s", text); g_free (text); return tmp; } static PyObject * bib_set_native (PyObject * self, PyObject * args) { PyObject * tmp; BibtexField * field; static BibtexSource * source = NULL; BibtexEntry * entry; BibtexStruct * s; BibtexFieldType type; gchar * text, * to_parse; if (! PyArg_ParseTuple(args, "si:set_native", & text, &type)) return NULL; /* Create new source */ if (source == NULL) source = bibtex_source_new (); /* parse as a string */ to_parse = g_strdup_printf ("@preamble{%s}", text); if (! bibtex_source_string (source, "internal string", to_parse)) { PyErr_SetString (PyExc_IOError, "can't create internal string for parsing"); return NULL; } g_free (to_parse); entry = bibtex_source_next_entry (source, FALSE); if (entry == NULL) { return NULL; } s = bibtex_struct_copy (entry->preamble); bibtex_entry_destroy (entry, TRUE); field = bibtex_struct_as_field (s, type); tmp = (PyObject *) PyObject_NEW (PyBibtexField_Object, & PyBibtexField_Type); ((PyBibtexField_Object *) tmp)->obj = field; return tmp; } static void fill_dico (gpointer key, gpointer value, gpointer user) { PyObject * dico = (PyObject *) user; PyObject * tmp1, * tmp2; tmp1 = PyString_FromString ((char *) key); tmp2 = (PyObject *) PyObject_NEW (PyBibtexField_Object, & PyBibtexField_Type); ((PyBibtexField_Object *) tmp2)->obj = value; PyDict_SetItem (dico, tmp1, tmp2); Py_DECREF (tmp1); Py_DECREF (tmp2); } static void fill_struct_dico (gpointer key, gpointer value, gpointer user) { PyObject * dico = (PyObject *) user; PyObject * tmp1, * tmp2; tmp1 = PyString_FromString ((char *) key); tmp2 = (PyObject *) PyObject_NEW (PyBibtexField_Object, & PyBibtexField_Type); ((PyBibtexField_Object *) tmp2)->obj = bibtex_struct_as_field (bibtex_struct_copy ((BibtexStruct *) value), BIBTEX_OTHER); PyDict_SetItem (dico, tmp1, tmp2); Py_DECREF (tmp1); Py_DECREF (tmp2); } static PyObject * bib_set_string (PyObject * self, PyObject * args) { BibtexField * field; BibtexSource * source; PyBibtexSource_Object * source_obj; PyBibtexField_Object * field_obj; gchar * key; if (! PyArg_ParseTuple(args, "O!sO!:set_string", & PyBibtexSource_Type, & source_obj, & key, & PyBibtexField_Type, & field_obj )) return NULL; source = source_obj->obj; field = field_obj->obj; /* set a copy of the struct as the field value */ bibtex_source_set_string (source, key, bibtex_struct_copy (field->structure)); Py_INCREF (Py_None); return Py_None; } static PyObject * _bib_next (PyBibtexSource_Object * file_obj, gboolean filter) { BibtexEntry * ent; BibtexSource * file; PyObject * dico, * tmp, * name; file = file_obj->obj; ent = bibtex_source_next_entry (file, filter); if (ent == NULL) { if (file->eof) { Py_INCREF(Py_None); return Py_None; } return NULL; } /* Retour de la fonction */ if (! filter && ! ent->name) { if (ent->textual_preamble) { tmp = Py_BuildValue ("ss", ent->type, ent->textual_preamble); } else { /* this must be a string then... */ tmp = Py_BuildValue ("(s)", ent->type); } } else { dico = PyDict_New (); g_hash_table_foreach (ent->table, fill_dico, dico); if (ent->name) { name = PyString_FromString (ent->name); } else { name = Py_None; } if (filter) { tmp = Py_BuildValue ("OsiiO", name, ent->type, ent->offset, ent->start_line, dico); } else { tmp = Py_BuildValue ("(s(OsiiO))", "entry", name, ent->type, ent->offset, ent->start_line, dico); } Py_DECREF (dico); } bibtex_entry_destroy (ent, FALSE); return tmp; } static PyObject * bib_next (PyObject * self, PyObject * args) { PyBibtexSource_Object * file_obj; if (! PyArg_ParseTuple(args, "O!:next", & PyBibtexSource_Type, & file_obj)) return NULL; return _bib_next (file_obj, TRUE); } static PyObject * bib_next_unfiltered (PyObject * self, PyObject * args) { PyBibtexSource_Object * file_obj; if (! PyArg_ParseTuple(args, "O!:next", & PyBibtexSource_Type, & file_obj)) return NULL; return _bib_next (file_obj, FALSE); } static PyObject * bib_get_dict (PyObject * self, PyObject * args) { BibtexSource * file; PyBibtexSource_Object * file_obj; PyObject * dico; if (! PyArg_ParseTuple(args, "O!:next", &PyBibtexSource_Type, & file_obj)) return NULL; file = file_obj->obj; dico = PyDict_New (); g_hash_table_foreach (file->table, fill_struct_dico, dico); return dico; } static PyObject * bib_first (PyObject * self, PyObject * args) { BibtexSource * file; PyBibtexSource_Object * file_obj; if (! PyArg_ParseTuple(args, "O!:first", &PyBibtexSource_Type, & file_obj)) return NULL; file = file_obj->obj; bibtex_source_rewind (file); Py_INCREF(Py_None); return Py_None; } static PyObject * bib_reverse (PyObject * self, PyObject * args) { BibtexField * field; PyObject * tuple, * authobj, * tmp; BibtexFieldType type; BibtexAuthor * auth; gint length, i, brace, quote; if (! PyArg_ParseTuple(args, "iiO:reverse", & type, & brace, & tuple)) return NULL; field = bibtex_field_new (type); if (field == NULL) { PyErr_SetString (PyExc_IOError, "can't create field"); return NULL; } quote = 1; switch (field->type) { case BIBTEX_VERBATIM: quote = 0; case BIBTEX_OTHER: case BIBTEX_TITLE: tmp = PyObject_Str (tuple); if (tmp == NULL) return NULL; field->text = g_strdup (PyString_AsString (tmp)); Py_DECREF (tmp); break; case BIBTEX_DATE: tmp = PyObject_GetAttrString (tuple, "year"); if (tmp == NULL) return NULL; if (tmp != Py_None) field->field.date.year = PyInt_AsLong (tmp); Py_DECREF (tmp); tmp = PyObject_GetAttrString (tuple, "month"); if (tmp == NULL) return NULL; if (tmp != Py_None) field->field.date.month = PyInt_AsLong (tmp); Py_DECREF (tmp); tmp = PyObject_GetAttrString (tuple, "day"); if (tmp == NULL) return NULL; if (tmp != Py_None) field->field.date.day = PyInt_AsLong (tmp); Py_DECREF (tmp); break; case BIBTEX_AUTHOR: length = PySequence_Length (tuple); if (length < 0) return NULL; field->field.author = bibtex_author_group_new (); g_array_set_size (field->field.author, length); for (i = 0; i < length; i++) { authobj = PySequence_GetItem (tuple, i); auth = & g_array_index (field->field.author, BibtexAuthor, i); tmp = PyObject_GetAttrString (authobj, "last"); if (tmp != Py_None) { auth->last = g_strdup (PyString_AsString (tmp)); } else { auth->last = NULL; } Py_DECREF (tmp); tmp = PyObject_GetAttrString (authobj, "first"); if (tmp != Py_None) { auth->first = g_strdup (PyString_AsString (tmp)); } else { auth->first = NULL; } Py_DECREF (tmp); tmp = PyObject_GetAttrString (authobj, "lineage"); if (tmp != Py_None) { auth->lineage = g_strdup (PyString_AsString (tmp)); } else { auth->lineage = NULL; } Py_DECREF (tmp); tmp = PyObject_GetAttrString (authobj, "honorific"); if (tmp != Py_None) { auth->honorific = g_strdup (PyString_AsString (tmp)); } else { auth->honorific = NULL; } Py_DECREF (tmp); } } bibtex_reverse_field (field, brace, quote); tmp = (PyObject *) PyObject_NEW (PyBibtexField_Object, & PyBibtexField_Type); ((PyBibtexField_Object *) tmp)->obj = field; return tmp; } static PyObject * bib_set_offset (PyObject * self, PyObject * args) { BibtexSource * file; gint offset = 0; PyBibtexSource_Object * file_obj; if (! PyArg_ParseTuple(args, "O!:first", &PyBibtexSource_Type, & file_obj)) return NULL; file = file_obj->obj; bibtex_source_set_offset (file, offset); if (file->error) { return NULL; } Py_INCREF(Py_None); return Py_None; } static PyObject * bib_get_offset (PyObject * self, PyObject * args) { BibtexSource * file; gint offset; PyObject * tmp; PyBibtexSource_Object * file_obj; if (! PyArg_ParseTuple(args, "O!:first", &PyBibtexSource_Type, & file_obj)) return NULL; file = file_obj->obj; offset = bibtex_source_get_offset (file); tmp = PyInt_FromLong ((long) offset); return tmp; } static PyMethodDef bibtexMeth [] = { { "open_file", bib_open_file, METH_VARARGS }, { "open_string", bib_open_string, METH_VARARGS }, { "next", bib_next, METH_VARARGS }, { "next_unfiltered", bib_next_unfiltered, METH_VARARGS }, { "first", bib_first, METH_VARARGS }, { "set_offset", bib_set_offset, METH_VARARGS }, { "get_offset", bib_get_offset, METH_VARARGS }, { "expand", bib_expand, METH_VARARGS }, { "get_native", bib_get_native, METH_VARARGS }, { "get_latex", bib_get_latex, METH_VARARGS }, { "set_native", bib_set_native, METH_VARARGS }, { "reverse", bib_reverse, METH_VARARGS }, { "get_dict", bib_get_dict, METH_VARARGS }, { "set_string", bib_set_string, METH_VARARGS }, { "copy_field", bib_copy_field, METH_VARARGS }, {NULL, NULL, 0}, }; void init_bibtex (void) { PyBibtexSource_Type.ob_type = & PyType_Type; PyBibtexField_Type.ob_type = & PyType_Type; bibtex_set_default_handler (); g_log_set_handler (G_LOG_DOMAIN, BIB_LEVEL_ERROR, py_message_handler, NULL); g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL); (void) Py_InitModule("_bibtex", bibtexMeth); } python-bibtex-1.2.5/setup.py0000664000076400007640000001075711416706522015117 0ustar zkotazkota# -*- python -*- import os, stat, sys from distutils.core import setup, Extension, Command from distutils.errors import DistutilsExecError from distutils.command.install import install as base_install version = '1.2.5' bibtex = [ 'accents.c', 'author.c', 'bibparse.c', 'biblex.c', 'bibtex.c', 'bibtexmodule.c', 'entry.c', 'field.c', 'reverse.c', 'source.c', 'stringutils.c', 'struct.c' ] def error (msg): sys.stderr.write ('setup.py: error: %s\n' % msg) return # Obtain path for Glib includes = [] libs = [] libdirs = [] def pread (cmd): fd = os.popen (cmd) data = fd.read () return (data, fd.close ()) include, ix = pread ('pkg-config glib-2.0 --cflags') library, lx = pread ('pkg-config glib-2.0 --libs') if ix or lx: error ('cannot find Glib-2.0 installation parameters.') error ('please check that your glib-2.0 development package') error ('has been installed.') sys.exit (1) # Split the path into pieces for inc in include.split (' '): inc = inc.strip () if not inc: continue if inc [:2] == '-I': includes.append (inc [2:]) for lib in library.split (' '): lib = lib.strip () if not lib: continue if lib [:2] == '-l': libs.append (lib [2:]) if lib [:2] == '-L': libdirs.append (lib [2:]) # Check the state of the generated lex and yacc files def rebuild (src, deps): st = os.stat (src) [stat.ST_MTIME] for dep in deps: try: dt = os.stat (dep) [stat.ST_MTIME] except OSError: return True if st > dt: return True return False def rename (src, dst): try: os.unlink (dst) except OSError: pass os.rename (src, dst) return if rebuild ('bibparse.y', ['bibparse.c', 'bibparse.h']): print "rebuilding from bibparse.y" os.system ('bison -y -d -t -p bibtex_parser_ bibparse.y') rename ('y.tab.c', 'bibparse.c') rename ('y.tab.h', 'bibparse.h') if rebuild ('biblex.l', ['biblex.c']): print "rebuilding from biblex.l" os.system ('flex -Pbibtex_parser_ biblex.l') rename ('lex.bibtex_parser_.c', 'biblex.c') class run_check (Command): """ Run all of the tests for the package using uninstalled (local) files """ description = "Automatically run the test suite for the package." user_options = [] def initialize_options(self): self.build_lib = None return def finalize_options(self): # Obtain the build_lib directory from the build command self.set_undefined_options ('build', ('build_lib', 'build_lib')) return def run(self): # Ensure the extension is built self.run_command ('build') # test the uninstalled extensions libdir = os.path.join (os.getcwd (), self.build_lib) sys.path.insert (0, libdir) import testsuite try: failures = testsuite.run () except RuntimeError, msg: sys.stderr.write ('error: %s\n' % msg) raise DistutilsExecError ('please consult the "Troubleshooting" section in the README file.') if failures > 0: raise DistutilsExecError ('check failed.') return class run_install (base_install): def run(self): # The code must pass the tests before being installed self.run_command ('check') base_install.run (self) return # Actual compilation setup (name = "python-bibtex", version = version, description = "A Python extension to parse BibTeX files", author = "Frederic Gobry", author_email = 'gobry@pybliographer.org', url = 'http://pybliographer.org/', license = 'GPL', cmdclass = { 'check': run_check, 'install': run_install }, long_description = \ ''' This module contains two extensions needed for pybliographer: - a bibtex parser - a simple binding to GNU Recode It requires the following libraries to be installed: - Glib-2.0 (and its development headers) - GNU Recode 3.5 (and its development headers) ''', ext_modules = [ Extension("_bibtex", bibtex, include_dirs = includes, library_dirs = libdirs, define_macros = [('G_LOG_DOMAIN', '"BibTeX"')], libraries = libs + ['recode']), Extension("_recode", ["recodemodule.c"], include_dirs = includes, libraries = ['recode']) ]) python-bibtex-1.2.5/field.c0000664000076400007640000000747511336332226014634 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: field.c,v 1.1.2.2 2003/09/02 14:35:33 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "bibtex.h" static GMemChunk * field_chunk = NULL; BibtexField * bibtex_field_new (BibtexFieldType type) { BibtexField * field; if (field_chunk == NULL) { field_chunk = g_mem_chunk_new ("BibtexField", sizeof (BibtexField), sizeof (BibtexField) * 16, G_ALLOC_AND_FREE); } field = g_chunk_new (BibtexField, field_chunk); field->structure = NULL; field->type = type; field->text = NULL; field->converted = FALSE; field->loss = FALSE; switch (field->type) { case BIBTEX_AUTHOR: /* Empty list */ field->field.author = NULL; break; case BIBTEX_DATE: field->field.date.year = 0; field->field.date.month = 0; field->field.date.day = 0; break; case BIBTEX_OTHER: case BIBTEX_TITLE: case BIBTEX_VERBATIM: break; default: g_warning ("unknown field type `%d'", field->type); bibtex_field_destroy (field, TRUE); return NULL; } return field; } void bibtex_field_destroy (BibtexField * field, gboolean value) { g_return_if_fail (field != NULL); if (value && field->structure) { bibtex_struct_destroy (field->structure, TRUE); } if (field->text) { g_free (field->text); } switch (field->type) { case BIBTEX_AUTHOR: if (field->field.author) { bibtex_author_group_destroy (field->field.author); } break; default: break; } g_chunk_free (field, field_chunk); } BibtexField * bibtex_struct_as_field (BibtexStruct * s, BibtexFieldType type) { BibtexField * field; g_return_val_if_fail (s != NULL, NULL); field = bibtex_field_new (type); field->structure = s; return field; } BibtexField * bibtex_field_parse (BibtexField * field, GHashTable * dico) { g_return_val_if_fail (field != NULL, NULL); if (field->converted) { /* Convert just once */ return field; } field->converted = TRUE; field->text = bibtex_struct_as_string (field->structure, field->type, dico, & field->loss); switch (field->type) { case BIBTEX_AUTHOR: field->field.author = bibtex_author_parse (field->structure, dico); break; case BIBTEX_DATE: field->field.date.year = atoi (field->text); field->field.date.month = 0; field->field.date.day = 0; break; default: break; } return field; } BibtexField * bibtex_string_as_field (gchar * string, BibtexFieldType type) { BibtexField * field = NULL; g_return_val_if_fail (string != NULL, NULL); field = bibtex_field_new (BIBTEX_OTHER); field->converted = TRUE; field->text = g_strdup (string); switch (type) { case BIBTEX_AUTHOR: case BIBTEX_DATE: case BIBTEX_TITLE: case BIBTEX_OTHER: case BIBTEX_VERBATIM: break; default: bibtex_field_destroy (field, TRUE); g_warning ("unknown type `%d' for string `%s'", type, string); return NULL; } return field; } python-bibtex-1.2.5/debugging.h0000664000076400007640000000120511336332226015472 0ustar zkotazkota#ifndef __debugging_h__ #define __debugging_h__ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #include static gchar * __my_strdup (gchar * text, gchar * file, gint line) { gchar * tmp = g_strdup (text); fprintf(stderr,"g_strdup: %x %s %d\n", tmp, file, line); return tmp; } static void __my_free (gpointer text, gchar *file, gint line) { fprintf(stderr,"g_free: %x %s %d\n", text, file, line); g_free (text); } #define g_strdup(text) __my_strdup (text,__FILE__,__LINE__) #define g_free(text) __my_free(text,__FILE__,__LINE__) #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* debugging.h */ python-bibtex-1.2.5/bibparse.h0000664000076400007640000000467511416711345015346 0ustar zkotazkota/* A Bison parser, made by GNU Bison 2.3. */ /* Skeleton interface for Bison's Yacc-like parsers in C Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ /* Tokens. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE /* Put the tokens into the symbol table, so that GDB and other debuggers know about them. */ enum yytokentype { end_of_file = 258, L_NAME = 259, L_DIGIT = 260, L_COMMAND = 261, L_BODY = 262, L_SPACE = 263, L_UBSPACE = 264 }; #endif /* Tokens. */ #define end_of_file 258 #define L_NAME 259 #define L_DIGIT 260 #define L_COMMAND 261 #define L_BODY 262 #define L_SPACE 263 #define L_UBSPACE 264 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE #line 193 "bibparse.y" { gchar * text; BibtexStruct * body; } /* Line 1489 of yacc.c. */ #line 72 "y.tab.h" YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 #endif extern YYSTYPE bibtex_parser_lval; python-bibtex-1.2.5/ChangeLog0000664000076400007640000003505611336332226015153 0ustar zkotazkota# do not edit -- automatically generated by arch changelog # arch-tag: automatic-ChangeLog--gobry@pybliographer.org--public/python-bibtex--stable--1.2 # 2007-04-24 17:32:48 GMT Frederic Gobry patch-35 Summary: merged with zoltan's branch Revision: python-bibtex--stable--1.2--patch-35 Patches applied: * kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-4 merged patch-33 from Frederic * kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-5 merge patch-34 from Frederic * kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-6 ready for 1.2.4 modified files: ChangeLog NEWS setup.py new patches: kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-4 kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-5 kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-6 2007-02-24 17:29:04 GMT Frederic Gobry patch-34 Summary: fixed bug in escaping non title fields Revision: python-bibtex--stable--1.2--patch-34 modified files: ChangeLog bibtexmodule.c testsuite.py 2007-01-19 10:39:19 GMT Frederic Gobry patch-33 Summary: merged doc updates from Zoltan Revision: python-bibtex--stable--1.2--patch-33 Patches applied: * kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-2 merge patch-31..32 from Frederic * kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-3 ready for release 1.2.3 modified files: ChangeLog NEWS setup.py new patches: kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-2 kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-3 2006-12-18 21:28:31 GMT Frederic Gobry patch-32 Summary: fixed parsing of standalone lowercase names, like "others" Revision: python-bibtex--stable--1.2--patch-32 new files: tests/.arch-ids/authors.bib-ok.id tests/.arch-ids/authors.bib.id tests/authors.bib tests/authors.bib-ok modified files: ChangeLog author.c bibtexmodule.c struct.c testsuite.py 2006-12-14 21:11:53 GMT Frederic Gobry patch-31 Summary: merged python2.5 compilation fixes from Zoltan Revision: python-bibtex--stable--1.2--patch-31 Patches applied: * kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--base-0 tag of gobry@pybliographer.org--public/python-bibtex--stable--1.2--patch-30 * kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-1 fix for python 2.5 modified files: ChangeLog bibtexmodule.c new patches: kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--base-0 kota@szbk.u-szeged.hu--pyblio/python-bibtex--stable--1.2--patch-1 2005-10-06 14:05:40 GMT Frederic Gobry patch-30 Summary: oops, forgot the NEWS file in the manifest Revision: python-bibtex--stable--1.2--patch-30 modified files: ChangeLog MANIFEST.in 2005-10-06 14:04:28 GMT Frederic Gobry patch-29 Summary: ready for release 1.2.2 Revision: python-bibtex--stable--1.2--patch-29 new files: .arch-ids/NEWS.id NEWS modified files: ChangeLog setup.py 2005-09-25 20:20:25 GMT Frederic Gobry patch-28 Summary: use the BIBTEX_VERBATIM type to specify no quoting in reverse () Revision: python-bibtex--stable--1.2--patch-28 modified files: ChangeLog bibtexmodule.c 2005-09-25 20:11:33 GMT Frederic Gobry patch-27 Summary: added support for "verbatim" fields, like urls Revision: python-bibtex--stable--1.2--patch-27 These fields have their ~ not escaped (so far, this overlaps the "quote" option of the reverse function) new files: tests/.arch-ids/url.bib-ok.id tests/.arch-ids/url.bib.id tests/url.bib tests/url.bib-ok modified files: ChangeLog bibparse.y bibtex.h bibtexmodule.c field.c reverse.c struct.c testsuite.py 2005-08-24 20:50:06 GMT Frederic Gobry patch-26 Summary: slight improvement in an error message Revision: python-bibtex--stable--1.2--patch-26 For extra commas in entry keys, the error message was speaking about a preamble problem. modified files: ChangeLog bibparse.y 2005-06-29 21:03:25 GMT Frederic Gobry patch-25 Summary: added a new parsing function next_unfiltered () Revision: python-bibtex--stable--1.2--patch-25 This function also returns @string and @preamble entries. Its return value is the same as next (), but encapsulated in an additional tuple, like: ('entry', ...) ('preamble', ...) ('string', ...) new files: tests/.arch-ids/preamble.bib-ok.id tests/.arch-ids/preamble.bib.id tests/.arch-ids/simple-2.bib-ok.id tests/.arch-ids/simple-2.bib.id tests/.arch-ids/string.bib-ok.id tests/.arch-ids/string.bib.id tests/preamble.bib tests/preamble.bib-ok tests/simple-2.bib tests/simple-2.bib-ok tests/string.bib tests/string.bib-ok modified files: ChangeLog bibtex.c bibtex.h bibtexmodule.c entry.c testsuite.py 2005-06-22 20:03:48 GMT Frederic Gobry patch-24 Summary: applied patch from mh21 for bug #1224723 Revision: python-bibtex--stable--1.2--patch-24 encode ÜII as \"{U}{II} modified files: ChangeLog reverse.c 2004-12-15 20:54:32 GMT Frederic Gobry patch-23 Summary: added a test for () in record key Revision: python-bibtex--stable--1.2--patch-23 new files: tests/.arch-ids/paren.bib-ok.id tests/.arch-ids/paren.bib.id tests/paren.bib tests/paren.bib-ok modified files: ChangeLog testsuite.py 2004-08-13 08:32:14 GMT Frederic Gobry patch-22 Summary: ready for release 1.2.1 Revision: python-bibtex--stable--1.2--patch-22 modified files: ChangeLog setup.py 2004-08-12 14:16:33 GMT Frederic Gobry patch-21 Summary: compilation fixes for AMD64 Revision: python-bibtex--stable--1.2--patch-21 Fix provided by Thomas Philipp via Karl Eichwalder. modified files: ChangeLog entry.c source.c 2004-06-21 19:05:59 GMT Frederic Gobry patch-20 Summary: fixed the remaining HEAD_INIT () Revision: python-bibtex--stable--1.2--patch-20 modified files: ChangeLog recodemodule.c 2004-06-14 19:57:49 GMT Frederic Gobry patch-19 Summary: attempt to fix building on windows Revision: python-bibtex--stable--1.2--patch-19 modified files: ChangeLog bibtexmodule.c recodemodule.c 2004-04-29 20:53:22 GMT Frederic Gobry patch-18 Summary: fink compliant Revision: python-bibtex--stable--1.2--patch-18 With a patched recode from fink, it is now possible to build the extension with: python setup.py build_ext -I /sw/include -L /sw/lib modified files: ChangeLog biblex.l reverse.c 2004-04-16 10:06:47 GMT Frederic Gobry patch-17 Summary: be ready to release version 1.2.0 Revision: python-bibtex--stable--1.2--patch-17 new files: .arch-ids/.arch-inventory.id .arch-inventory modified files: ChangeLog setup.py {arch}/=tagging-method 2004-04-16 09:59:01 GMT Frederic Gobry patch-16 Summary: fixed bug #932321 Revision: python-bibtex--stable--1.2--patch-16 Support ñ and Ñ. modified files: ChangeLog accents.c 2003-10-30 13:27:58 GMT Frederic Gobry patch-15 Summary: cosmetic fixes Revision: python-bibtex--stable--1.2--patch-15 modified files: ChangeLog README 2003-10-08 05:20:47 GMT Frederic Gobry patch-14 Summary: fixed archive content Revision: python-bibtex--stable--1.2--patch-14 The testsuite was missing from the archive modified files: ChangeLog MANIFEST.in setup.py 2003-10-05 19:04:56 GMT Frederic Gobry patch-13 Summary: prepare 1.1.93 Revision: python-bibtex--stable--1.2--patch-13 - fixed version number - distribute the changelog modified files: ChangeLog MANIFEST.in setup.py 2003-10-03 09:31:09 GMT Frederic Gobry patch-12 Summary: merged preliminary bibtex checks Revision: python-bibtex--stable--1.2--patch-12 Patches applied: * gobry@puck.ch--2003/python-bibtex--development--1.2--base-0 tag of gobry@pybliographer.org--public/python-bibtex--stable--1.2--patch-10 * gobry@puck.ch--2003/python-bibtex--development--1.2--patch-1 added a first trivial check for _bibtex * gobry@puck.ch--2003/python-bibtex--development--1.2--patch-2 removed C test program * gobry@puck.ch--2003/python-bibtex--development--1.2--patch-3 check for unfinished entries * gobry@puck.ch--2003/python-bibtex--development--1.2--patch-4 check for incomplete entries * gobry@puck.ch--2003/python-bibtex--development--1.2--patch-5 abort when some test fails new files: tests/.arch-ids/eof.bib-ok.id tests/.arch-ids/eof.bib.id tests/.arch-ids/simple.bib-ok.id tests/.arch-ids/simple.bib.id tests/eof.bib tests/eof.bib-ok tests/simple.bib tests/simple.bib-ok removed files: .arch-ids/testparser.c.id testparser.c modified files: ChangeLog bibtexmodule.c setup.py testsuite.py new patches: gobry@puck.ch--2003/python-bibtex--development--1.2--base-0 gobry@puck.ch--2003/python-bibtex--development--1.2--patch-1 gobry@puck.ch--2003/python-bibtex--development--1.2--patch-2 gobry@puck.ch--2003/python-bibtex--development--1.2--patch-3 gobry@puck.ch--2003/python-bibtex--development--1.2--patch-4 gobry@puck.ch--2003/python-bibtex--development--1.2--patch-5 2003-10-01 07:47:18 GMT Frederic Gobry patch-11 Summary: fix handling of bibtex_error as python exceptions Revision: python-bibtex--stable--1.2--patch-11 - The definition of G_LOG_DOMAIN=BibTeX was missing from the setup.py. - use the macro in the module file too. modified files: ./ChangeLog ./bibtexmodule.c ./setup.py 2003-09-24 07:46:34 GMT Frederic Gobry patch-10 Summary: even more verbose messages Revision: python-bibtex--stable--1.2--patch-10 - point to the Troubleshooting when a known problem is detected. - provide additional help in the README. modified files: ./ChangeLog ./README ./setup.py 2003-09-23 21:00:34 GMT Frederic Gobry patch-9 Summary: explicit error message for recode import problem Revision: python-bibtex--stable--1.2--patch-9 When recode is compiled under certain circumstances (notably recode 3.5 with gcc-3.3), recode_outer_new () can return NULL. This causes the module not to be loaded, but silentely. This patch adds a warning for this case. modified files: ./ChangeLog ./README ./recodemodule.c ./testsuite.py 2003-09-21 20:33:27 GMT Frederic Gobry patch-8 Summary: removed the "module" suffix Revision: python-bibtex--stable--1.2--patch-8 the generated python extensions do not need to be called _recodemodule.so, _recode.so is enough. modified files: ./ChangeLog ./setup.py 2003-09-19 15:04:57 GMT Frederic Gobry patch-7 Summary: explicit help for recode Revision: python-bibtex--stable--1.2--patch-7 - the error message is cleaner for broken recode - the README explains this specific error message modified files: ./ChangeLog ./README ./setup.py ./testsuite.py 2003-09-19 14:46:51 GMT Frederic Gobry patch-6 Summary: forbid installation of broken recode Revision: python-bibtex--stable--1.2--patch-6 the test suite checks that recode is not broken. modified files: ./ChangeLog ./testsuite.py 2003-09-19 14:19:49 GMT Frederic Gobry patch-5 Summary: .py[co] are precious Revision: python-bibtex--stable--1.2--patch-5 accept pyc files in the tree modified files: ./ChangeLog ./{arch}/=tagging-method 2003-09-19 14:14:59 GMT Frederic Gobry patch-4 Summary: test suite skeleton Revision: python-bibtex--stable--1.2--patch-4 added a testsuite that is automatically run before the module can be installed. new files: ./.arch-ids/testsuite.py.id ./tests/.arch-ids/=id ./testsuite.py modified files: ./ChangeLog ./setup.py new directories: ./tests ./tests/.arch-ids 2003-09-18 13:51:58 GMT Frederic Gobry patch-3 Summary: release 1.1.92 Revision: python-bibtex--stable--1.2--patch-3 - fixed setup.py to be declared as 1.1.92 modified files: ./ChangeLog ./setup.py 2003-09-17 20:03:34 GMT Frederic Gobry patch-2 Summary: project bookkeeping Revision: python-bibtex--stable--1.2--patch-2 - handling of build directories - added a changelog new files: ./.arch-ids/ChangeLog.id ./ChangeLog modified files: ./{arch}/=tagging-method 2003-09-17 20:01:45 GMT Frederic Gobry patch-1 Summary: fixed a memory leak Revision: python-bibtex--stable--1.2--patch-1 fixed a leak when the request is invalid. modified files: ./recodemodule.c 2003-09-16 12:07:11 GMT Frederic Gobry base-0 Summary: initial import Revision: python-bibtex--stable--1.2--base-0 (automatically generated log message) new files: ./MANIFEST.in ./README ./accents.c ./author.c ./biblex.l ./bibparse.y ./bibtex.c ./bibtex.h ./bibtexmodule.c ./debugging.h ./entry.c ./field.c ./logging.h ./recodemodule.c ./reverse.c ./setup.py ./source.c ./stringutils.c ./struct.c ./testparser.c python-bibtex-1.2.5/entry.c0000664000076400007640000000423311336332226014677 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: entry.c,v 1.1.2.1 2003/09/01 19:54:46 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "bibtex.h" static GMemChunk * entry_chunk = NULL; static void free_data_field (gpointer key, gpointer value, gpointer user) { g_free (key); if (user) { bibtex_field_destroy ((BibtexField *) value, TRUE); } } BibtexEntry * bibtex_entry_new (void) { BibtexEntry * entry; if (entry_chunk == NULL) { entry_chunk = g_mem_chunk_new ("BibtexEntry", sizeof (BibtexEntry), sizeof (BibtexEntry) * 16, G_ALLOC_AND_FREE); } entry = g_chunk_new (BibtexEntry, entry_chunk); entry->length = 0; entry->name = entry->type = NULL; entry->preamble = NULL; entry->textual_preamble = NULL; entry->table = g_hash_table_new (g_str_hash, g_str_equal); return entry; } void bibtex_entry_destroy (BibtexEntry * entry, gboolean content) { g_return_if_fail (entry != NULL); if (entry->type) g_free (entry->type); if (entry->name) g_free (entry->name); if (entry->textual_preamble) g_free (entry->textual_preamble); if (entry->preamble) bibtex_struct_destroy (entry->preamble, TRUE); g_hash_table_foreach (entry->table, free_data_field, GINT_TO_POINTER(content)); g_hash_table_destroy (entry->table); g_chunk_free (entry, entry_chunk); } python-bibtex-1.2.5/source.c0000664000076400007640000001157311336332226015043 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: source.c,v 1.1.2.1 2003/09/01 19:54:46 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "bibtex.h" BibtexSource * bibtex_source_new (void) { BibtexSource * new; new = g_new (BibtexSource, 1); new->name = NULL; new->type = BIBTEX_SOURCE_NONE; new->table = g_hash_table_new (g_str_hash, g_str_equal); new->debug = FALSE; new->buffer = NULL; new->strict = TRUE; return new; } static void reset_source (BibtexSource * source) { bibtex_analyzer_finish (source); if (source->name) { g_free (source->name); } switch (source->type) { case BIBTEX_SOURCE_NONE: break; case BIBTEX_SOURCE_FILE: fclose (source->source.file); break; case BIBTEX_SOURCE_STRING: g_free (source->source.string); break; default: g_assert_not_reached (); } source->offset = 0; source->line = 1; source->eof = FALSE; source->error = FALSE; } static void freedata (gpointer key, gpointer value, gpointer user) { g_free (key); if ((gboolean) GPOINTER_TO_INT(user)) { bibtex_struct_destroy ((BibtexStruct *) value, TRUE); } } BibtexStruct * bibtex_source_get_string (BibtexSource * source, gchar * key) { g_return_val_if_fail (source != NULL, NULL); g_return_val_if_fail (key != NULL, NULL); return g_hash_table_lookup (source->table, key); } void bibtex_source_set_string (BibtexSource * source, gchar * key, BibtexStruct * value) { gchar * inskey = key; BibtexStruct * oldstruct = NULL; g_return_if_fail (source != NULL); g_return_if_fail (key != NULL); if ((oldstruct = g_hash_table_lookup (source->table, inskey)) == NULL) { inskey = g_strdup (key); g_strdown (inskey); } else { bibtex_struct_destroy (oldstruct, TRUE); } g_hash_table_insert (source->table, inskey, value); } void bibtex_source_destroy (BibtexSource * source, gboolean free_data) { g_return_if_fail (source != NULL); g_hash_table_foreach (source->table, freedata, GINT_TO_POINTER(free_data)); g_hash_table_destroy (source->table); reset_source (source); g_free (source); } gboolean bibtex_source_file (BibtexSource * source, gchar * filename) { FILE * fh = NULL; g_return_val_if_fail (source != NULL, FALSE); g_return_val_if_fail (filename != NULL, FALSE); fh = fopen (filename, "r"); if (fh == NULL) { bibtex_error ("can't open file `%s': %s", filename, g_strerror (errno)); return FALSE; } reset_source (source); source->type = BIBTEX_SOURCE_FILE; source->name = g_strdup (filename); source->source.file = fh; bibtex_analyzer_initialize (source); return TRUE; } gboolean bibtex_source_string (BibtexSource * source, gchar * name, gchar * string) { g_return_val_if_fail (source != NULL, FALSE); g_return_val_if_fail (string != NULL, FALSE); reset_source (source); source->type = BIBTEX_SOURCE_STRING; if (name) { source->name = g_strdup (name); } else { source->name = g_strdup (""); } source->source.string = g_strdup (string); bibtex_analyzer_initialize (source); return TRUE; } void bibtex_source_rewind (BibtexSource * file) { bibtex_source_set_offset (file, 0); } gint bibtex_source_get_offset (BibtexSource * file) { g_return_val_if_fail (file != NULL, -1); return file->offset; } void bibtex_source_set_offset (BibtexSource * file, gint offset) { g_return_if_fail (file != NULL); bibtex_analyzer_finish (file); switch (file->type) { case BIBTEX_SOURCE_FILE: if (fseek (file->source.file, offset, SEEK_SET) == -1) { bibtex_error ("%s: can't jump to offset %d: %s", file->name, offset, g_strerror (errno)); file->error = TRUE; return; } break; case BIBTEX_SOURCE_STRING: break; case BIBTEX_SOURCE_NONE: g_warning ("no source to set offset"); break; } file->offset = offset; file->eof = file->error = FALSE; bibtex_analyzer_initialize (file); } python-bibtex-1.2.5/testsuite.py0000664000076400007640000001161211416700152015770 0ustar zkotazkota# -* coding: latin-1 -*- """ Run is the main function that will check if the recode and bibtex modules are working """ import sys, os def check_recode (): try: import _recode except SystemError: raise RuntimeError ('the recode library is probably broken.') # First, check if the recode version has the famous 3.6 bug rq = _recode.request ('latin1..latex') if _recode.recode (rq, 'abc') != 'abc': raise RuntimeError ('the _recode module is broken.') return 0 def expected_result (obtained, valid): if obtained == valid: return True try: return eval(obtained) == eval(valid) except SyntaxError: return False def check_bibtex (): _debug = False import _bibtex def checkfile (filename, strict = 1, typemap = {}): def expand (file, entry, type = -1): items = entry [4] for k in items.keys (): items [k] = _bibtex.expand (file, items [k], typemap.get (k, -1)) return file = _bibtex.open_file (filename, strict) result = open (filename + '-ok', 'r') line = 1 failures = 0 checks = 0 while 1: try: entry = _bibtex.next (file) if entry is None: break expand (file, entry) obtained = `entry` except IOError, msg: obtained = 'ParserError' if _debug: print obtained valid = result.readline ().strip () if not expected_result(obtained, valid): sys.stderr.write ('error: %s: line %d: unexpected result:\n' % ( filename, line)) sys.stderr.write ('error: %s: line %d: obtained %s\n' % ( filename, line, obtained)) sys.stderr.write ('error: %s: line %d: expected %s\n' % ( filename, line, valid)) failures = failures + 1 checks = checks + 1 return failures, checks def checkunfiltered (filename, strict = 1): def expand (file, entry): if entry [0] in ('preamble', 'string'): return items = entry [1] [4] for k in items.keys (): items [k] = _bibtex.expand (file, items [k], -1) return file = _bibtex.open_file (filename, strict) result = open (filename + '-ok', 'r') line = 1 failures = 0 checks = 0 while 1: try: entry = _bibtex.next_unfiltered (file) if entry is None: break expand (file, entry) obtained = `entry` except IOError, msg: obtained = 'ParserError' if _debug: print obtained valid = result.readline ().strip () if not expected_result(obtained, valid): sys.stderr.write ('error: %s: line %d: unexpected result:\n' % ( filename, line)) sys.stderr.write ('error: %s: line %d: obtained %s\n' % ( filename, line, obtained)) sys.stderr.write ('error: %s: line %d: expected %s\n' % ( filename, line, valid)) failures = failures + 1 checks = checks + 1 return failures, checks failures = 0 checks = 0 parser = _bibtex.open_file('/dev/null', True) def convert(text, t): field = _bibtex.reverse(t, True, text) return _bibtex.get_latex(parser, field, t) text = 'éssai A {} toto~tutu' for t, r in ((0, r'\'essai A \{\} toto~tutu'), (2, r'\'essai {A} \{\} toto~tutu'), (4, text)): checks += 1 o = convert(text, t) if o != r: print "type %d convert: got %r instead of %r" % ( t, o, r) failures += 1 for file in('tests/preamble.bib', 'tests/string.bib', 'tests/simple-2.bib'): f, c = checkunfiltered (file) failures = failures + f checks = checks + c failures += f checks += c for file in ('tests/simple.bib', 'tests/authors.bib', 'tests/eof.bib', 'tests/paren.bib', 'tests/url.bib'): f, c = checkfile (file, typemap = {'url': 4}) failures = failures + f checks = checks + c print "testsuite: %d checks, %d failures" % (checks, failures) return failures def run (): failures = 0 failures += check_recode () failures += check_bibtex () return failures python-bibtex-1.2.5/bibparse.c0000664000076400007640000015324111416711345015333 0ustar zkotazkota/* A Bison parser, made by GNU Bison 2.3. */ /* Skeleton implementation for Bison's Yacc-like parsers in C Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. There are some unavoidable exceptions within include files to define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ /* Identify Bison output. */ #define YYBISON 1 /* Bison version. */ #define YYBISON_VERSION "2.3" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" /* Pure parsers. */ #define YYPURE 0 /* Using locations. */ #define YYLSP_NEEDED 0 /* Substitute the variable and function names. */ #define yyparse bibtex_parser_parse #define yylex bibtex_parser_lex #define yyerror bibtex_parser_error #define yylval bibtex_parser_lval #define yychar bibtex_parser_char #define yydebug bibtex_parser_debug #define yynerrs bibtex_parser_nerrs /* Tokens. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE /* Put the tokens into the symbol table, so that GDB and other debuggers know about them. */ enum yytokentype { end_of_file = 258, L_NAME = 259, L_DIGIT = 260, L_COMMAND = 261, L_BODY = 262, L_SPACE = 263, L_UBSPACE = 264 }; #endif /* Tokens. */ #define end_of_file 258 #define L_NAME 259 #define L_DIGIT 260 #define L_COMMAND 261 #define L_BODY 262 #define L_SPACE 263 #define L_UBSPACE 264 /* Copy the first part of user declarations. */ #line 1 "bibparse.y" /* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: bibparse.y,v 1.1.2.2 2003/09/02 14:35:33 fredgo Exp $ */ /* #include "parsername.h" */ #include #include "bibtex.h" extern void bibtex_parser_initialize (BibtexSource *); extern void bibtex_parser_continue (BibtexSource *); extern void bibtex_parser_finish (BibtexSource *); extern int bibtex_parser_lex (void); int bibtex_parser_parse (void); extern gboolean bibtex_parser_is_content; extern int bibtex_parser_debug; static BibtexEntry * entry = NULL; static int start_line, entry_start; static BibtexSource * current_source; static gchar * error_string = NULL; static gchar * warning_string = NULL; static GString * tmp_string = NULL; static void nop (void) { return ; } void bibtex_next_line (void) { entry->length ++; } void bibtex_analyzer_initialize (BibtexSource * source) { bibtex_parser_initialize (source); } void bibtex_analyzer_finish (BibtexSource * source) { g_return_if_fail (source != NULL); bibtex_parser_finish (source); current_source = NULL; } BibtexEntry * bibtex_analyzer_parse (BibtexSource * source) { int ret; gboolean is_comment; g_return_val_if_fail (source != NULL, NULL); if (! tmp_string) { tmp_string = g_string_new (NULL); } current_source = source; bibtex_parser_debug = source->debug; start_line = source->line; entry_start = source->line + 1; entry = bibtex_entry_new (); bibtex_parser_continue (source); bibtex_parser_is_content = FALSE; ret = bibtex_parser_parse (); entry->start_line = entry_start; bibtex_tmp_string_free (); is_comment = (entry->type && (strcasecmp (entry->type, "comment") == 0)); if (warning_string && ! is_comment) { bibtex_warning (warning_string); } if (ret != 0) { source->line += entry->length; if (error_string && ! is_comment) { bibtex_error (error_string); } bibtex_entry_destroy (entry, TRUE); entry = NULL; } if (error_string) { g_free (error_string); error_string = NULL; } if (warning_string) { g_free (warning_string); warning_string = NULL; } return entry; } void bibtex_parser_error (char * s) { if (error_string) { g_free (error_string); } if (current_source) { error_string = g_strdup_printf ("%s:%d: %s", current_source->name, start_line + entry->length, s); } else { error_string = g_strdup_printf ("%d: %s", start_line + entry->length, s); } } void bibtex_parser_warning (char * s) { if (current_source) { warning_string = g_strdup_printf ("%s:%d: %s", current_source->name, start_line + entry->length, s); } else { warning_string = g_strdup_printf ("%d: %s", start_line + entry->length, s); } } static void bibtex_parser_start_error (char * s) { if (error_string) { g_free (error_string); } if (current_source) { error_string = g_strdup_printf ("%s:%d: %s", current_source->name, entry_start, s); } else { error_string = g_strdup_printf ("%d: %s", entry_start, s); } } static void bibtex_parser_start_warning (char * s) { if (current_source) { warning_string = g_strdup_printf ("%s:%d: %s", current_source->name, entry_start, s); } else { warning_string = g_strdup_printf ("%d: %s", entry_start, s); } } /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 1 #endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE # undef YYERROR_VERBOSE # define YYERROR_VERBOSE 1 #else # define YYERROR_VERBOSE 0 #endif /* Enabling the token table. */ #ifndef YYTOKEN_TABLE # define YYTOKEN_TABLE 0 #endif #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE #line 193 "bibparse.y" { gchar * text; BibtexStruct * body; } /* Line 187 of yacc.c. */ #line 319 "y.tab.c" YYSTYPE; # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 #endif /* Copy the second part of user declarations. */ /* Line 216 of yacc.c. */ #line 332 "y.tab.c" #ifdef short # undef short #endif #ifdef YYTYPE_UINT8 typedef YYTYPE_UINT8 yytype_uint8; #else typedef unsigned char yytype_uint8; #endif #ifdef YYTYPE_INT8 typedef YYTYPE_INT8 yytype_int8; #elif (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) typedef signed char yytype_int8; #else typedef short int yytype_int8; #endif #ifdef YYTYPE_UINT16 typedef YYTYPE_UINT16 yytype_uint16; #else typedef unsigned short int yytype_uint16; #endif #ifdef YYTYPE_INT16 typedef YYTYPE_INT16 yytype_int16; #else typedef short int yytype_int16; #endif #ifndef YYSIZE_T # ifdef __SIZE_TYPE__ # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else # define YYSIZE_T unsigned int # endif #endif #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ # if YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) # endif # endif # ifndef YY_ # define YY_(msgid) msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ # define YYUSE(e) ((void) (e)) #else # define YYUSE(e) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint # define YYID(n) (n) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static int YYID (int i) #else static int YYID (i) int i; #endif { return i; } #endif #if ! defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ # ifdef YYSTACK_USE_ALLOCA # if YYSTACK_USE_ALLOCA # ifdef __GNUC__ # define YYSTACK_ALLOC __builtin_alloca # elif defined __BUILTIN_VA_ARG_INCR # include /* INFRINGES ON USER NAME SPACE */ # elif defined _AIX # define YYSTACK_ALLOC __alloca # elif defined _MSC_VER # include /* INFRINGES ON USER NAME SPACE */ # define alloca _alloca # else # define YYSTACK_ALLOC alloca # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ # ifndef _STDLIB_H # define _STDLIB_H 1 # endif # endif # endif # endif # endif # ifdef YYSTACK_ALLOC /* Pacify GCC's `empty if-body' warning. */ # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) # ifndef YYSTACK_ALLOC_MAXIMUM /* The OS might guarantee only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely invoke alloca (N) if N exceeds 4096. Use a slightly smaller number to allow for a few compiler-allocated temporary stack slots. */ # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ # endif # else # define YYSTACK_ALLOC YYMALLOC # define YYSTACK_FREE YYFREE # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif # if (defined __cplusplus && ! defined _STDLIB_H \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ # ifndef _STDLIB_H # define _STDLIB_H 1 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { yytype_int16 yyss; YYSTYPE yyvs; }; /* The size of the maximum gap between one aligned stack and the next. */ # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) /* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else # define YYCOPY(To, From, Count) \ do \ { \ YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (To)[yyi] = (From)[yyi]; \ } \ while (YYID (0)) # endif # endif /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ # define YYSTACK_RELOCATE(Stack) \ do \ { \ YYSIZE_T yynewbytes; \ YYCOPY (&yyptr->Stack, Stack, yysize); \ Stack = &yyptr->Stack; \ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (YYID (0)) #endif /* YYFINAL -- State number of the termination state. */ #define YYFINAL 5 /* YYLAST -- Last index in YYTABLE. */ #define YYLAST 57 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 19 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 13 /* YYNRULES -- Number of rules. */ #define YYNRULES 33 /* YYNRULES -- Number of states. */ #define YYNSTATES 53 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 #define YYMAXUTOK 264 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 18, 17, 2, 2, 2, 2, 13, 14, 2, 2, 15, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 16, 2, 2, 10, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 11, 2, 12, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; #if YYDEBUG /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ static const yytype_uint8 yyprhs[] = { 0, 0, 3, 9, 15, 17, 23, 29, 35, 41, 45, 48, 50, 54, 56, 60, 62, 63, 68, 69, 74, 76, 78, 80, 82, 84, 88, 90, 92, 94, 95, 98, 101, 102 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yytype_int8 yyrhs[] = { 20, 0, -1, 10, 4, 11, 21, 12, -1, 10, 4, 13, 21, 14, -1, 3, -1, 10, 4, 13, 1, 14, -1, 10, 4, 11, 1, 12, -1, 10, 4, 13, 1, 3, -1, 10, 4, 11, 1, 3, -1, 22, 15, 21, -1, 22, 15, -1, 22, -1, 4, 16, 23, -1, 23, -1, 28, 17, 23, -1, 28, -1, -1, 11, 25, 30, 12, -1, -1, 18, 27, 31, 18, -1, 5, -1, 4, -1, 24, -1, 26, -1, 6, -1, 11, 30, 12, -1, 8, -1, 9, -1, 7, -1, -1, 18, 30, -1, 29, 30, -1, -1, 29, 31, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { 0, 222, 222, 231, 240, 247, 273, 299, 306, 320, 326, 332, 344, 393, 411, 417, 430, 430, 446, 446, 459, 466, 475, 481, 491, 498, 506, 512, 519, 532, 537, 546, 558, 563 }; #endif #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { "$end", "error", "$undefined", "end_of_file", "L_NAME", "L_DIGIT", "L_COMMAND", "L_BODY", "L_SPACE", "L_UBSPACE", "'@'", "'{'", "'}'", "'('", "')'", "','", "'='", "'#'", "'\"'", "$accept", "entry", "values", "value", "content", "content_brace", "@1", "content_quote", "@2", "simple_content", "text_part", "text_brace", "text_quote", 0 }; #endif # ifdef YYPRINT /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to token YYLEX-NUM. */ static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 64, 123, 125, 40, 41, 44, 61, 35, 34 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { 0, 19, 20, 20, 20, 20, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 25, 24, 27, 26, 28, 28, 28, 28, 29, 29, 29, 29, 29, 30, 30, 30, 31, 31 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const yytype_uint8 yyr2[] = { 0, 2, 5, 5, 1, 5, 5, 5, 5, 3, 2, 1, 3, 1, 3, 1, 0, 4, 0, 4, 1, 1, 1, 1, 1, 3, 1, 1, 1, 0, 2, 2, 0, 2 }; /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state STATE-NUM when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { 0, 4, 0, 0, 0, 1, 0, 0, 0, 21, 20, 16, 18, 0, 11, 13, 22, 23, 15, 0, 0, 8, 6, 0, 29, 32, 2, 10, 0, 7, 5, 3, 21, 12, 24, 28, 26, 27, 29, 29, 29, 0, 32, 0, 9, 14, 0, 30, 31, 17, 33, 19, 25 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { -1, 3, 13, 14, 15, 16, 24, 17, 25, 18, 40, 41, 43 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ #define YYPACT_NINF -24 static const yytype_int8 yypact[] = { 30, -24, -1, 37, 34, -24, 0, 5, 10, 32, -24, -24, -24, 38, 36, -24, -24, -24, 39, 12, 40, -24, -24, 3, 21, 35, -24, 20, 3, -24, -24, -24, -24, -24, -24, -24, -24, -24, 21, 21, 21, 41, 35, 31, -24, -24, 43, -24, -24, -24, -24, -24, -24 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { -24, -24, -7, -24, -11, -24, -24, -24, -24, -24, -23, -4, 15 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which number is the opposite. If zero, do what YYDEFACT says. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { 20, 8, 42, 4, 9, 10, 19, 32, 10, 9, 10, 11, 33, 21, 11, 29, 11, 45, 12, 42, 44, 12, 22, 12, 9, 10, 30, 34, 35, 36, 37, 11, 38, 1, 46, 47, 48, 5, 12, 39, 2, 34, 35, 36, 37, 6, 38, 7, 23, 51, 26, 27, 0, 49, 31, 52, 28, 50 }; static const yytype_int8 yycheck[] = { 7, 1, 25, 4, 4, 5, 1, 4, 5, 4, 5, 11, 23, 3, 11, 3, 11, 28, 18, 42, 27, 18, 12, 18, 4, 5, 14, 6, 7, 8, 9, 11, 11, 3, 38, 39, 40, 0, 18, 18, 10, 6, 7, 8, 9, 11, 11, 13, 16, 18, 12, 15, -1, 12, 14, 12, 17, 42 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { 0, 3, 10, 20, 4, 0, 11, 13, 1, 4, 5, 11, 18, 21, 22, 23, 24, 26, 28, 1, 21, 3, 12, 16, 25, 27, 12, 15, 17, 3, 14, 14, 4, 23, 6, 7, 8, 9, 11, 18, 29, 30, 29, 31, 21, 23, 30, 30, 30, 12, 31, 18, 12 }; #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYEMPTY (-2) #define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. Once GCC version 2 has supplanted version 1, this can go. */ #define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) #define YYBACKUP(Token, Value) \ do \ if (yychar == YYEMPTY && yylen == 1) \ { \ yychar = (Token); \ yylval = (Value); \ yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK (1); \ goto yybackup; \ } \ else \ { \ yyerror (YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) #define YYTERROR 1 #define YYERRCODE 256 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ #define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ do \ if (YYID (N)) \ { \ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ } \ else \ { \ (Current).first_line = (Current).last_line = \ YYRHSLOC (Rhs, 0).last_line; \ (Current).first_column = (Current).last_column = \ YYRHSLOC (Rhs, 0).last_column; \ } \ while (YYID (0)) #endif /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT # if YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ (Loc).last_line, (Loc).last_column) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif #endif /* YYLEX -- calling `yylex' with the right arguments. */ #ifdef YYLEX_PARAM # define YYLEX yylex (YYLEX_PARAM) #else # define YYLEX yylex () #endif /* Enable debugging if requested. */ #if YYDEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ # define YYFPRINTF fprintf # endif # define YYDPRINTF(Args) \ do { \ if (yydebug) \ YYFPRINTF Args; \ } while (YYID (0)) # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ Type, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (YYID (0)) /*--------------------------------. | Print this symbol on YYOUTPUT. | `--------------------------------*/ /*ARGSUSED*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else static void yy_symbol_value_print (yyoutput, yytype, yyvaluep) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; #endif { if (!yyvaluep) return; # ifdef YYPRINT if (yytype < YYNTOKENS) YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); # else YYUSE (yyoutput); # endif switch (yytype) { default: break; } } /*--------------------------------. | Print this symbol on YYOUTPUT. | `--------------------------------*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else static void yy_symbol_print (yyoutput, yytype, yyvaluep) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; #endif { if (yytype < YYNTOKENS) YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); yy_symbol_value_print (yyoutput, yytype, yyvaluep); YYFPRINTF (yyoutput, ")"); } /*------------------------------------------------------------------. | yy_stack_print -- Print the state stack from its BOTTOM up to its | | TOP (included). | `------------------------------------------------------------------*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_stack_print (yytype_int16 *bottom, yytype_int16 *top) #else static void yy_stack_print (bottom, top) yytype_int16 *bottom; yytype_int16 *top; #endif { YYFPRINTF (stderr, "Stack now"); for (; bottom <= top; ++bottom) YYFPRINTF (stderr, " %d", *bottom); YYFPRINTF (stderr, "\n"); } # define YY_STACK_PRINT(Bottom, Top) \ do { \ if (yydebug) \ yy_stack_print ((Bottom), (Top)); \ } while (YYID (0)) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_reduce_print (YYSTYPE *yyvsp, int yyrule) #else static void yy_reduce_print (yyvsp, yyrule) YYSTYPE *yyvsp; int yyrule; #endif { int yynrhs = yyr2[yyrule]; int yyi; unsigned long int yylno = yyrline[yyrule]; YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { fprintf (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) ); fprintf (stderr, "\n"); } } # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ yy_reduce_print (yyvsp, Rule); \ } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) # define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only if the built-in stack extension method is used). Do not make this value too large; the results are undefined if YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH # define YYMAXDEPTH 10000 #endif #if YYERROR_VERBOSE # ifndef yystrlen # if defined __GLIBC__ && defined _STRING_H # define yystrlen strlen # else /* Return the length of YYSTR. */ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static YYSIZE_T yystrlen (const char *yystr) #else static YYSIZE_T yystrlen (yystr) const char *yystr; #endif { YYSIZE_T yylen; for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } # endif # endif # ifndef yystpcpy # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE # define yystpcpy stpcpy # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static char * yystpcpy (char *yydest, const char *yysrc) #else static char * yystpcpy (yydest, yysrc) char *yydest; const char *yysrc; #endif { char *yyd = yydest; const char *yys = yysrc; while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } # endif # endif # ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string contains an apostrophe, a comma, or backslash (other than backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ static YYSIZE_T yytnamerr (char *yyres, const char *yystr) { if (*yystr == '"') { YYSIZE_T yyn = 0; char const *yyp = yystr; for (;;) switch (*++yyp) { case '\'': case ',': goto do_not_strip_quotes; case '\\': if (*++yyp != '\\') goto do_not_strip_quotes; /* Fall through. */ default: if (yyres) yyres[yyn] = *yyp; yyn++; break; case '"': if (yyres) yyres[yyn] = '\0'; return yyn; } do_not_strip_quotes: ; } if (! yyres) return yystrlen (yystr); return yystpcpy (yyres, yystr) - yyres; } # endif /* Copy into YYRESULT an error message about the unexpected token YYCHAR while in state YYSTATE. Return the number of bytes copied, including the terminating null byte. If YYRESULT is null, do not copy anything; just return the number of bytes that would be copied. As a special case, return 0 if an ordinary "syntax error" message will do. Return YYSIZE_MAXIMUM if overflow occurs during size calculation. */ static YYSIZE_T yysyntax_error (char *yyresult, int yystate, int yychar) { int yyn = yypact[yystate]; if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) return 0; else { int yytype = YYTRANSLATE (yychar); YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); YYSIZE_T yysize = yysize0; YYSIZE_T yysize1; int yysize_overflow = 0; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; int yyx; # if 0 /* This is so xgettext sees the translatable formats that are constructed on the fly. */ YY_("syntax error, unexpected %s"); YY_("syntax error, unexpected %s, expecting %s"); YY_("syntax error, unexpected %s, expecting %s or %s"); YY_("syntax error, unexpected %s, expecting %s or %s or %s"); YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); # endif char *yyfmt; char const *yyf; static char const yyunexpected[] = "syntax error, unexpected %s"; static char const yyexpecting[] = ", expecting %s"; static char const yyor[] = " or %s"; char yyformat[sizeof yyunexpected + sizeof yyexpecting - 1 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) * (sizeof yyor - 1))]; char const *yyprefix = yyexpecting; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ int yyxbegin = yyn < 0 ? -yyn : 0; /* Stay within bounds of both yycheck and yytname. */ int yychecklim = YYLAST - yyn + 1; int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; int yycount = 1; yyarg[0] = yytname[yytype]; yyfmt = yystpcpy (yyformat, yyunexpected); for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) { if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) { yycount = 1; yysize = yysize0; yyformat[sizeof yyunexpected - 1] = '\0'; break; } yyarg[yycount++] = yytname[yyx]; yysize1 = yysize + yytnamerr (0, yytname[yyx]); yysize_overflow |= (yysize1 < yysize); yysize = yysize1; yyfmt = yystpcpy (yyfmt, yyprefix); yyprefix = yyor; } yyf = YY_(yyformat); yysize1 = yysize + yystrlen (yyf); yysize_overflow |= (yysize1 < yysize); yysize = yysize1; if (yysize_overflow) return YYSIZE_MAXIMUM; if (yyresult) { /* Avoid sprintf, as that infringes on the user's name space. Don't have undefined behavior even if the translation produced a string with the wrong number of "%s"s. */ char *yyp = yyresult; int yyi = 0; while ((*yyp = *yyf) != '\0') { if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) { yyp += yytnamerr (yyp, yyarg[yyi++]); yyf += 2; } else { yyp++; yyf++; } } } return yysize; } } #endif /* YYERROR_VERBOSE */ /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ /*ARGSUSED*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) #else static void yydestruct (yymsg, yytype, yyvaluep) const char *yymsg; int yytype; YYSTYPE *yyvaluep; #endif { YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); switch (yytype) { default: break; } } /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus int yyparse (void *YYPARSE_PARAM); #else int yyparse (); #endif #else /* ! YYPARSE_PARAM */ #if defined __STDC__ || defined __cplusplus int yyparse (void); #else int yyparse (); #endif #endif /* ! YYPARSE_PARAM */ /* The look-ahead symbol. */ int yychar; /* The semantic value of the look-ahead symbol. */ YYSTYPE yylval; /* Number of syntax errors so far. */ int yynerrs; /*----------. | yyparse. | `----------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int yyparse (void *YYPARSE_PARAM) #else int yyparse (YYPARSE_PARAM) void *YYPARSE_PARAM; #endif #else /* ! YYPARSE_PARAM */ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int yyparse (void) #else int yyparse () #endif #endif { int yystate; int yyn; int yyresult; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; /* Look-ahead token as an internal (translated) token number. */ int yytoken = 0; #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif /* Three stacks and their tools: `yyss': related to states, `yyvs': related to semantic values, `yyls': related to locations. Refer to the stacks thru separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ yytype_int16 yyssa[YYINITDEPTH]; yytype_int16 *yyss = yyssa; yytype_int16 *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs = yyvsa; YYSTYPE *yyvsp; #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) YYSIZE_T yystacksize = YYINITDEPTH; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ /* Initialize stack pointers. Waste one element of value and location stack so that they stay on the same level as the state stack. The wasted elements are never initialized. */ yyssp = yyss; yyvsp = yyvs; goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) { /* Get the current used size of the three stacks, in elements. */ YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; yytype_int16 *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE goto yyexhaustedlab; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { yytype_int16 *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss); YYSTACK_RELOCATE (yyvs); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* Do appropriate processing given the current state. Read a look-ahead token if we need one and don't already have one. */ /* First try to decide what to do without reference to look-ahead token. */ yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; /* Not known => get a look-ahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; } if (yychar <= YYEOF) { yychar = yytoken = YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) { if (yyn == 0 || yyn == YYTABLE_NINF) goto yyerrlab; yyn = -yyn; goto yyreduce; } if (yyn == YYFINAL) YYACCEPT; /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; /* Shift the look-ahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token unless it is eof. */ if (yychar != YYEOF) yychar = YYEMPTY; yystate = yyn; *++yyvsp = yylval; goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; YY_REDUCE_PRINT (yyn); switch (yyn) { case 2: #line 224 "bibparse.y" { entry->type = g_strdup ((yyvsp[(2) - (5)].text)); g_strdown (entry->type); YYACCEPT; } break; case 3: #line 233 "bibparse.y" { entry->type = g_strdup ((yyvsp[(2) - (5)].text)); g_strdown (entry->type); YYACCEPT; } break; case 4: #line 242 "bibparse.y" { current_source->eof = TRUE; YYABORT; } break; case 5: #line 249 "bibparse.y" { if (strcasecmp ((yyvsp[(2) - (5)].text), "comment") == 0) { entry->type = g_strdup ((yyvsp[(2) - (5)].text)); g_strdown (entry->type); yyclearin; YYACCEPT; } if (current_source->strict) { bibtex_parser_start_error ("perhaps a missing coma"); YYABORT; } else { bibtex_parser_start_warning ("perhaps a missing coma."); entry->type = g_strdup ((yyvsp[(2) - (5)].text)); g_strdown (entry->type); yyclearin; YYACCEPT; } } break; case 6: #line 275 "bibparse.y" { if (strcasecmp ((yyvsp[(2) - (5)].text), "comment") == 0) { entry->type = g_strdup ((yyvsp[(2) - (5)].text)); g_strdown (entry->type); yyclearin; YYACCEPT; } if (current_source->strict) { bibtex_parser_start_error ("perhaps a missing coma"); YYABORT; } else { bibtex_parser_start_warning ("perhaps a missing coma"); entry->type = g_strdup ((yyvsp[(2) - (5)].text)); g_strdown (entry->type); yyclearin; YYACCEPT; } } break; case 7: #line 301 "bibparse.y" { bibtex_parser_start_error ("end of file during processing"); YYABORT; } break; case 8: #line 308 "bibparse.y" { bibtex_parser_start_error ("end of file during processing"); YYABORT; } break; case 9: #line 322 "bibparse.y" { nop (); } break; case 10: #line 328 "bibparse.y" { nop (); } break; case 11: #line 334 "bibparse.y" { nop (); } break; case 12: #line 346 "bibparse.y" { char * name; BibtexField * field; BibtexFieldType type = BIBTEX_OTHER; g_strdown ((yyvsp[(1) - (3)].text)); field = g_hash_table_lookup (entry->table, (yyvsp[(1) - (3)].text)); /* Get a new instance of a field name */ if (field) { g_string_sprintf (tmp_string, "field `%s' is already defined", (yyvsp[(1) - (3)].text)); bibtex_parser_warning (tmp_string->str); bibtex_field_destroy (field, TRUE); name = (yyvsp[(1) - (3)].text); } else { name = g_strdup ((yyvsp[(1) - (3)].text)); } /* Search its type */ do { if (strcmp (name, "author") == 0) { type = BIBTEX_AUTHOR; break; } if (strcmp (name, "title") == 0) { type = BIBTEX_TITLE; break; } if (strcmp (name, "year") == 0) { type = BIBTEX_DATE; break; } } while (0); /* Convert into the right field */ field = bibtex_struct_as_field (bibtex_struct_flatten ((yyvsp[(3) - (3)].body)), type); g_hash_table_insert (entry->table, name, field); } break; case 13: #line 395 "bibparse.y" { entry_start = start_line + entry->length; if (entry->preamble) { bibtex_parser_start_error ("entry already contains a preamble or has an unexpected comma in its key"); YYABORT; } entry->preamble = (yyvsp[(1) - (1)].body); } break; case 14: #line 413 "bibparse.y" { (yyval.body) = bibtex_struct_append ((yyvsp[(1) - (3)].body), (yyvsp[(3) - (3)].body)); } break; case 15: #line 419 "bibparse.y" { (yyval.body) = (yyvsp[(1) - (1)].body); } break; case 16: #line 430 "bibparse.y" { bibtex_parser_is_content = TRUE; } break; case 17: #line 433 "bibparse.y" { bibtex_parser_is_content = FALSE; (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_SUB); (yyval.body)->value.sub->encloser = BIBTEX_ENCLOSER_BRACE; (yyval.body)->value.sub->content = (yyvsp[(3) - (4)].body); } break; case 18: #line 446 "bibparse.y" { bibtex_parser_is_content = TRUE; } break; case 19: #line 449 "bibparse.y" { bibtex_parser_is_content = FALSE; (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_SUB); (yyval.body)->value.sub->encloser = BIBTEX_ENCLOSER_QUOTE; (yyval.body)->value.sub->content = (yyvsp[(3) - (4)].body); } break; case 20: #line 461 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_TEXT); (yyval.body)->value.text = g_strdup ((yyvsp[(1) - (1)].text)); } break; case 21: #line 468 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_REF); (yyval.body)->value.ref = g_strdup ((yyvsp[(1) - (1)].text)); /* g_strdown ($$->value.ref); */ } break; case 22: #line 477 "bibparse.y" { (yyval.body) = (yyvsp[(1) - (1)].body); } break; case 23: #line 483 "bibparse.y" { (yyval.body) = (yyvsp[(1) - (1)].body); } break; case 24: #line 493 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_COMMAND); (yyval.body)->value.com = g_strdup ((yyvsp[(1) - (1)].text) + 1); } break; case 25: #line 500 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_SUB); (yyval.body)->value.sub->encloser = BIBTEX_ENCLOSER_BRACE; (yyval.body)->value.sub->content = (yyvsp[(2) - (3)].body); } break; case 26: #line 508 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_SPACE); } break; case 27: #line 514 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_SPACE); (yyval.body)->value.unbreakable = TRUE; } break; case 28: #line 521 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_TEXT); (yyval.body)->value.text = g_strdup ((yyvsp[(1) - (1)].text)); } break; case 29: #line 532 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_TEXT); (yyval.body)->value.text = g_strdup (""); } break; case 30: #line 539 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_TEXT); (yyval.body)->value.text = g_strdup ("\""); (yyval.body) = bibtex_struct_append ((yyval.body), (yyvsp[(2) - (2)].body)); } break; case 31: #line 548 "bibparse.y" { (yyval.body) = bibtex_struct_append ((yyvsp[(1) - (2)].body), (yyvsp[(2) - (2)].body)); } break; case 32: #line 558 "bibparse.y" { (yyval.body) = bibtex_struct_new (BIBTEX_STRUCT_TEXT); (yyval.body)->value.text = g_strdup (""); } break; case 33: #line 565 "bibparse.y" { (yyval.body) = bibtex_struct_append ((yyvsp[(1) - (2)].body), (yyvsp[(2) - (2)].body)); } break; /* Line 1267 of yacc.c. */ #line 1906 "y.tab.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; /* Now `shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; /*------------------------------------. | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else { YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) { YYSIZE_T yyalloc = 2 * yysize; if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) yyalloc = YYSTACK_ALLOC_MAXIMUM; if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); yymsg = (char *) YYSTACK_ALLOC (yyalloc); if (yymsg) yymsg_alloc = yyalloc; else { yymsg = yymsgbuf; yymsg_alloc = sizeof yymsgbuf; } } if (0 < yysize && yysize <= yymsg_alloc) { (void) yysyntax_error (yymsg, yystate, yychar); yyerror (yymsg); } else { yyerror (YY_("syntax error")); if (yysize != 0) goto yyexhaustedlab; } } #endif } if (yyerrstatus == 3) { /* If just tried and failed to reuse look-ahead token after an error, discard it. */ if (yychar <= YYEOF) { /* Return failure if at end of input. */ if (yychar == YYEOF) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval); yychar = YYEMPTY; } } /* Else will try to reuse look-ahead token after shifting the error token. */ goto yyerrlab1; /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: /* Pacify compilers like GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ if (/*CONSTCOND*/ 0) goto yyerrorlab; /* Do not reclaim the symbols of the rule which action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); yystate = *yyssp; goto yyerrlab1; /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; if (yyn != YYPACT_NINF) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { yyn = yytable[yyn]; if (0 < yyn) break; } } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) YYABORT; yydestruct ("Error: popping", yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } if (yyn == YYFINAL) YYACCEPT; *++yyvsp = yylval; /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; #ifndef yyoverflow /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEOF && yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", yytoken, &yylval); /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif #if YYERROR_VERBOSE if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); #endif /* Make sure YYID is used. */ return YYID (yyresult); } #line 572 "bibparse.y" python-bibtex-1.2.5/stringutils.c0000664000076400007640000000240011336332226016117 0ustar zkotazkota/* This file is part of pybliographer Copyright (C) 1998-1999 Frederic GOBRY Email : gobry@idiap.ch This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id: stringutils.c,v 1.1.2.1 2003/09/01 19:54:46 fredgo Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "bibtex.h" static GList * strings = NULL; gchar * bibtex_tmp_string (gchar * string) { strings = g_list_append (strings, string); return string; } void bibtex_tmp_string_free (void) { GList * tmp = strings; while (tmp) { g_free (tmp->data); tmp = tmp->next; } g_list_free (strings); strings = NULL; }