Changeset 264 for libyaml/trunk/src/api.c
- Timestamp:
- 12/27/07 12:14:01 (5 years ago)
- File:
-
- 1 edited
-
libyaml/trunk/src/api.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/src/api.c
r263 r264 68 68 69 69 /* 70 * Format an error message. 71 */ 72 73 YAML_DECLARE(int) 74 yaml_error_message(yaml_error_t *error, char *buffer, size_t capacity) 75 { 76 char *prefixes[] = { 77 "No error", 78 "Memory error", 79 "Reader error", 80 "Decoder error", 81 "Scanner error", 82 "Parser error", 83 "Composer error", 84 "Writer error", 85 "Emitter error", 86 "Serializer error", 87 "Resolver error", 88 }; 89 int length; 90 91 assert(error); /* Non-NULL error is expected. */ 92 assert(buffer); /* Non-NULL buffer is expected. */ 93 94 switch (error->type) 95 { 96 case YAML_NO_ERROR: 97 case YAML_MEMORY_ERROR: 98 length = snprintf(buffer, capacity, "%s", 99 prefixes[error->type]); 100 break; 101 102 case YAML_READER_ERROR: 103 case YAML_DECODER_ERROR: 104 if (error->data.reading.value == -1) { 105 length = snprintf(buffer, capacity, 106 "%s: %s at position %d", 107 prefixes[error->type], 108 error->data.reading.problem, 109 error->data.reading.offset); 110 } 111 else { 112 length = snprintf(buffer, capacity, 113 "%s: %s (#%X) at position %d", 114 prefixes[error->type], 115 error->data.reading.problem, 116 error->data.reading.value, 117 error->data.reading.offset); 118 } 119 break; 120 121 case YAML_SCANNER_ERROR: 122 case YAML_PARSER_ERROR: 123 case YAML_COMPOSER_ERROR: 124 if (!error->data.loading.context) { 125 length = snprintf(buffer, capacity, 126 "%s: %s at line %d, column %d", 127 prefixes[error->type], 128 error->data.loading.problem, 129 error->data.loading.problem_mark.line+1, 130 error->data.loading.problem_mark.column+1); 131 } 132 else { 133 length = snprintf(buffer, capacity, 134 "%s: %s at line %d, column %d, %s at line %d, column %d", 135 prefixes[error->type], 136 error->data.loading.context, 137 error->data.loading.context_mark.line+1, 138 error->data.loading.context_mark.column+1, 139 error->data.loading.problem, 140 error->data.loading.problem_mark.line+1, 141 error->data.loading.problem_mark.column+1); 142 } 143 break; 144 145 case YAML_WRITER_ERROR: 146 length = snprintf(buffer, capacity, 147 "%s: %s at position %d", 148 prefixes[error->type], 149 error->data.writing.problem, 150 error->data.writing.offset); 151 break; 152 153 case YAML_EMITTER_ERROR: 154 case YAML_SERIALIZER_ERROR: 155 length = snprintf(buffer, capacity, "%s: %s", 156 prefixes[error->type], 157 error->data.dumping.problem); 158 break; 159 160 case YAML_RESOLVER_ERROR: 161 length = snprintf(buffer, capacity, "%s: %s", 162 prefixes[error->type], 163 error->data.resolving.problem); 164 break; 165 166 default: 167 assert(0); /* Should never happen. */ 168 } 169 170 return (length >= 0 && length < capacity); 171 } 172 173 174 /* 70 175 * Extend a string. 71 176 */ 72 177 73 178 YAML_DECLARE(int) 74 yaml_ string_extend(yaml_char_t **buffer, size_t *capacity)179 yaml_ostring_extend(yaml_char_t **buffer, size_t *capacity) 75 180 { 76 181 yaml_char_t *new_buffer = yaml_realloc(*buffer, (*capacity)*2); … … 91 196 92 197 YAML_DECLARE(int) 93 yaml_ string_join(198 yaml_ostring_join( 94 199 yaml_char_t **base_buffer, size_t *base_pointer, size_t *base_capacity, 95 yaml_char_t *adj_buffer, size_t adj_pointer , size_t adj_capacity)200 yaml_char_t *adj_buffer, size_t adj_pointer) 96 201 { 97 202 if (!adj_pointer) … … 99 204 100 205 while (*base_capacity - *base_pointer <= adj_pointer) { 101 if (!yaml_ string_extend(base_buffer, base_capacity))206 if (!yaml_ostring_extend(base_buffer, base_capacity)) 102 207 return 0; 103 208 } … … 173 278 174 279 memset(parser, 0, sizeof(yaml_parser_t)); 175 if (! STRING_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY))280 if (!IOSTRING_INIT(parser, parser->raw_input, RAW_INPUT_BUFFER_CAPACITY)) 176 281 goto error; 177 if (! STRING_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY))282 if (!IOSTRING_INIT(parser, parser->input, INPUT_BUFFER_CAPACITY)) 178 283 goto error; 179 284 if (!QUEUE_INIT(parser, parser->tokens, INITIAL_QUEUE_CAPACITY)) … … 207 312 assert(parser); /* Non-NULL parser object expected. */ 208 313 209 STRING_DEL(parser, parser->raw_input);210 STRING_DEL(parser, parser->input);314 IOSTRING_DEL(parser, parser->raw_input); 315 IOSTRING_DEL(parser, parser->input); 211 316 while (!QUEUE_EMPTY(parser, parser->tokens)) { 212 317 yaml_token_destroy(&DEQUEUE(parser, parser->tokens)); … … 250 355 yaml_standard_reader_data_t *data = untyped_data; 251 356 252 if (data->string.pointer == data->string. capacity) {357 if (data->string.pointer == data->string.length) { 253 358 *length = 0; 254 359 return 1; 255 360 } 256 361 257 if (capacity > (size_t)(data->string. capacity- data->string.pointer)) {258 capacity = data->string. capacity- data->string.pointer;362 if (capacity > (size_t)(data->string.length - data->string.pointer)) { 363 capacity = data->string.length - data->string.pointer; 259 364 } 260 365 … … 294 399 parser->reader_data = &(parser->standard_reader_data); 295 400 296 parser->standard_reader_data.string.buffer = (unsigned char *)buffer;401 parser->standard_reader_data.string.buffer = buffer; 297 402 parser->standard_reader_data.string.pointer = 0; 298 parser->standard_reader_data.string. capacity= length;403 parser->standard_reader_data.string.length = length; 299 404 } 300 405 … … 358 463 359 464 memset(emitter, 0, sizeof(yaml_emitter_t)); 360 if (! STRING_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY))465 if (!IOSTRING_INIT(emitter, emitter->output, OUTPUT_BUFFER_CAPACITY)) 361 466 goto error; 362 if (! STRING_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY))467 if (!IOSTRING_INIT(emitter, emitter->raw_output, RAW_OUTPUT_BUFFER_CAPACITY)) 363 468 goto error; 364 469 if (!STACK_INIT(emitter, emitter->states, INITIAL_STACK_CAPACITY)) … … 388 493 assert(emitter); /* Non-NULL emitter object expected. */ 389 494 390 STRING_DEL(emitter, emitter->output);391 STRING_DEL(emitter, emitter->raw_output);495 IOSTRING_DEL(emitter, emitter->output); 496 IOSTRING_DEL(emitter, emitter->raw_output); 392 497 STACK_DEL(emitter, emitter->states); 393 498 while (!QUEUE_EMPTY(emitter, emitter->events)) { … … 425 530 426 531 static int 427 yaml_string_writer(void *untyped_data, unsigned char *buffer, size_t length)532 yaml_string_writer(void *untyped_data, const unsigned char *buffer, size_t length) 428 533 { 429 534 yaml_standard_writer_data_t *data = untyped_data; … … 447 552 448 553 static int 449 yaml_file_writer(void *untyped_data, unsigned char *buffer, size_t length)554 yaml_file_writer(void *untyped_data, const unsigned char *buffer, size_t length) 450 555 { 451 556 yaml_standard_writer_data_t *data = untyped_data; … … 617 722 618 723 YAML_DECLARE(int) 619 yaml_token_duplicate(yaml_token_t *token, yaml_token_t *model)724 yaml_token_duplicate(yaml_token_t *token, const yaml_token_t *model) 620 725 { 621 726 assert(token); /* Non-NULL token object is expected. */ … … 810 915 811 916 YAML_DECLARE(int) 812 yaml_event_duplicate(yaml_event_t *event, yaml_event_t *model)917 yaml_event_duplicate(yaml_event_t *event, const yaml_event_t *model) 813 918 { 814 919 struct {
Note: See TracChangeset
for help on using the changeset viewer.
