From 4d859f926a2bacd21f06630ff185da3d09a1a314 Mon Sep 17 00:00:00 2001 From: why Date: Thu, 24 Jul 2003 16:30:43 +0000 Subject: * ext/syck/emitter.c (syck_emitter_flush): accepts count of bytes to flush. anchor offsets now functional. * ext/syck/syck.h (syck_emitter_flush): ditto. * ext/syck/rubyext.c: ditto. * ext/syck/token.c: URI escaping now supported. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/syck/emitter.c | 70 ++++++++++---- ext/syck/rubyext.c | 13 ++- ext/syck/syck.h | 4 +- ext/syck/token.c | 267 ++++++++++++++++++++++++++++++++++------------------- 4 files changed, 237 insertions(+), 117 deletions(-) (limited to 'ext/syck') diff --git a/ext/syck/emitter.c b/ext/syck/emitter.c index 1927b7e1e2..07cd84e408 100644 --- a/ext/syck/emitter.c +++ b/ext/syck/emitter.c @@ -5,6 +5,9 @@ * $Date$ * * Copyright (C) 2003 why the lucky stiff + * + * All Base64 code from Ruby's pack.c. + * Ruby is Copyright (C) 1993-2003 Yukihiro Matsumoto */ #include #include @@ -148,7 +151,7 @@ syck_emitter_write( SyckEmitter *e, char *str, long len ) at = e->marker - e->buffer; if ( len + at > e->bufsize ) { - syck_emitter_flush( e ); + syck_emitter_flush( e, 0 ); } /* @@ -162,8 +165,26 @@ syck_emitter_write( SyckEmitter *e, char *str, long len ) * Write a chunk of data out. */ void -syck_emitter_flush( SyckEmitter *e ) +syck_emitter_flush( SyckEmitter *e, long check_room ) { + /* + * Check for enough space in the buffer for check_room length. + */ + if ( check_room > 0 ) + { + if ( e->bufsize > ( e->marker - e->buffer ) + check_room ) + { + return; + } + } + else + { + check_room = e->bufsize; + } + + /* + * Determine headers. + */ if ( ( e->stage == doc_open && ( e->headless == 0 || e->use_header == 1 ) ) || e->stage == doc_need_header ) { @@ -181,9 +202,17 @@ syck_emitter_flush( SyckEmitter *e ) } e->stage = doc_processing; } - (e->handler)( e, e->buffer, e->marker - e->buffer ); - e->bufpos += e->marker - e->buffer; - e->marker = e->buffer; + + /* + * Commit buffer. + */ + if ( check_room > e->marker - e->buffer ) + { + check_room = e->marker - e->buffer; + } + (e->handler)( e, e->buffer, check_room ); + e->bufpos += check_room; + e->marker -= check_room; } /* @@ -202,9 +231,9 @@ syck_emitter_simple( SyckEmitter *e, char *str, long len ) int syck_adjust_anchors( char *key, SyckEmitterNode *n, struct adjust_arg *arg ) { - if ( arg->startpos >= n->pos ) + if ( arg->startpos < n->pos ) { - n->pos += arg->offset + 1; + n->pos += arg->offset; } return ST_CONTINUE; } @@ -271,32 +300,37 @@ syck_emitter_start_obj( SyckEmitter *e, SYMID oid ) char *start = e->buffer + ( n->pos - e->bufpos ); char *anc = ( e->anchor_format == NULL ? DEFAULT_ANCHOR_FORMAT : e->anchor_format ); - char *aname = S_ALLOC_N( char, strlen( anc ) + 10 ); - S_MEMZERO( aname, char, strlen( anc ) + 10 ); - sprintf( aname, anc, idx ); + anchor_name = S_ALLOC_N( char, strlen( anc ) + 10 ); + S_MEMZERO( anchor_name, char, strlen( anc ) + 10 ); + sprintf( anchor_name, anc, idx ); + + /* + * Need to flush the buffer some, if there is not room for the anchor. + */ + alen = strlen( anchor_name ) + 2; + syck_emitter_flush( e, alen ); /* * Write the anchor into the buffer - * FIXME: Need to flush the buffer some, if there is not room for the anchor. */ - alen = strlen( aname ); - S_MEMMOVE( start + alen + 1, start, char, e->marker - start ); - S_MEMCPY( start + 1, aname, char, alen ); + S_MEMMOVE( start + alen, start, char, e->marker - start ); + S_MEMCPY( start + 1, anchor_name, char, strlen( anchor_name ) ); start[0] = '&'; - e->marker += alen + 1; + start[alen - 1] = ' '; + e->marker += alen; /* * Cycle through anchors, modify for the size of the anchor. */ args->startpos = n->pos; - args->offset = alen + 1; - st_foreach( e->anchors, syck_adjust_anchors, (st_data_t)args ); + args->offset = alen; + st_foreach( e->markers, syck_adjust_anchors, (st_data_t)args ); S_FREE( args ); /* * Insert into anchors table */ - st_insert( e->anchors, (st_data_t)oid, (st_data_t)aname ); + st_insert( e->anchors, (st_data_t)oid, (st_data_t)anchor_name ); } } diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c index 854762c591..a87edad11f 100644 --- a/ext/syck/rubyext.c +++ b/ext/syck/rubyext.c @@ -1025,7 +1025,12 @@ rb_syck_output_handler( emitter, str, len ) char *str; long len; { - rb_str_cat( (VALUE)emitter->bonus, str, len ); + VALUE dest = (VALUE)emitter->bonus; + if ( rb_respond_to( dest, rb_intern("to_str") ) ) { + rb_str_cat( dest, str, len ); + } else { + rb_io_write( dest, rb_str_new( str, len ) ); + } } /* @@ -1035,7 +1040,7 @@ static void syck_mark_emitter(emitter) SyckEmitter *emitter; { - rb_gc_mark( emitter->ignore_id ); + rb_gc_mark(emitter->ignore_id); if ( emitter->bonus != NULL ) { rb_gc_mark( (VALUE)emitter->bonus ); @@ -1104,7 +1109,7 @@ syck_emitter_flush_m( self ) SyckEmitter *emitter; Data_Get_Struct(self, SyckEmitter, emitter); - syck_emitter_flush( emitter ); + syck_emitter_flush( emitter, 0 ); return self; } @@ -1171,7 +1176,7 @@ syck_emitter_end_object( self, oid ) if ( emitter->level < 0 ) { - syck_emitter_flush( emitter ); + syck_emitter_flush( emitter, 0 ); } return (VALUE)emitter->bonus; } diff --git a/ext/syck/syck.h b/ext/syck/syck.h index 259a4cdfbd..cace70b01c 100644 --- a/ext/syck/syck.h +++ b/ext/syck/syck.h @@ -13,7 +13,7 @@ #define SYCK_YAML_MAJOR 1 #define SYCK_YAML_MINOR 0 -#define SYCK_VERSION "0.35" +#define SYCK_VERSION "0.38" #define YAML_DOMAIN "yaml.org,2002" #include @@ -308,7 +308,7 @@ void syck_emitter_handler( SyckEmitter *, SyckOutputHandler ); void syck_free_emitter( SyckEmitter * ); void syck_emitter_clear( SyckEmitter * ); void syck_emitter_write( SyckEmitter *, char *, long ); -void syck_emitter_flush( SyckEmitter * ); +void syck_emitter_flush( SyckEmitter *, long ); char *syck_emitter_start_obj( SyckEmitter *, SYMID ); void syck_emitter_end_obj( SyckEmitter * ); SyckParser *syck_new_parser(); diff --git a/ext/syck/token.c b/ext/syck/token.c index 03ab196510..bec1e7bb5b 100644 --- a/ext/syck/token.c +++ b/ext/syck/token.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.5 on Sun Jun 15 16:14:26 2003 */ +/* Generated by re2c 0.5 on Thu Jul 24 10:01:15 2003 */ #line 1 "token.re" /* * token.re @@ -1685,7 +1685,7 @@ yy153: } else if ( indt_len < lvl->spaces ) { - /* Error! */ + /* FIXME */ } if ( keep_nl == 1 ) @@ -1880,6 +1880,11 @@ yy175: ++YYCURSOR; TransferMethod: { + int qidx = 0; + int qcapa = 100; + char *qstr = S_ALLOC_N( char, qcapa ); + +TransferMethod2: YYTOKTMP = YYCURSOR; { @@ -1888,22 +1893,28 @@ TransferMethod: goto yy176; yy177: ++YYCURSOR; yy176: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + if((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *YYCURSOR; switch(yych){ case '\000': goto yy178; case '\n': goto yy179; case '\r': goto yy182; case ' ': goto yy181; - default: goto yy184; + case '\\': goto yy184; + default: goto yy185; + } +yy178: YYCURSOR = YYMARKER; + switch(yyaccept){ + case 0: goto yy183; } -yy178:yy179: yych = *++YYCURSOR; +yy179: yych = *++YYCURSOR; yy180: -#line 694 +#line 699 { SyckLevel *lvl; YYCURSOR = YYTOKTMP; if ( YYCURSOR == YYTOKEN + 1 ) { + free( qstr ); return ITRANSFER; } @@ -1912,62 +1923,132 @@ yy180: /* * URL Prefixing */ - if ( *(YYTOKEN + 1) == '^' ) + if ( *qstr == '^' ) { - yylval->name = S_ALLOC_N( char, ( YYCURSOR - YYTOKEN ) + strlen( lvl->domain ) ); + yylval->name = S_ALLOC_N( char, qidx + strlen( lvl->domain ) ); yylval->name[0] = '\0'; strcat( yylval->name, lvl->domain ); - strncat( yylval->name, YYTOKEN + 2, ( YYCURSOR - YYTOKEN ) - 2 ); + strncat( yylval->name, qstr + 1, qidx - 1 ); + free( qstr ); } else { - char *carat = YYTOKEN; - while ( (++carat) < YYCURSOR ) + char *carat = qstr; + char *qend = qstr + qidx; + while ( (++carat) < qend ) { if ( *carat == '^' ) break; } - if ( carat < YYCURSOR ) + if ( carat < qend ) { free( lvl->domain ); - lvl->domain = syck_strndup( YYTOKEN + 1, ( carat - YYTOKEN ) - 1 ); - yylval->name = S_ALLOC_N( char, ( YYCURSOR - carat ) + strlen( lvl->domain ) ); + lvl->domain = syck_strndup( qstr, carat - qstr ); + yylval->name = S_ALLOC_N( char, ( qend - carat ) + strlen( lvl->domain ) ); yylval->name[0] = '\0'; strcat( yylval->name, lvl->domain ); - strncat( yylval->name, carat + 1, ( YYCURSOR - carat ) - 1 ); + strncat( yylval->name, carat + 1, ( qend - carat ) - 1 ); + free( qstr ); } else { - yylval->name = syck_strndup( YYTOKEN + 1, ( YYCURSOR - YYTOKEN ) - 1 ); + yylval->name = qstr; } } return TRANSFER; } yy181: yych = *++YYCURSOR; - goto yy187; + goto yy192; yy182: yych = *++YYCURSOR; switch(yych){ - case '\n': goto yy185; + case '\n': goto yy190; default: goto yy183; } yy183: -#line 740 - { goto TransferMethod; } -yy184: yych = *++YYCURSOR; - goto yy183; +#line 761 + { QUOTECAT(qstr, qcapa, qidx, *(YYCURSOR - 1)); + goto TransferMethod2; + } +yy184: yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + switch(yych){ + case 'x': goto yy186; + default: goto yy183; + } yy185: yych = *++YYCURSOR; + goto yy183; +yy186: yych = *++YYCURSOR; + switch(yych){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': goto yy187; + default: goto yy178; + } +yy187: yych = *++YYCURSOR; + switch(yych){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': goto yy188; + default: goto yy178; + } +yy188: yych = *++YYCURSOR; +yy189: +#line 752 + { long ch; + char *chr_text = syck_strndup( YYTOKTMP, 4 ); + chr_text[0] = '0'; + ch = strtol( chr_text, NULL, 16 ); + free( chr_text ); + QUOTECAT(qstr, qcapa, qidx, ch); + goto TransferMethod2; + } +yy190: yych = *++YYCURSOR; goto yy180; -yy186: ++YYCURSOR; +yy191: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy187: switch(yych){ - case ' ': goto yy186; +yy192: switch(yych){ + case ' ': goto yy191; default: goto yy180; } } -#line 742 +#line 766 } @@ -2017,23 +2098,23 @@ ScalarBlock2: { YYCTYPE yych; unsigned int yyaccept; - goto yy188; -yy189: ++YYCURSOR; -yy188: + goto yy193; +yy194: ++YYCURSOR; +yy193: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; switch(yych){ - case '\000': goto yy196; - case '\n': goto yy190; - case '\r': goto yy192; - case '#': goto yy194; - default: goto yy198; + case '\000': goto yy201; + case '\n': goto yy195; + case '\r': goto yy197; + case '#': goto yy199; + default: goto yy203; } -yy190: yyaccept = 0; +yy195: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - goto yy200; -yy191: -#line 790 + goto yy205; +yy196: +#line 814 { char *pacer; char *tok = YYTOKTMP; int indt_len = 0, nl_count = 0, fold_nl = 0, nl_begin = 0; @@ -2099,19 +2180,19 @@ yy191: } goto ScalarBlock2; } -yy192: yych = *++YYCURSOR; +yy197: yych = *++YYCURSOR; switch(yych){ - case '\n': goto yy199; - default: goto yy193; + case '\n': goto yy204; + default: goto yy198; } -yy193: -#line 876 +yy198: +#line 900 { QUOTECAT(qstr, qcapa, qidx, *YYTOKTMP); goto ScalarBlock2; } -yy194: yych = *++YYCURSOR; -yy195: -#line 857 +yy199: yych = *++YYCURSOR; +yy200: +#line 881 { lvl = CURRENT_LEVEL(); if ( lvl->status != syck_lvl_block ) { @@ -2124,37 +2205,37 @@ yy195: } goto ScalarBlock2; } -yy196: yych = *++YYCURSOR; -yy197: -#line 871 +yy201: yych = *++YYCURSOR; +yy202: +#line 895 { YYCURSOR--; POP_LEVEL(); RETURN_BLOCK(); } -yy198: yych = *++YYCURSOR; - goto yy193; -yy199: yyaccept = 0; +yy203: yych = *++YYCURSOR; + goto yy198; +yy204: yyaccept = 0; YYMARKER = ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy200: switch(yych){ - case '\n': case ' ': goto yy199; - case '\r': goto yy201; - default: goto yy191; +yy205: switch(yych){ + case '\n': case ' ': goto yy204; + case '\r': goto yy206; + default: goto yy196; } -yy201: ++YYCURSOR; +yy206: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; switch(yych){ - case '\n': goto yy199; - default: goto yy202; + case '\n': goto yy204; + default: goto yy207; } -yy202: YYCURSOR = YYMARKER; +yy207: YYCURSOR = YYMARKER; switch(yyaccept){ - case 0: goto yy191; + case 0: goto yy196; } } -#line 881 +#line 905 } @@ -2172,60 +2253,60 @@ Comment: { YYCTYPE yych; unsigned int yyaccept; - goto yy203; -yy204: ++YYCURSOR; -yy203: + goto yy208; +yy209: ++YYCURSOR; +yy208: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; switch(yych){ - case '\000': goto yy205; - case '\n': goto yy207; - case '\r': goto yy208; - default: goto yy210; - } -yy205: yych = *++YYCURSOR; -yy206: -#line 897 + case '\000': goto yy210; + case '\n': goto yy212; + case '\r': goto yy213; + default: goto yy215; + } +yy210: yych = *++YYCURSOR; +yy211: +#line 921 { SyckLevel *lvl = CURRENT_LEVEL(); YYCURSOR = tok; return; } -yy207: yyaccept = 0; +yy212: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); - goto yy212; -yy208: yych = *++YYCURSOR; + goto yy217; +yy213: yych = *++YYCURSOR; switch(yych){ - case '\n': goto yy211; - default: goto yy209; + case '\n': goto yy216; + default: goto yy214; } -yy209: -#line 902 +yy214: +#line 926 { goto Comment; } -yy210: yych = *++YYCURSOR; - goto yy209; -yy211: yyaccept = 0; +yy215: yych = *++YYCURSOR; + goto yy214; +yy216: yyaccept = 0; YYMARKER = ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; -yy212: switch(yych){ - case '\n': goto yy211; - case '\r': goto yy213; - default: goto yy206; +yy217: switch(yych){ + case '\n': goto yy216; + case '\r': goto yy218; + default: goto yy211; } -yy213: ++YYCURSOR; +yy218: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; switch(yych){ - case '\n': goto yy211; - default: goto yy214; + case '\n': goto yy216; + default: goto yy219; } -yy214: YYCURSOR = YYMARKER; +yy219: YYCURSOR = YYMARKER; switch(yyaccept){ - case 0: goto yy206; + case 0: goto yy211; } } -#line 905 +#line 929 } -- cgit v1.2.3