From: William D. <wdo...@us...> - 2005-01-24 20:44:27
|
Update of /cvsroot/flexml/flexml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7371 Modified Files: skel Log Message: - Handle ] at end of CDATA like: <![CDATA[val xxx]]]>; - Do not print to stderr: add primitive error message facility; - Allow multiple calls/multiple returns, so flexml-generated parsers can parse document sequences (>1 document in a stream); - Allow failure from all states (<*>) so flex scanner jammed does not occur. Index: skel =================================================================== RCS file: /cvsroot/flexml/flexml/skel,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** skel 5 Jan 2005 18:49:27 -0000 1.19 --- skel 24 Jan 2005 20:44:03 -0000 1.20 *************** *** 1,8 **** /* Flex(1) XML processor skeleton scanner (in -*-C-*-). * Copyright © 1999 Kristoffer Rose. All rights reserved. ! * * This file is part of the FleXML XML processor generator system. * Copyright © 1999 Kristoffer Rose. All rights reserved. ! * * 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 --- 1,8 ---- /* Flex(1) XML processor skeleton scanner (in -*-C-*-). * Copyright © 1999 Kristoffer Rose. All rights reserved. ! * * This file is part of the FleXML XML processor generator system. * Copyright © 1999 Kristoffer Rose. All rights reserved. ! * * 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 *************** *** 65,69 **** char* limit = bufferstack + FLEXML_BUFFERSTACKSIZE; typedef struct BufferLast_s { ! struct BufferLast_s *old; char* saved; char new[1]; } BufferLast; BufferLast* last = (BufferLast*)0; --- 65,69 ---- char* limit = bufferstack + FLEXML_BUFFERSTACKSIZE; typedef struct BufferLast_s { ! struct BufferLast_s *old; char* saved; char new1[1]; } BufferLast; BufferLast* last = (BufferLast*)0; *************** *** 82,86 **** if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; } else BUFFERPUTC(*s); ! } BUFFERDONE; } --- 82,86 ---- if (isspace(*s)) { BUFFERPUTC(' '); while (isspace(*s)) ++s; } else BUFFERPUTC(*s); ! } BUFFERDONE; } *************** *** 93,97 **** l->old = last; l->saved = p; ! next = l->new; last = l; } --- 93,97 ---- l->old = last; l->saved = p; ! next = l->new1; last = l; } *************** *** 166,170 **** /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */ ! SET(PROLOG); FLEXML_EXTRA_DEFINITIONS_INIT --- 166,170 ---- /* Bypass Flex's default INITIAL state and begin by parsing the XML prolog. */ ! SET(PROLOG); FLEXML_EXTRA_DEFINITIONS_INIT *************** *** 213,217 **** <EPILOG>{ ! . FAIL("Unexpected character `%c' after document.", yytext[0]); <<EOF>> SUCCEED; } --- 213,217 ---- <EPILOG>{ ! . {SET(PROLOG); yyless(0); return -1;} <<EOF>> SUCCEED; } *************** *** 256,260 **** <CDATA>{ "]""]>" LEAVE; ! "]""]" BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); . BUFFERPUTC(yytext[0]); <<EOF>> FAIL("EOF in CDATA section."); --- 256,260 ---- <CDATA>{ "]""]>" LEAVE; ! /* "]""]" BUFFERPUTC(yytext[0]); BUFFERPUTC(yytext[1]); */ . BUFFERPUTC(yytext[0]); <<EOF>> FAIL("EOF in CDATA section."); *************** *** 262,268 **** /* Impossible rules to avoid warnings from flex(1). */ ! ! <INITIAL,IMPOSSIBLE>{ ! .|[\n] FAIL("The Impossible Happened: INITIAL or IMPOSSIBLE state entered?"); } --- 262,269 ---- /* Impossible rules to avoid warnings from flex(1). */ ! /* Ideally, this should be replaced by code in flexml.pl that ! generates just the states not covered by other rules. */ ! <*>{ ! .|[\n] FAIL("Syntax error on character `%c'.", yytext[0]); } *************** *** 304,319 **** #endif static int fail(const char* fmt, ...) { ! va_list ap; va_start(ap, fmt); #ifdef FLEXML_yylineno ! fprintf(stderr, "Invalid XML (XML input line %d, state %d): ", yylineno, YY_START); #else ! fprintf(stderr, "Invalid XML (state %d): ",YY_START); #endif ! vfprintf(stderr, fmt, ap); ! fprintf(stderr, "\n"); ! va_end(ap); ! return 1; } --- 305,339 ---- #endif + enum {flexml_max_err_msg_size = 512}; + + static char flexml_err_msg[flexml_max_err_msg_size]; + const char * parse_err_msg() + { + return flexml_err_msg; + } + + static void reset_parse_err_msg() + { + flexml_err_msg[0] = '\0'; + } + static int fail(const char* fmt, ...) { ! int chars_left, used; ! va_list ap; va_start(ap, fmt); #ifdef FLEXML_yylineno ! used = sprintf(flexml_err_msg, ! "Invalid XML (XML input line %d, state %d): ", ! yylineno, YY_START); #else ! used = sprintf(flexml_err_msg, ! "Invalid XML (state %d): ", ! YY_START); #endif ! chars_left = flexml_max_err_msg_size - used - 1; ! vsnprintf(flexml_err_msg + used, chars_left, fmt, ap); ! ! va_end(ap); ! return 1; } |