📄 lexpgn.c
字号:
-146, -146, -146, -146, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 151, 81, 81, 81, 81, 81, 81, -146, -146 }, { 17, -147, -147, -147, -147, -147, -147, -147, -147, -147, -147, -147, -147, -147, -147, -147, 81, 81, 81, 81, -147, -147, -147, -147, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 152, 81, 81, 81, -147, -147 }, { 17, -148, 148, 148, 148, 148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148, -148 }, { 17, -149, -149, -149, -149, -149, -149, -149, -149, -149, -149, -149, -149, -149, -149, -149, 81, 81, 81, 81, -149, -149, -149, -149, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, -149, -149 }, { 17, -150, -150, -150, -150, -150, -150, -150, -150, -150, -150, -150, -150, -150, -150, -150, 81, 81, 81, 81, -150, -150, -150, -150, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 153, 81, 81, 81, 81, 81, 81, 81, 81, -150, -150 }, { 17, -151, -151, -151, -151, -151, -151, -151, -151, -151, -151, -151, -151, -151, -151, -151, 81, 81, 81, 81, -151, -151, -151, -151, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, -151, -151 }, { 17, -152, -152, -152, -152, -152, -152, -152, -152, -152, -152, -152, -152, -152, -152, -152, 81, 81, 81, 81, -152, -152, -152, -152, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 154, 81, 81, 81, 81, 81, 81, 81, 81, -152, -152 }, { 17, -153, -153, -153, -153, -153, -153, -153, -153, -153, -153, -153, -153, -153, -153, -153, 81, 81, 81, 81, -153, -153, -153, -153, 81, 81, 81, 81, 81, 155, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, -153, -153 }, { 17, -154, -154, -154, -154, -154, -154, -154, -154, -154, -154, -154, -154, -154, -154, -154, 81, 81, 81, 81, -154, -154, -154, -154, 81, 81, 81, 81, 81, 156, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, -154, -154 }, { 17, -155, -155, -155, -155, -155, -155, -155, -155, -155, -155, -155, -155, -155, -155, -155, 81, 81, 81, 81, -155, -155, -155, -155, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, -155, -155 }, { 17, -156, -156, -156, -156, -156, -156, -156, -156, -156, -156, -156, -156, -156, -156, -156, 81, 81, 81, 81, -156, -156, -156, -156, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, 81, -156, -156 }, } ;static yy_state_type yy_get_previous_state YY_PROTO(( void ));static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));static int yy_get_next_buffer YY_PROTO(( void ));static void yy_fatal_error YY_PROTO(( yyconst char msg[] ));/* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */#define YY_DO_BEFORE_ACTION \ yytext_ptr = yy_bp; \ yyleng = (int) (yy_cp - yy_bp); \ yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ yy_c_buf_p = yy_cp;#define YY_NUM_RULES 51#define YY_END_OF_BUFFER 52static yyconst short int yy_accept[157] = { 0, 0, 0, 4, 4, 0, 0, 0, 0, 23, 23, 27, 27, 0, 0, 0, 0, 52, 50, 1, 1, 36, 2, 44, 37, 50, 43, 41, 41, 28, 3, 43, 29, 4, 51, 20, 20, 19, 19, 17, 18, 17, 17, 17, 17, 17, 17, 17, 22, 21, 23, 26, 26, 25, 23, 27, 30, 35, 34, 31, 47, 45, 46, 49, 49, 1, 36, 2, 37, 42, 43, 43, 0, 41, 0, 41, 28, 3, 4, 0, 18, 17, 17, 17, 17, 17, 17, 17, 17, 17, 21, 21, 23, 23, 25, 25, 24, 27, 30, 30, 32, 33, 47, 0, 39, 40, 0, 17, 17, 17, 10, 17, 17, 17, 17, 24, 30, 0, 39, 40, 0, 17, 13, 17, 17, 17, 12, 17, 0, 0, 6, 11, 17, 14, 5, 0, 0, 17, 17, 7, 17, 17, 48, 38, 17, 17, 17, 17, 38, 16, 17, 15, 17, 17, 17, 9, 8 } ;static yyconst int yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 6, 7, 6, 8, 9, 1, 1, 10, 11, 12, 6, 6, 13, 14, 15, 16, 17, 18, 19, 19, 19, 19, 19, 19, 19, 1, 20, 1, 6, 1, 6, 1, 25, 26, 27, 28, 29, 30, 31, 32, 33, 31, 34, 35, 31, 36, 37, 31, 31, 38, 39, 40, 41, 42, 43, 31, 31, 31, 21, 22, 23, 1, 24, 1, 25, 26, 27, 28, 29, 30, 31, 32, 33, 31, 34, 35, 31, 36, 37, 31, 31, 38, 39, 40, 41, 42, 43, 31, 31, 31, 44, 1, 45, 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, 1 } ;static yy_state_type yy_last_accepting_state;static char *yy_last_accepting_cpos;/* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */#define REJECT reject_used_but_not_detected#define yymore() yymore_used_but_not_detected#define YY_MORE_ADJ 0#define YY_RESTORE_YY_MORE_OFFSETchar *yytext;#line 1 "lexpgn.l"#define INITIAL 0#line 2 "lexpgn.l"/* lexpgn by David A. Wheeler (http://www.dwheeler.com). This code processes files formatted using PGN, as defined in "Standard Portable Game Notation Specification and Implementation Guide" Revised 1994.03.12 by Steven J. Edwards. This code lexically analyzes PGN files as an import format; since it's importing, it tries to accept nonstandard formats as much as it can and figure out the "intent". It handles varying newlines (e.g. \r), etc. It will accept a great deal of misformatting that isn't, strictly speaking, legal PGN, but the point is to be able to figure out what was intended. Calling the lexer will process ONE game in a file, starting with 0 or more tags, followed by 0 or more moves. It returns 0 if no erors, 1 if errors, 2 if terminated (normally). It will place data somewhere depending on the value of data_dest; if data_dest is DEST_TRASH, it skips the game (not fully implemented), if data_dest is DEST_GAME, it stores into Game[], if data_dest is DEST_BOOK, it's stored into the book material. To process a multi-game PGN file, call it again and again. Some of the funny ordering (e.g., for bracecomment) is to make it high speed. Flex/lex can produce high speed lexers, but only if it gets some help, in particular by defining patterns that maximally match. TODO: prevent buffer overflow for FEN.*/#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <string.h>#include "common.h"#include "lexpgn.h"#include "book.h"enum tagtype { NO_TAG, EVENT_TAG, SITE_TAG, DATE_TAG, ROUND_TAG, WHITE_TAG, BLACK_TAG, RESULT_TAG, WHITE_ELO_TAG, BLACK_ELO_TAG, WHITETITLE_TAG, BLACKTITLE_TAG, FEN_TAG, OTHER_TAG };enum data_destination_t data_dest;#define yyterminate() { if ( seen_tags || seen_moves) return 1; \ return 2; } char *pgn_event;char *pgn_site;char *pgn_date;char *pgn_round;char *pgn_white;char *pgn_black;char *pgn_result;char *pgn_whiteELO;char *pgn_blackELO;char *pgn_othertags;char *initial_comments; /* PGN comments before any moves */char *return_append_str(char *dest, const char *s) {/* Append text s to dest, and return new result. */ char *newloc; size_t newlen; /* This doesn't have buffer overflow vulnerabilities, because we always allocate for enough space before appending. */ if (!dest) { newloc = (char *) malloc(strlen(s))+1; strcpy(newloc, s); return newloc; } newlen = strlen(dest) + strlen(s) + 1; newloc = (char *) malloc(newlen); strcpy(newloc, dest); if (!newloc) return dest; /* Can't do it, throw away the data */ strcat(newloc, s); return newloc;}void append_str(char **dest, const char *s) {/* Append text s to *dest, and modify *dest to new location. */ char *temp; temp = return_append_str(*dest, s); *dest = temp;}void append_comment(const char *t) {/* Append PGN text t after the current move */ if (data_dest == DEST_GAME) { /* TODO */ if (GameCnt < 1) { append_str(&initial_comments,t); } else { append_str(&(Game[GameCnt].comments),t); } }}#define tag_gobble 1#define tagsymbol 2#define tagsep 3#define tagdata 4#define tagend 5#define bracecomment 6#define RAV 7#line 1819 "lexpgn.c"/* Macros after this point can all be overridden by user definitions in * section 1. */#ifndef YY_SKIP_YYWRAP#ifdef __cplusplusextern "C" int yywrap YY_PROTO(( void ));#elseextern int yywrap YY_PROTO(( void ));#endif#endif#ifndef YY_NO_UNPUTstatic void yyunput YY_PROTO(( int c, char *buf_ptr ));#endif#ifndef yytext_ptrstatic void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int ));#endif#ifdef YY_NEED_STRLENstatic int yy_flex_strlen YY_PROTO(( yyconst char * ));#endif#ifndef YY_NO_INPUT#ifdef __cplusplusstatic int yyinput YY_PROTO(( void ));#elsestatic int input YY_PROTO(( void ));#endif#endif#if YY_STACK_USEDstatic int yy_start_stack_ptr = 0;static int yy_start_stack_depth = 0;static int *yy_start_stack = 0;#ifndef YY_NO_PUSH_STATEstatic void yy_push_state YY_PROTO(( int new_state ));#endif#ifndef YY_NO_POP_STATEstatic void yy_pop_state YY_PROTO(( void ));#endif#ifndef YY_NO_TOP_STATEstatic int yy_top_state YY_PROTO(( void ));#endif#else#define YY_NO_PUSH_STATE 1#define YY_NO_POP_STATE 1#define YY_NO_TOP_STATE 1#endif#ifdef YY_MALLOC_DECLYY_MALLOC_DECL#else#if __STDC__#ifndef __cplusplus#include <stdlib.h>#endif#else/* Just try to get by without declaring the routines. This will fail * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) * or sizeof(void*) != sizeof(int). */#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 (vo
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -