Changeset 263

Show
Ignore:
Timestamp:
12/27/07 07:05:17 (10 months ago)
Author:
xi
Message:

Completed the first phase of API refactoring.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libyaml/trunk/src/api.c

    r261 r263  
    173173 
    174174    memset(parser, 0, sizeof(yaml_parser_t)); 
    175     if (!BUFFER_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY)) 
     175    if (!STRING_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY)) 
    176176        goto error; 
    177     if (!BUFFER_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY)) 
     177    if (!STRING_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY)) 
    178178        goto error; 
    179179    if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_CAPACITY)) 
     
    207207    assert(parser); /* Non-NULL parser object expected. */ 
    208208 
    209     BUFFER_DEL(parser, parser->raw_input); 
    210     BUFFER_DEL(parser, parser->input); 
     209    STRING_DEL(parser, parser->raw_input); 
     210    STRING_DEL(parser, parser->input); 
    211211    while (!QUEUE_EMPTY(parser, parser->tokens)) { 
    212212        yaml_token_destroy(&DEQUEUE(parser, parser->tokens)); 
     
    358358 
    359359    memset(emitter, 0, sizeof(yaml_emitter_t)); 
    360     if (!BUFFER_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY)) 
     360    if (!STRING_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY)) 
    361361        goto error; 
    362     if (!BUFFER_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY)) 
     362    if (!STRING_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY)) 
    363363        goto error; 
    364364    if (!STACK_INIT(emitter, emitter->states, INITIAL_STACK_CAPACITY)) 
     
    388388    assert(emitter);    /* Non-NULL emitter object expected. */ 
    389389 
    390     BUFFER_DEL(emitter, emitter->output); 
    391     BUFFER_DEL(emitter, emitter->raw_output); 
     390    STRING_DEL(emitter, emitter->output); 
     391    STRING_DEL(emitter, emitter->raw_output); 
    392392    STACK_DEL(emitter, emitter->states); 
    393393    while (!QUEUE_EMPTY(emitter, emitter->events)) { 
  • libyaml/trunk/src/dumper.c

    r238 r263  
    11 
    22#include "yaml_private.h" 
     3 
     4#if 0 
    35 
    46/* 
     
    393395} 
    394396 
     397#endif 
     398 
  • libyaml/trunk/src/emitter.c

    r241 r263  
    77 
    88#define FLUSH(emitter)                                                          \ 
    9     ((emitter->buffer.pointer+5 < emitter->buffer.end)                          \ 
     9    ((emitter->output.pointer+5 < emitter->output.capacity)                     \ 
    1010     || yaml_emitter_flush(emitter)) 
    1111 
     
    1616#define PUT(emitter,value)                                                      \ 
    1717    (FLUSH(emitter)                                                             \ 
    18      && (*(emitter->buffer.pointer++) = (yaml_char_t)(value),                   \ 
     18     && (JOIN_OCTET(emitter->output,(yaml_char_t)(value)),                      \ 
    1919         emitter->column ++,                                                    \ 
    2020         1)) 
     
    2727    (FLUSH(emitter)                                                             \ 
    2828     && ((emitter->line_break == YAML_CR_BREAK ?                                \ 
    29              (*(emitter->buffer.pointer++) = (yaml_char_t) '\r') :              \ 
     29             JOIN_OCTET(emitter->output, (yaml_char_t) '\r') :                  \ 
    3030          emitter->line_break == YAML_LN_BREAK ?                                \ 
    31              (*(emitter->buffer.pointer++) = (yaml_char_t) '\n') :              \ 
     31             JOIN_OCTET(emitter->output, (yaml_char_t) '\n') :                  \ 
    3232          emitter->line_break == YAML_CRLN_BREAK ?                              \ 
    33              (*(emitter->buffer.pointer++) = (yaml_char_t) '\r',                \ 
    34               *(emitter->buffer.pointer++) = (yaml_char_t) '\n') : 0),          \ 
     33             (JOIN_OCTET(emitter->output, (yaml_char_t) '\r'),                  \ 
     34              JOIN_OCTET(emitter->output, (yaml_char_t) '\n')) : 0),            \ 
    3535         emitter->column = 0,                                                   \ 
    3636         emitter->line ++,                                                      \ 
     
    4343#define WRITE(emitter,string)                                                   \ 
    4444    (FLUSH(emitter)                                                             \ 
    45      && (COPY(emitter->buffer,string),                                          \ 
     45     && (COPY(emitter->output,string),                                          \ 
    4646         emitter->column ++,                                                    \ 
    4747         1)) 
     
    5757          string.pointer ++,                                                    \ 
    5858          1) :                                                                  \ 
    59          (COPY(emitter->buffer,string),                                         \ 
     59         (COPY(emitter->output,string),                                         \ 
    6060          emitter->column = 0,                                                  \ 
    6161          emitter->line ++,                                                     \ 
     
    7474 
    7575static int 
    76 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem); 
    77  
    78 static int 
    7976yaml_emitter_need_more_events(yaml_emitter_t *emitter); 
    8077 
     
    136133static int 
    137134yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 
    138         int root, int sequence, int mapping, int simple_key); 
     135        int is_root, int is_sequence, int is_mapping, int is_simple_key); 
    139136 
    140137static int 
     
    262259 
    263260/* 
    264  * Set an emitter error and return 0. 
    265  */ 
    266  
    267 static int 
    268 yaml_emitter_set_emitter_error(yaml_emitter_t *emitter, const char *problem) 
    269 { 
    270     emitter->error = YAML_EMITTER_ERROR; 
    271     emitter->problem = problem; 
    272  
    273     return 0; 
    274 } 
    275  
    276 /* 
    277261 * Emit an event. 
    278262 */ 
     
    287271 
    288272    while (!yaml_emitter_need_more_events(emitter)) { 
    289         if (!yaml_emitter_analyze_event(emitter, emitter->events.head)) 
    290             return 0; 
    291         if (!yaml_emitter_state_machine(emitter, emitter->events.head)) 
     273        if (!yaml_emitter_analyze_event(emitter, 
     274                    emitter->events.list + emitter->events.head)) 
     275            return 0; 
     276        if (!yaml_emitter_state_machine(emitter, 
     277                    emitter->events.list + emitter->events.head)) 
    292278            return 0; 
    293279        yaml_event_delete(&DEQUEUE(emitter, emitter->events)); 
     
    311297    int level = 0; 
    312298    int accumulate = 0; 
    313     yaml_event_t *event
     299    size_t idx
    314300 
    315301    if (QUEUE_EMPTY(emitter, emitter->events)) 
    316302        return 1; 
    317303 
    318     switch (emitter->events.head->type) { 
     304    switch (emitter->events.list[emitter->events.head].type) { 
    319305        case YAML_DOCUMENT_START_EVENT: 
    320306            accumulate = 1; 
     
    333319        return 0; 
    334320 
    335     for (event = emitter->events.head; event != emitter->events.tail; event ++) { 
     321    for (idx = emitter->events.head; idx < emitter->events.tail; idx ++) { 
     322        yaml_event_t *event = emitter->events.list+idx; 
    336323        switch (event->type) { 
    337324            case YAML_STREAM_START_EVENT: 
     
    365352        yaml_tag_directive_t value, int allow_duplicates) 
    366353{ 
    367     yaml_tag_directive_t *tag_directive
     354    int idx
    368355    yaml_tag_directive_t copy = { NULL, NULL }; 
    369356 
    370     for (tag_directive = emitter->tag_directives.start; 
    371             tag_directive != emitter->tag_directives.top; tag_directive ++) { 
     357    for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 
     358        yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 
    372359        if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { 
    373360            if (allow_duplicates) 
    374361                return 1; 
    375             return yaml_emitter_set_emitter_error(emitter, 
    376                     "duplicate %TAG directive"); 
     362            return EMITTER_ERROR_INIT(emitter, "duplicate %TAG directive"); 
    377363        } 
    378364    } 
     
    381367    copy.prefix = yaml_strdup(value.prefix); 
    382368    if (!copy.handle || !copy.prefix) { 
    383         emitter->error = YAML_MEMORY_ERROR
     369        MEMORY_ERROR_INIT(emitter)
    384370        goto error; 
    385371    } 
     
    478464 
    479465        case YAML_EMIT_END_STATE: 
    480             return yaml_emitter_set_emitter_error(emitter, 
     466            return EMITTER_ERROR_INIT(emitter, 
    481467                    "expected nothing after STREAM-END"); 
    482468 
     
    527513        emitter->line = 0; 
    528514        emitter->column = 0; 
    529         emitter->whitespace = 1; 
    530         emitter->indention = 1; 
     515        emitter->is_whitespace = 1; 
     516        emitter->is_indention = 1; 
    531517 
    532518        if (emitter->encoding != YAML_UTF8_ENCODING) { 
     
    540526    } 
    541527 
    542     return yaml_emitter_set_emitter_error(emitter, 
    543             "expected STREAM-START"); 
     528    return EMITTER_ERROR_INIT(emitter, "expected STREAM-START"); 
    544529} 
    545530 
     
    560545        }; 
    561546        yaml_tag_directive_t *tag_directive; 
    562         int implicit; 
     547        int is_implicit; 
     548        int idx; 
    563549 
    564550        if (event->data.document_start.version_directive) { 
     
    568554        } 
    569555 
    570         for (tag_directive = event->data.document_start.tag_directives.start; 
    571                 tag_directive != event->data.document_start.tag_directives.end; 
    572                 tag_directive ++) { 
     556        for (idx = 0; idx < event->data.document_start.tag_directives.length; idx++) { 
     557            tag_directive = event->data.document_start.tag_directives.list+idx; 
    573558            if (!yaml_emitter_analyze_tag_directive(emitter, *tag_directive)) 
    574559                return 0; 
     
    583568        } 
    584569 
    585         implicit = event->data.document_start.implicit; 
    586         if (!first || emitter->canonical) { 
    587             implicit = 0; 
     570        is_implicit = event->data.document_start.is_implicit; 
     571        if (!first || emitter->is_canonical) { 
     572            is_implicit = 0; 
    588573        } 
    589574 
    590575        if (event->data.document_start.version_directive) { 
    591             implicit = 0; 
     576            is_implicit = 0; 
    592577            if (!yaml_emitter_write_indicator(emitter, "%YAML", 1, 0, 0)) 
    593578                return 0; 
     
    598583        } 
    599584         
    600         if (event->data.document_start.tag_directives.start 
    601                 != event->data.document_start.tag_directives.end) { 
    602             implicit = 0; 
    603             for (tag_directive = event->data.document_start.tag_directives.start; 
    604                     tag_directive != event->data.document_start.tag_directives.end; 
    605                     tag_directive ++) { 
     585        if (event->data.document_start.tag_directives.length) { 
     586            is_implicit = 0; 
     587            for (idx = 0; idx < event->data.document_start.tag_directives.length; 
     588                    idx++) { 
     589                tag_directive = event->data.document_start.tag_directives.list+idx; 
    606590                if (!yaml_emitter_write_indicator(emitter, "%TAG", 1, 0, 0)) 
    607591                    return 0; 
     
    618602 
    619603        if (yaml_emitter_check_empty_document(emitter)) { 
    620             implicit = 0; 
    621         } 
    622  
    623         if (!implicit) { 
     604            is_implicit = 0; 
     605        } 
     606 
     607        if (!is_implicit) { 
    624608            if (!yaml_emitter_write_indent(emitter)) 
    625609                return 0; 
    626610            if (!yaml_emitter_write_indicator(emitter, "---", 1, 0, 0)) 
    627611                return 0; 
    628             if (emitter->canonical) { 
     612            if (emitter->is_canonical) { 
    629613                if (!yaml_emitter_write_indent(emitter)) 
    630614                    return 0; 
     
    647631    } 
    648632 
    649     return yaml_emitter_set_emitter_error(emitter, 
    650             "expected DOCUMENT-START or STREAM-END"); 
     633    return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-START or STREAM-END"); 
    651634} 
    652635 
     
    677660        if (!yaml_emitter_write_indent(emitter)) 
    678661            return 0; 
    679         if (!event->data.document_end.implicit) { 
     662        if (!event->data.document_end.is_implicit) { 
    680663            if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0)) 
    681664                return 0; 
     
    698681    } 
    699682 
    700     return yaml_emitter_set_emitter_error(emitter, 
    701             "expected DOCUMENT-END"); 
     683    return EMITTER_ERROR_INIT(emitter, "expected DOCUMENT-END"); 
    702684} 
    703685 
     
    724706        emitter->flow_level --; 
    725707        emitter->indent = POP(emitter, emitter->indents); 
    726         if (emitter->canonical && !first) { 
     708        if (emitter->is_canonical && !first) { 
    727709            if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 
    728710                return 0; 
     
    742724    } 
    743725 
    744     if (emitter->canonical || emitter->column > emitter->best_width) { 
     726    if (emitter->is_canonical || emitter->column > emitter->best_width) { 
    745727        if (!yaml_emitter_write_indent(emitter)) 
    746728            return 0; 
     
    773755        emitter->flow_level --; 
    774756        emitter->indent = POP(emitter, emitter->indents); 
    775         if (emitter->canonical && !first) { 
     757        if (emitter->is_canonical && !first) { 
    776758            if (!yaml_emitter_write_indicator(emitter, ",", 0, 0, 0)) 
    777759                return 0; 
     
    790772            return 0; 
    791773    } 
    792     if (emitter->canonical || emitter->column > emitter->best_width) { 
     774    if (emitter->is_canonical || emitter->column > emitter->best_width) { 
    793775        if (!yaml_emitter_write_indent(emitter)) 
    794776            return 0; 
    795777    } 
    796778 
    797     if (!emitter->canonical && yaml_emitter_check_simple_key(emitter)) 
     779    if (!emitter->is_canonical && yaml_emitter_check_simple_key(emitter)) 
    798780    { 
    799781        if (!PUSH(emitter, emitter->states, 
     
    828810    } 
    829811    else { 
    830         if (emitter->canonical || emitter->column > emitter->best_width) { 
     812        if (emitter->is_canonical || emitter->column > emitter->best_width) { 
    831813            if (!yaml_emitter_write_indent(emitter)) 
    832814                return 0; 
     
    851833    { 
    852834        if (!yaml_emitter_increase_indent(emitter, 0, 
    853                     (emitter->mapping_context && !emitter->indention))) 
     835                    (emitter->is_mapping_context && !emitter->is_indention))) 
    854836            return 0; 
    855837    } 
     
    950932static int 
    951933yaml_emitter_emit_node(yaml_emitter_t *emitter, yaml_event_t *event, 
    952         int root, int sequence, int mapping, int simple_key) 
    953 { 
    954     emitter->root_context = root; 
    955     emitter->sequence_context = sequence; 
    956     emitter->mapping_context = mapping; 
    957     emitter->simple_key_context = simple_key; 
     934        int is_root, int is_sequence, int is_mapping, int is_simple_key) 
     935{ 
     936    emitter->is_root_context = is_root; 
     937    emitter->is_sequence_context = is_sequence; 
     938    emitter->is_mapping_context = is_mapping; 
     939    emitter->is_simple_key_context = is_simple_key; 
    958940 
    959941    switch (event->type) 
     
    972954 
    973955        default: 
    974             return yaml_emitter_set_emitter_error(emitter, 
     956            return EMITTER_ERROR_INIT(emitter, 
    975957                    "expected SCALAR, SEQUENCE-START, MAPPING-START, or ALIAS"); 
    976958    } 
     
    10281010        return 0; 
    10291011 
    1030     if (emitter->flow_level || emitter->canonical 
     1012    if (emitter->flow_level || emitter->is_canonical 
    10311013            || event->data.sequence_start.style == YAML_FLOW_SEQUENCE_STYLE 
    10321014            || yaml_emitter_check_empty_sequence(emitter)) { 
     
    10521034        return 0; 
    10531035 
    1054     if (emitter->flow_level || emitter->canonical 
     1036    if (emitter->flow_level || emitter->is_canonical 
    10551037            || event->data.mapping_start.style == YAML_FLOW_MAPPING_STYLE 
    10561038            || yaml_emitter_check_empty_mapping(emitter)) { 
     
    10841066        return 0; 
    10851067 
    1086     return (emitter->events.head[0].type == YAML_SEQUENCE_START_EVENT 
    1087             && emitter->events.head[1].type == YAML_SEQUENCE_END_EVENT); 
     1068    return (emitter->events.list[emitter->events.head].type 
     1069                            == YAML_SEQUENCE_START_EVENT && 
     1070            emitter->events.list[emitter->events.head+1].type 
     1071                            == YAML_SEQUENCE_END_EVENT); 
    10881072} 
    10891073 
     
    10981082        return 0; 
    10991083 
    1100     return (emitter->events.head[0].type == YAML_MAPPING_START_EVENT 
    1101             && emitter->events.head[1].type == YAML_MAPPING_END_EVENT); 
     1084    return (emitter->events.list[emitter->events.head].type 
     1085                            == YAML_MAPPING_START_EVENT && 
     1086            emitter->events.list[emitter->events.head+1].type 
     1087                            == YAML_MAPPING_END_EVENT); 
    11021088} 
    11031089 
     
    11091095yaml_emitter_check_simple_key(yaml_emitter_t *emitter) 
    11101096{ 
    1111     yaml_event_t *event = emitter->events.head; 
     1097    yaml_event_t *event = emitter->events.list + emitter->events.head; 
    11121098    size_t length = 0; 
    11131099 
     
    11191105 
    11201106        case YAML_SCALAR_EVENT: 
    1121             if (emitter->scalar_data.multiline) 
     1107            if (emitter->scalar_data.is_multiline) 
    11221108                return 0; 
    11231109            length += emitter->anchor_data.anchor_length 
     
    11631149    int no_tag = (!emitter->tag_data.handle && !emitter->tag_data.suffix); 
    11641150 
    1165     if (no_tag && !event->data.scalar.plain_implicit 
    1166             && !event->data.scalar.quoted_implicit) { 
    1167         return yaml_emitter_set_emitter_error(emitter, 
     1151    if (no_tag && !event->data.scalar.is_plain_implicit 
     1152            && !event->data.scalar.is_quoted_implicit) { 
     1153        return EMITTER_ERROR_INIT(emitter, 
    11681154                "neither tag nor implicit flags are specified"); 
    11691155    } 
     
    11721158        style = YAML_PLAIN_SCALAR_STYLE; 
    11731159 
    1174     if (emitter->canonical) 
     1160    if (emitter->is_canonical) 
    11751161        style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 
    11761162 
    1177     if (emitter->simple_key_context && emitter->scalar_data.multiline) 
     1163    if (emitter->is_simple_key_context && emitter->scalar_data.is_multiline) 
    11781164        style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 
    11791165 
    11801166    if (style == YAML_PLAIN_SCALAR_STYLE) 
    11811167    { 
    1182         if ((emitter->flow_level && !emitter->scalar_data.flow_plain_allowed) 
    1183                 || (!emitter->flow_level && !emitter->scalar_data.block_plain_allowed)) 
     1168        if ((emitter->flow_level && !emitter->scalar_data.is_flow_plain_allowed) 
     1169                || (!emitter->flow_level && !emitter->scalar_data.is_block_plain_allowed)) 
    11841170            style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 
    11851171        if (!emitter->scalar_data.length 
    1186                 && (emitter->flow_level || emitter->simple_key_context)) 
     1172                && (emitter->flow_level || emitter->is_simple_key_context)) 
    11871173            style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 
    1188         if (no_tag && !event->data.scalar.plain_implicit) 
     1174        if (no_tag && !event->data.scalar.is_plain_implicit) 
    11891175            style = YAML_SINGLE_QUOTED_SCALAR_STYLE; 
    11901176    } 
     
    11921178    if (style == YAML_SINGLE_QUOTED_SCALAR_STYLE) 
    11931179    { 
    1194         if (!emitter->scalar_data.single_quoted_allowed) 
     1180        if (!emitter->scalar_data.is_single_quoted_allowed) 
    11951181            style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 
    11961182    } 
     
    11981184    if (style == YAML_LITERAL_SCALAR_STYLE || style == YAML_FOLDED_SCALAR_STYLE) 
    11991185    { 
    1200         if (!emitter->scalar_data.block_allowed 
    1201                 || emitter->flow_level || emitter->simple_key_context) 
     1186        if (!emitter->scalar_data.is_block_allowed 
     1187                || emitter->flow_level || emitter->is_simple_key_context) 
    12021188            style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; 
    12031189    } 
    12041190 
    1205     if (no_tag && !event->data.scalar.quoted_implicit 
     1191    if (no_tag && !event->data.scalar.is_quoted_implicit 
    12061192            && style != YAML_PLAIN_SCALAR_STYLE) 
    12071193    { 
     
    12261212 
    12271213    if (!yaml_emitter_write_indicator(emitter, 
    1228                 (emitter->anchor_data.alias ? "*" : "&"), 1, 0, 0)) 
     1214                (emitter->anchor_data.is_alias ? "*" : "&"), 1, 0, 0)) 
    12291215        return 0; 
    12301216 
     
    12801266            return yaml_emitter_write_plain_scalar(emitter, 
    12811267                    emitter->scalar_data.value, emitter->scalar_data.length, 
    1282                     !emitter->simple_key_context); 
     1268                    !emitter->is_simple_key_context); 
    12831269 
    12841270        case YAML_SINGLE_QUOTED_SCALAR_STYLE: 
    12851271            return yaml_emitter_write_single_quoted_scalar(emitter, 
    12861272                    emitter->scalar_data.value, emitter->scalar_data.length, 
    1287                     !emitter->simple_key_context); 
     1273                    !emitter->is_simple_key_context); 
    12881274 
    12891275        case YAML_DOUBLE_QUOTED_SCALAR_STYLE: 
    12901276            return yaml_emitter_write_double_quoted_scalar(emitter, 
    12911277                    emitter->scalar_data.value, emitter->scalar_data.length, 
    1292                     !emitter->simple_key_context); 
     1278                    !emitter->is_simple_key_context); 
    12931279 
    12941280        case YAML_LITERAL_SCALAR_STYLE: 
     
    13161302{ 
    13171303    if (version_directive.major != 1 || version_directive.minor != 1) { 
    1318         return yaml_emitter_set_emitter_error(emitter, 
    1319                 "incompatible %YAML directive"); 
     1304        return EMITTER_ERROR_INIT(emitter, "incompatible %YAML directive"); 
    13201305    } 
    13211306 
     
    13361321            strlen((char *)tag_directive.prefix)); 
    13371322 
    1338     if (handle.start == handle.end) { 
    1339         return yaml_emitter_set_emitter_error(emitter, 
    1340                 "tag handle must not be empty"); 
    1341     } 
    1342  
    1343     if (handle.start[0] != '!') { 
    1344         return yaml_emitter_set_emitter_error(emitter, 
    1345                 "tag handle must start with '!'"); 
    1346     } 
    1347  
    1348     if (handle.end[-1] != '!') { 
    1349         return yaml_emitter_set_emitter_error(emitter, 
    1350                 "tag handle must end with '!'"); 
     1323    if (!handle.capacity) { 
     1324        return EMITTER_ERROR_INIT(emitter, "tag handle must not be empty"); 
     1325    } 
     1326 
     1327    if (handle.buffer[0] != '!') { 
     1328        return EMITTER_ERROR_INIT(emitter, "tag handle must start with '!'"); 
     1329    } 
     1330 
     1331    if (handle.buffer[handle.capacity-1] != '!') { 
     1332        return EMITTER_ERROR_INIT(emitter, "tag handle must end with '!'"); 
    13511333    } 
    13521334 
    13531335    handle.pointer ++; 
    13541336 
    1355     while (handle.pointer < handle.end-1) { 
     1337    while (handle.pointer < handle.capacity-1) { 
    13561338        if (!IS_ALPHA(handle)) { 
    1357             return yaml_emitter_set_emitter_error(emitter, 
     1339            return EMITTER_ERROR_INIT(emitter, 
    13581340                    "tag handle must contain alphanumerical characters only"); 
    13591341        } 
     
    13611343    } 
    13621344 
    1363     if (prefix.start == prefix.end) { 
    1364         return yaml_emitter_set_emitter_error(emitter, 
    1365                 "tag prefix must not be empty"); 
     1345    if (!prefix.capacity) { 
     1346        return EMITTER_ERROR_INIT(emitter, "tag prefix must not be empty"); 
    13661347    } 
    13671348 
     
    13751356static int 
    13761357yaml_emitter_analyze_anchor(yaml_emitter_t *emitter, 
    1377         yaml_char_t *anchor, int alias) 
     1358        yaml_char_t *anchor, int is_alias) 
    13781359{ 
    13791360    yaml_string_t string = STRING(anchor, strlen((char *)anchor)); 
    13801361 
    1381     if (string.start == string.end) { 
    1382         return yaml_emitter_set_emitter_error(emitter, alias ? 
     1362    if (!string.capacity) { 
     1363        return EMITTER_ERROR_INIT(emitter, is_alias ? 
    13831364                "alias value must not be empty" : 
    13841365                "anchor value must not be empty"); 
    13851366    } 
    13861367 
    1387     while (string.pointer != string.end) { 
     1368    while (string.pointer < string.capacity) { 
    13881369        if (!IS_ALPHA(string)) { 
    1389             return yaml_emitter_set_emitter_error(emitter, alias ? 
     1370            return EMITTER_ERROR_INIT(emitter, is_alias ? 
    13901371                    "alias value must contain alphanumerical characters only" : 
    13911372                    "anchor value must contain alphanumerical characters only"); 
     
    13941375    } 
    13951376 
    1396     emitter->anchor_data.anchor = string.start
    1397     emitter->anchor_data.anchor_length = string.end - string.start
    1398     emitter->anchor_data.alias = alias; 
     1377    emitter->anchor_data.anchor = string.buffer
     1378    emitter->anchor_data.anchor_length = string.capacity
     1379    emitter->anchor_data.is_alias = is_alias; 
    13991380 
    14001381    return 1; 
     
    14101391{ 
    14111392    yaml_string_t string = STRING(tag, strlen((char *)tag)); 
    1412     yaml_tag_directive_t *tag_directive; 
    1413  
    1414     if (string.start == string.end) { 
    1415         return yaml_emitter_set_emitter_error(emitter, 
    1416                 "tag value must not be empty"); 
    1417     } 
    1418  
    1419     for (tag_directive = emitter->tag_directives.start; 
    1420             tag_directive != emitter->tag_directives.top; tag_directive ++) { 
     1393    size_t idx; 
     1394 
     1395    if (!string.capacity) { 
     1396        return EMITTER_ERROR_INIT(emitter, "tag value must not be empty"); 
     1397    } 
     1398 
     1399    for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 
     1400        yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 
    14211401        size_t prefix_length = strlen((char *)tag_directive->prefix); 
    1422         if (prefix_length < (size_t)(string.end - string.start) 
    1423                 && strncmp((char *)tag_directive->prefix, (char *)string.start
     1402        if (prefix_length < string.capacity 
     1403                && strncmp((char *)tag_directive->prefix, (char *)string.buffer
    14241404                    prefix_length) == 0) 
    14251405        { 
     
    14271407            emitter->tag_data.handle_length = 
    14281408                strlen((char *)tag_directive->handle); 
    1429             emitter->tag_data.suffix = string.start + prefix_length; 
    1430             emitter->tag_data.suffix_length = 
    1431                 (string.end - string.start) - prefix_length; 
     1409            emitter->tag_data.suffix = string.buffer + prefix_length; 
     1410            emitter->tag_data.suffix_length = string.capacity - prefix_length; 
    14321411            return 1; 
    14331412        } 
    14341413    } 
    14351414 
    1436     emitter->tag_data.suffix = string.start
    1437     emitter->tag_data.suffix_length = string.end - string.start
     1415    emitter->tag_data.suffix = string.buffer
     1416    emitter->tag_data.suffix_length = string.capacity
    14381417 
    14391418    return 1; 
     
    14741453    emitter->scalar_data.length = length; 
    14751454 
    1476     if (string.start == string.end
    1477     { 
    1478         emitter->scalar_data.multiline = 0; 
    1479         emitter->scalar_data.flow_plain_allowed = 0; 
    1480         emitter->scalar_data.block_plain_allowed = 1; 
    1481         emitter->scalar_data.single_quoted_allowed = 1; 
    1482         emitter->scalar_data.block_allowed = 0; 
     1455    if (!string.capacity
     1456    { 
     1457        emitter->scalar_data.is_multiline = 0; 
     1458        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1459        emitter->scalar_data.is_block_plain_allowed = 1; 
     1460        emitter->scalar_data.is_single_quoted_allowed = 1; 
     1461        emitter->scalar_data.is_block_allowed = 0; 
    14831462 
    14841463        return 1; 
     
    14981477    followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 
    14991478 
    1500     while (string.pointer != string.end
    1501     { 
    1502         if (string.start == string.pointer) 
     1479    while (string.pointer < string.capacity
     1480    { 
     1481        if (!string.pointer) 
    15031482        { 
    15041483            if (CHECK(string, '#') || CHECK(string, ',') 
     
    15481527 
    15491528        if (!IS_PRINTABLE(string) 
    1550                 || (!IS_ASCII(string) && !emitter->unicode)) { 
     1529                || (!IS_ASCII(string) && !emitter->is_unicode)) { 
    15511530            special_characters = 1; 
    15521531        } 
     
    15591538        { 
    15601539            spaces = 1; 
    1561             if (string.start == string.pointer) { 
     1540            if (!string.pointer) { 
    15621541                leading = 1; 
    15631542            } 
     
    15701549            } 
    15711550            breaks = 1; 
    1572             if (string.start == string.pointer) { 
     1551            if (!string.pointer) { 
    15731552                leading = 1; 
    15741553            } 
     
    16051584        } 
    16061585 
    1607         if ((spaces || breaks) && string.pointer == string.end-1) 
     1586        if ((spaces || breaks) && string.pointer == string.capacity-1) 
    16081587        { 
    16091588            if (spaces && breaks) { 
     
    16261605        preceeded_by_space = IS_BLANKZ(string); 
    16271606        MOVE(string); 
    1628         if (string.pointer != string.end) { 
     1607        if (string.pointer < string.capacity) { 
    16291608            followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 
    16301609        } 
    16311610    } 
    16321611 
    1633     emitter->scalar_data.multiline = line_breaks; 
    1634  
    1635     emitter->scalar_data.flow_plain_allowed = 1; 
    1636     emitter->scalar_data.block_plain_allowed = 1; 
    1637     emitter->scalar_data.single_quoted_allowed = 1; 
    1638     emitter->scalar_data.block_allowed = 1; 
     1612    emitter->scalar_data.is_multiline = line_breaks; 
     1613 
     1614    emitter->scalar_data.is_flow_plain_allowed = 1; 
     1615    emitter->scalar_data.is_block_plain_allowed = 1; 
     1616    emitter->scalar_data.is_single_quoted_allowed = 1; 
     1617    emitter->scalar_data.is_block_allowed = 1; 
    16391618 
    16401619    if (leading_spaces || leading_breaks || trailing_spaces) { 
    1641         emitter->scalar_data.flow_plain_allowed = 0; 
    1642         emitter->scalar_data.block_plain_allowed = 0; 
    1643         emitter->scalar_data.block_allowed = 0; 
     1620        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1621        emitter->scalar_data.is_block_plain_allowed = 0; 
     1622        emitter->scalar_data.is_block_allowed = 0; 
    16441623    } 
    16451624 
    16461625    if (trailing_breaks) { 
    1647         emitter->scalar_data.flow_plain_allowed = 0; 
    1648         emitter->scalar_data.block_plain_allowed = 0; 
     1626        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1627        emitter->scalar_data.is_block_plain_allowed = 0; 
    16491628    } 
    16501629 
    16511630    if (inline_breaks_spaces) { 
    1652         emitter->scalar_data.flow_plain_allowed = 0; 
    1653         emitter->scalar_data.block_plain_allowed = 0; 
    1654         emitter->scalar_data.single_quoted_allowed = 0; 
     1631        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1632        emitter->scalar_data.is_block_plain_allowed = 0; 
     1633        emitter->scalar_data.is_single_quoted_allowed = 0; 
    16551634    } 
    16561635 
    16571636    if (mixed_breaks_spaces || special_characters) { 
    1658         emitter->scalar_data.flow_plain_allowed = 0; 
    1659         emitter->scalar_data.block_plain_allowed = 0; 
    1660         emitter->scalar_data.single_quoted_allowed = 0; 
    1661         emitter->scalar_data.block_allowed = 0; 
     1637        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1638        emitter->scalar_data.is_block_plain_allowed = 0; 
     1639        emitter->scalar_data.is_single_quoted_allowed = 0; 
     1640        emitter->scalar_data.is_block_allowed = 0; 
    16621641    } 
    16631642 
    16641643    if (line_breaks) { 
    1665         emitter->scalar_data.flow_plain_allowed = 0; 
    1666         emitter->scalar_data.block_plain_allowed = 0; 
     1644        emitter->scalar_data.is_flow_plain_allowed = 0; 
     1645        emitter->scalar_data.is_block_plain_allowed = 0; 
    16671646    } 
    16681647 
    16691648    if (flow_indicators) { 
    1670         emitter->scalar_data.flow_plain_allowed = 0; 
     1649        emitter->scalar_data.is_flow_plain_allowed = 0; 
    16711650    } 
    16721651 
    16731652    if (block_indicators) { 
    1674         emitter->scalar_data.block_plain_allowed = 0; 
     1653        emitter->scalar_data.is_block_plain_allowed = 0; 
    16751654    } 
    16761655 
     
    17091688                    return 0; 
    17101689            } 
    1711             if (event->data.scalar.tag && (emitter->canonical || 
    1712                         (!event->data.scalar.plain_implicit 
    1713                          && !event->data.scalar.quoted_implicit))) { 
     1690            if (event->data.scalar.tag && (emitter->is_canonical || 
     1691                        (!event->data.scalar.is_plain_implicit 
     1692                         && !event->data.scalar.is_quoted_implicit))) { 
    17141693                if (!yaml_emitter_analyze_tag(emitter, event->data.scalar.tag)) 
    17151694                    return 0; 
     
    17261705                    return 0; 
    17271706            } 
    1728             if (event->data.sequence_start.tag && (emitter->canonical || 
    1729                         !event->data.sequence_start.implicit)) { 
     1707            if (event->data.sequence_start.tag && (emitter->is_canonical || 
     1708                        !event->data.sequence_start.is_implicit)) { 
    17301709                if (!yaml_emitter_analyze_tag(emitter, 
    17311710                            event->data.sequence_start.tag)) 
     
    17401719                    return 0; 
    17411720            } 
    1742             if (event->data.mapping_start.tag && (emitter->canonical || 
    1743                         !event->data.mapping_start.implicit)) { 
     1721            if (event->data.mapping_start.tag && (emitter->is_canonical || 
     1722                        !event->data.mapping_start.is_implicit)) { 
    17441723                if (!yaml_emitter_analyze_tag(emitter, 
    17451724                            event->data.mapping_start.tag)) 
     
    17621741    if (!FLUSH(emitter)) return 0; 
    17631742 
    1764     *(emitter->buffer.pointer++) = (yaml_char_t) '\xEF'
    1765     *(emitter->buffer.pointer++) = (yaml_char_t) '\xBB'
    1766     *(emitter->buffer.pointer++) = (yaml_char_t) '\xBF'
     1743    JOIN_OCTET(emitter->output, (yaml_char_t) '\xEF')
     1744    JOIN_OCTET(emitter->output, (yaml_char_t) '\xBB')
     1745    JOIN_OCTET(emitter->output, (yaml_char_t) '\xBF')
    17671746 
    17681747    return 1; 
     
    17741753    int indent = (emitter->indent >= 0) ? emitter->indent : 0; 
    17751754 
    1776     if (!emitter->indention || emitter->column > indent 
    1777             || (emitter->column == indent && !emitter->whitespace)) { 
     1755    if (!emitter->is_indention || emitter->column > indent 
     1756            || (emitter->column == indent && !emitter->is_whitespace)) { 
    17781757        if (!PUT_BREAK(emitter)) return 0; 
    17791758    } 
     
    17831762    } 
    17841763 
    1785     emitter->whitespace = 1; 
    1786     emitter->indention = 1; 
     1764    emitter->is_whitespace = 1; 
     1765    emitter->is_indention = 1; 
    17871766 
    17881767    return 1; 
     
    17961775    yaml_string_t string = STRING((yaml_char_t *)indicator, strlen(indicator)); 
    17971776 
    1798     if (need_whitespace && !emitter->whitespace) { 
     1777    if (need_whitespace && !emitter->is_whitespace) { 
    17991778        if (!PUT(emitter, ' ')) return 0; 
    18001779    } 
    18011780 
    1802     while (string.pointer != string.end) { 
     1781    while (string.pointer < string.capacity) { 
    18031782        if (!WRITE(emitter, string)) return 0; 
    18041783    } 
    18051784 
    1806     emitter->whitespace = is_whitespace; 
    1807     emitter->indention = (emitter->indention && is_indention); 
     1785    emitter->is_whitespace = is_whitespace; 
     1786    emitter->is_indention = (emitter->is_indention && is_indention); 
    18081787 
    18091788    return 1; 
     
    18161795    yaml_string_t string = STRING(value, length); 
    18171796 
    1818     while (string.pointer != string.end) { 
     1797    while (string.pointer < string.capacity) { 
    18191798        if (!WRITE(emitter, string)) return 0; 
    18201799    } 
    18211800 
    1822     emitter->whitespace = 0; 
    1823     emitter->indention = 0; 
     1801    emitter->is_whitespace = 0; 
     1802    emitter->is_indention = 0;