Changeset 264
- Timestamp:
- 12/27/07 12:14:01 (5 years ago)
- Location:
- libyaml/trunk
- Files:
-
- 10 edited
-
configure.ac (modified) (3 diffs)
-
include/yaml.h (modified) (16 diffs)
-
src/api.c (modified) (13 diffs)
-
src/emitter.c (modified) (43 diffs)
-
src/parser.c (modified) (7 diffs)
-
src/reader.c (modified) (22 diffs)
-
src/scanner.c (modified) (33 diffs)
-
src/writer.c (modified) (5 diffs)
-
src/yaml_private.h (modified) (40 diffs)
-
tests/run-scanner.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libyaml/trunk/configure.ac
r238 r264 3 3 # Define the package version numbers and the bug reporting link. 4 4 m4_define([YAML_MAJOR], 0) 5 m4_define([YAML_MINOR], 0)6 m4_define([YAML_PATCH], 1)5 m4_define([YAML_MINOR], 2) 6 m4_define([YAML_PATCH], 0) 7 7 m4_define([YAML_BUGS], [http://pyyaml.org/newticket?component=libyaml]) 8 8 … … 19 19 # YAML_AGE = 0 20 20 m4_define([YAML_RELEASE], 0) 21 m4_define([YAML_CURRENT], 1)21 m4_define([YAML_CURRENT], 2) 22 22 m4_define([YAML_REVISION], 0) 23 23 m4_define([YAML_AGE], 0) … … 29 29 AC_CONFIG_HEADERS([config.h]) 30 30 AM_INIT_AUTOMAKE([1.9 foreign]) 31 32 # Define macro variables for the package version numbers.33 AC_DEFINE(YAML_VERSION_MAJOR, YAML_MAJOR, [Define the major version number.])34 AC_DEFINE(YAML_VERSION_MINOR, YAML_MINOR, [Define the minor version number.])35 AC_DEFINE(YAML_VERSION_PATCH, YAML_PATCH, [Define the patch version number.])36 AC_DEFINE(YAML_VERSION_STRING, "YAML_MAJOR.YAML_MINOR.YAML_PATCH", [Define the version string.])37 31 38 32 # Define substitutions for the libtool version numbers. -
libyaml/trunk/include/yaml.h
r261 r264 46 46 */ 47 47 48 /** 49 * Get the library version as a string. 50 * 51 * @returns The function returns the pointer to a static string of the form 52 * @c "X.Y.Z", where @c X is the major version number, @c Y is a minor version 53 * number, and @c Z is the patch version number. 54 */ 55 56 YAML_DECLARE(const char *) 57 yaml_get_version_string(void); 58 59 /** 60 * Get the library version numbers. 48 /** The major version number. */ 49 #define YAML_VERSION_MAJOR 0 50 51 /** The minor version number. */ 52 #define YAML_VERSION_MINOR 2 53 54 /** The patch version number. */ 55 #define YAML_VERSION_PATCH 0 56 57 /** The version string generator macro. */ 58 #define YAML_VERSION_STRING_GENERATOR(major,minor,patch) \ 59 (#major "." #minor "." #patch) 60 61 /** The version string. */ 62 #define YAML_VERSION_STRING \ 63 YAML_VERSION_STRING_GENERATOR(YAML_VERSION_MAJOR,YAML_VERSION_MINOR,YAML_VERSION_PATCH) 64 65 /** 66 * Get the library version numbers at runtime. 61 67 * 62 68 * @param[out] major Major version number. … … 67 73 YAML_DECLARE(void) 68 74 yaml_get_version(int *major, int *minor, int *patch); 75 76 /** 77 * Get the library version as a string at runtime. 78 * 79 * @returns The function returns the pointer to a static string of the form 80 * @c "X.Y.Z", where @c X is the major version number, @c Y is the minor version 81 * number, and @c Z is the patch version number. 82 */ 83 84 YAML_DECLARE(const char *) 85 yaml_get_version_string(void); 69 86 70 87 /** @} */ … … 87 104 /** Cannot decode the input stream. */ 88 105 YAML_DECODER_ERROR, 89 90 106 /** Cannot scan a YAML token. */ 91 107 YAML_SCANNER_ERROR, … … 97 113 /** Cannot write into the output stream. */ 98 114 YAML_WRITER_ERROR, 99 100 115 /** Cannot emit a YAML event. */ 101 116 YAML_EMITTER_ERROR, 102 117 /** Cannot serialize a YAML document. */ 103 YAML_SERIALIZER_ERROR 118 YAML_SERIALIZER_ERROR, 119 120 /** Cannot resolve an implicit tag. */ 121 YAML_RESOLVER_ERROR 104 122 } yaml_error_type_t; 105 123 … … 143 161 */ 144 162 struct { 145 /** The problem description. */146 const char *problem;147 /** The problem mark. */148 yaml_mark_t problem_mark;149 163 /** The context in which the problem occured 150 164 * (@c NULL if not applicable). … … 153 167 /** The context mark (if @c problem_mark is not @c NULL). **/ 154 168 yaml_mark_t context_mark; 169 /** The problem description. */ 170 const char *problem; 171 /** The problem mark. */ 172 yaml_mark_t problem_mark; 155 173 } loading; 156 174 … … 171 189 } dumping; 172 190 191 /** A problem while resolving an implicit tag (@c YAML_RESOLVER_ERROR). */ 192 struct { 193 /** The problem description. */ 194 const char *problem; 195 } resolving; 196 173 197 } data; 174 198 175 199 } yaml_error_t; 176 200 201 /** 202 * Create an error message. 203 * 204 * @param[in] error An error object. 205 * @param[out] buffer model A token to copy. 206 * 207 * @returns @c 1 if the function succeeded, @c 0 on error. The function may 208 * fail if the buffer is not large enough to contain the whole message. 209 */ 210 211 YAML_DECLARE(int) 212 yaml_error_message(yaml_error_t *error, char *buffer, size_t capacity); 177 213 178 214 /** @} */ … … 434 470 435 471 YAML_DECLARE(int) 436 yaml_token_duplicate(yaml_token_t *token, yaml_token_t *model);472 yaml_token_duplicate(yaml_token_t *token, const yaml_token_t *model); 437 473 438 474 /** … … 608 644 609 645 YAML_DECLARE(int) 610 yaml_event_duplicate(yaml_event_t *event, yaml_event_t *model);646 yaml_event_duplicate(yaml_event_t *event, const yaml_event_t *model); 611 647 612 648 /** … … 792 828 793 829 /** The tag @c !!null with the only possible value: @c null. */ 794 #define YAML_NULL_TAG "tag:yaml.org,2002:null"830 #define YAML_NULL_TAG ((const yaml_char_t *) "tag:yaml.org,2002:null") 795 831 /** The tag @c !!bool with the values: @c true and @c falce. */ 796 #define YAML_BOOL_TAG "tag:yaml.org,2002:bool"832 #define YAML_BOOL_TAG ((const yaml_char_t *) "tag:yaml.org,2002:bool") 797 833 /** The tag @c !!str for string values. */ 798 #define YAML_STR_TAG "tag:yaml.org,2002:str"834 #define YAML_STR_TAG ((const yaml_char_t *) "tag:yaml.org,2002:str") 799 835 /** The tag @c !!int for integer values. */ 800 #define YAML_INT_TAG "tag:yaml.org,2002:int"836 #define YAML_INT_TAG ((const yaml_char_t *) "tag:yaml.org,2002:int") 801 837 /** The tag @c !!float for float values. */ 802 #define YAML_FLOAT_TAG "tag:yaml.org,2002:float"838 #define YAML_FLOAT_TAG ((const yaml_char_t *) "tag:yaml.org,2002:float") 803 839 804 840 /** The tag @c !!seq is used to denote sequences. */ 805 #define YAML_SEQ_TAG "tag:yaml.org,2002:seq"841 #define YAML_SEQ_TAG ((const yaml_char_t *) "tag:yaml.org,2002:seq") 806 842 /** The tag @c !!map is used to denote mapping. */ 807 #define YAML_MAP_TAG "tag:yaml.org,2002:map"843 #define YAML_MAP_TAG ((const yaml_char_t *) "tag:yaml.org,2002:map") 808 844 809 845 /** The default scalar tag is @c !!str. */ … … 1228 1264 */ 1229 1265 1230 typedef int yaml_writer_t(void *data, unsigned char *buffer, size_t length); 1266 typedef int yaml_writer_t(void *data, const unsigned char *buffer, 1267 size_t length); 1231 1268 1232 1269 /** … … 1399 1436 1400 1437 YAML_DECLARE(int) 1401 yaml_parser_ scan(yaml_parser_t *parser, yaml_token_t *token);1438 yaml_parser_parse_token(yaml_parser_t *parser, yaml_token_t *token); 1402 1439 1403 1440 /** … … 1423 1460 1424 1461 YAML_DECLARE(int) 1425 yaml_parser_parse (yaml_parser_t *parser, yaml_event_t *event);1462 yaml_parser_parse_event(yaml_parser_t *parser, yaml_event_t *event); 1426 1463 1427 1464 #if 0 … … 1450 1487 1451 1488 YAML_DECLARE(int) 1452 yaml_parser_ load(yaml_parser_t *parser, yaml_document_t *document);1489 yaml_parser_parse_document(yaml_parser_t *parser, yaml_document_t *document); 1453 1490 1454 1491 #endif … … 1648 1685 1649 1686 YAML_DECLARE(int) 1650 yaml_emitter_emit (yaml_emitter_t *emitter, yaml_event_t *event);1687 yaml_emitter_emit_event(yaml_emitter_t *emitter, yaml_event_t *event); 1651 1688 1652 1689 #if 0 … … 1695 1732 1696 1733 YAML_DECLARE(int) 1697 yaml_emitter_ dump(yaml_emitter_t *emitter, yaml_document_t *document);1734 yaml_emitter_emit_document(yaml_emitter_t *emitter, yaml_document_t *document); 1698 1735 1699 1736 #endif -
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 { -
libyaml/trunk/src/emitter.c
r263 r264 14 14 */ 15 15 16 #define PUT(emitter, value)\16 #define PUT(emitter, value) \ 17 17 (FLUSH(emitter) \ 18 && (JOIN_OCTET(emitter->output, (yaml_char_t)(value)),\18 && (JOIN_OCTET(emitter->output, (yaml_char_t)(value)), \ 19 19 emitter->column ++, \ 20 20 1)) … … 41 41 */ 42 42 43 #define WRITE(emitter, string)\43 #define WRITE(emitter, string) \ 44 44 (FLUSH(emitter) \ 45 && (COPY(emitter->output, string),\45 && (COPY(emitter->output, string), \ 46 46 emitter->column ++, \ 47 47 1)) … … 51 51 */ 52 52 53 #define WRITE_BREAK(emitter, string)\53 #define WRITE_BREAK(emitter, string) \ 54 54 (FLUSH(emitter) \ 55 && (CHECK(string, '\n') ?\55 && (CHECK(string, '\n') ? \ 56 56 (PUT_BREAK(emitter), \ 57 57 string.pointer ++, \ 58 58 1) : \ 59 (COPY(emitter->output, string),\59 (COPY(emitter->output, string), \ 60 60 emitter->column = 0, \ 61 61 emitter->line ++, \ … … 67 67 68 68 YAML_DECLARE(int) 69 yaml_emitter_emit (yaml_emitter_t *emitter, yaml_event_t *event);69 yaml_emitter_emit_event(yaml_emitter_t *emitter, yaml_event_t *event); 70 70 71 71 /* … … 219 219 static int 220 220 yaml_emitter_write_indicator(yaml_emitter_t *emitter, 221 c har *indicator, int need_whitespace,221 const char *indicator, int need_whitespace, 222 222 int is_whitespace, int is_indention); 223 223 224 224 static int 225 225 yaml_emitter_write_anchor(yaml_emitter_t *emitter, 226 yaml_char_t *value, size_t length);226 const yaml_char_t *value, size_t length); 227 227 228 228 static int 229 229 yaml_emitter_write_tag_handle(yaml_emitter_t *emitter, 230 yaml_char_t *value, size_t length);230 const yaml_char_t *value, size_t length); 231 231 232 232 static int 233 233 yaml_emitter_write_tag_content(yaml_emitter_t *emitter, 234 yaml_char_t *value, size_t length, int need_whitespace);234 const yaml_char_t *value, size_t length, int need_whitespace); 235 235 236 236 static int 237 237 yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, 238 yaml_char_t *value, size_t length, int allow_breaks);238 const yaml_char_t *value, size_t length, int allow_breaks); 239 239 240 240 static int 241 241 yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter, 242 yaml_char_t *value, size_t length, int allow_breaks);242 const yaml_char_t *value, size_t length, int allow_breaks); 243 243 244 244 static int 245 245 yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, 246 yaml_char_t *value, size_t length, int allow_breaks);246 const yaml_char_t *value, size_t length, int allow_breaks); 247 247 248 248 static int 249 249 yaml_emitter_determine_chomping(yaml_emitter_t *emitter, 250 yaml_ string_t string);250 yaml_istring_t string); 251 251 252 252 static int 253 253 yaml_emitter_write_literal_scalar(yaml_emitter_t *emitter, 254 yaml_char_t *value, size_t length);254 const yaml_char_t *value, size_t length); 255 255 256 256 static int 257 257 yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter, 258 yaml_char_t *value, size_t length);258 const yaml_char_t *value, size_t length); 259 259 260 260 /* … … 263 263 264 264 YAML_DECLARE(int) 265 yaml_emitter_emit (yaml_emitter_t *emitter, yaml_event_t *event)265 yaml_emitter_emit_event(yaml_emitter_t *emitter, yaml_event_t *event) 266 266 { 267 267 if (!ENQUEUE(emitter, emitter->events, *event)) { … … 468 468 469 469 default: 470 assert( 1); /* Invalid state. */470 assert(0); /* Invalid state. */ 471 471 } 472 472 … … 1287 1287 1288 1288 default: 1289 assert( 1); /* Impossible. */1289 assert(0); /* Impossible. */ 1290 1290 } 1291 1291 … … 1316 1316 yaml_tag_directive_t tag_directive) 1317 1317 { 1318 yaml_ string_t handle =STRING(tag_directive.handle,1318 yaml_istring_t handle = ISTRING(tag_directive.handle, 1319 1319 strlen((char *)tag_directive.handle)); 1320 yaml_ string_t prefix =STRING(tag_directive.prefix,1320 yaml_istring_t prefix = ISTRING(tag_directive.prefix, 1321 1321 strlen((char *)tag_directive.prefix)); 1322 1322 1323 if (!handle. capacity) {1323 if (!handle.length) { 1324 1324 return EMITTER_ERROR_INIT(emitter, "tag handle must not be empty"); 1325 1325 } … … 1329 1329 } 1330 1330 1331 if (handle.buffer[handle. capacity-1] != '!') {1331 if (handle.buffer[handle.length-1] != '!') { 1332 1332 return EMITTER_ERROR_INIT(emitter, "tag handle must end with '!'"); 1333 1333 } … … 1335 1335 handle.pointer ++; 1336 1336 1337 while (handle.pointer < handle. capacity-1) {1337 while (handle.pointer < handle.length-1) { 1338 1338 if (!IS_ALPHA(handle)) { 1339 1339 return EMITTER_ERROR_INIT(emitter, … … 1343 1343 } 1344 1344 1345 if (!prefix. capacity) {1345 if (!prefix.length) { 1346 1346 return EMITTER_ERROR_INIT(emitter, "tag prefix must not be empty"); 1347 1347 } … … 1358 1358 yaml_char_t *anchor, int is_alias) 1359 1359 { 1360 yaml_ string_t string =STRING(anchor, strlen((char *)anchor));1361 1362 if (!string. capacity) {1360 yaml_istring_t string = ISTRING(anchor, strlen((char *)anchor)); 1361 1362 if (!string.length) { 1363 1363 return EMITTER_ERROR_INIT(emitter, is_alias ? 1364 1364 "alias value must not be empty" : … … 1366 1366 } 1367 1367 1368 while (string.pointer < string. capacity) {1368 while (string.pointer < string.length) { 1369 1369 if (!IS_ALPHA(string)) { 1370 1370 return EMITTER_ERROR_INIT(emitter, is_alias ? … … 1376 1376 1377 1377 emitter->anchor_data.anchor = string.buffer; 1378 emitter->anchor_data.anchor_length = string. capacity;1378 emitter->anchor_data.anchor_length = string.length; 1379 1379 emitter->anchor_data.is_alias = is_alias; 1380 1380 … … 1390 1390 yaml_char_t *tag) 1391 1391 { 1392 yaml_ string_t string =STRING(tag, strlen((char *)tag));1392 yaml_istring_t string = ISTRING(tag, strlen((char *)tag)); 1393 1393 size_t idx; 1394 1394 1395 if (!string. capacity) {1395 if (!string.length) { 1396 1396 return EMITTER_ERROR_INIT(emitter, "tag value must not be empty"); 1397 1397 } 1398 1398 1399 1399 for (idx = 0; idx < emitter->tag_directives.length; idx ++) { 1400 yaml_tag_directive_t *tag_directive = emitter->tag_directives.list+idx; 1400 yaml_tag_directive_t *tag_directive = 1401 STACK_ITER(emitter, emitter->tag_directives, idx); 1401 1402 size_t prefix_length = strlen((char *)tag_directive->prefix); 1402 if (prefix_length < string. capacity1403 if (prefix_length < string.length 1403 1404 && strncmp((char *)tag_directive->prefix, (char *)string.buffer, 1404 1405 prefix_length) == 0) … … 1408 1409 strlen((char *)tag_directive->handle); 1409 1410 emitter->tag_data.suffix = string.buffer + prefix_length; 1410 emitter->tag_data.suffix_length = string. capacity- prefix_length;1411 emitter->tag_data.suffix_length = string.length - prefix_length; 1411 1412 return 1; 1412 1413 } … … 1414 1415 1415 1416 emitter->tag_data.suffix = string.buffer; 1416 emitter->tag_data.suffix_length = string. capacity;1417 emitter->tag_data.suffix_length = string.length; 1417 1418 1418 1419 return 1; … … 1427 1428 yaml_char_t *value, size_t length) 1428 1429 { 1429 yaml_ string_t string =STRING(value, length);1430 yaml_istring_t string = ISTRING(value, length); 1430 1431 1431 1432 int block_indicators = 0; … … 1453 1454 emitter->scalar_data.length = length; 1454 1455 1455 if (!string. capacity)1456 if (!string.length) 1456 1457 { 1457 1458 emitter->scalar_data.is_multiline = 0; … … 1477 1478 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1478 1479 1479 while (string.pointer < string. capacity)1480 while (string.pointer < string.length) 1480 1481 { 1481 1482 if (!string.pointer) … … 1584 1585 } 1585 1586 1586 if ((spaces || breaks) && string.pointer == string. capacity-1)1587 if ((spaces || breaks) && string.pointer == string.length-1) 1587 1588 { 1588 1589 if (spaces && breaks) { … … 1605 1606 preceeded_by_space = IS_BLANKZ(string); 1606 1607 MOVE(string); 1607 if (string.pointer < string. capacity) {1608 if (string.pointer < string.length) { 1608 1609 followed_by_space = IS_BLANKZ_AT(string, WIDTH(string)); 1609 1610 } … … 1770 1771 static int 1771 1772 yaml_emitter_write_indicator(yaml_emitter_t *emitter, 1772 c har *indicator, int need_whitespace,1773 const char *indicator, int need_whitespace, 1773 1774 int is_whitespace, int is_indention) 1774 1775 { 1775 yaml_ string_t string =STRING((yaml_char_t *)indicator, strlen(indicator));1776 yaml_istring_t string = ISTRING((yaml_char_t *)indicator, strlen(indicator)); 1776 1777 1777 1778 if (need_whitespace && !emitter->is_whitespace) { … … 1779 1780 } 1780 1781 1781 while (string.pointer < string. capacity) {1782 while (string.pointer < string.length) { 1782 1783 if (!WRITE(emitter, string)) return 0; 1783 1784 } … … 1791 1792 static int 1792 1793 yaml_emitter_write_anchor(yaml_emitter_t *emitter, 1793 yaml_char_t *value, size_t length)1794 { 1795 yaml_ string_t string =STRING(value, length);1796 1797 while (string.pointer < string. capacity) {1794 const yaml_char_t *value, size_t length) 1795 { 1796 yaml_istring_t string = ISTRING(value, length); 1797 1798 while (string.pointer < string.length) { 1798 1799 if (!WRITE(emitter, string)) return 0; 1799 1800 } … … 1807 1808 static int 1808 1809 yaml_emitter_write_tag_handle(yaml_emitter_t *emitter, 1809 yaml_char_t *value, size_t length)1810 { 1811 yaml_ string_t string =STRING(value, length);1810 const yaml_char_t *value, size_t length) 1811 { 1812 yaml_istring_t string = ISTRING(value, length); 1812 1813 1813 1814 if (!emitter->is_whitespace) { … … 1815 1816 } 1816 1817 1817 while (string.pointer < string. capacity) {1818 while (string.pointer < string.length) { 1818 1819 if (!WRITE(emitter, string)) return 0; 1819 1820 } … … 1827 1828 static int 1828 1829 yaml_emitter_write_tag_content(yaml_emitter_t *emitter, 1829 yaml_char_t *value, size_t length,1830 const yaml_char_t *value, size_t length, 1830 1831 int need_whitespace) 1831 1832 { 1832 yaml_ string_t string =STRING(value, length);1833 yaml_istring_t string = ISTRING(value, length); 1833 1834 1834 1835 if (need_whitespace && !emitter->is_whitespace) { … … 1836 1837 } 1837 1838 1838 while (string.pointer < string. capacity) {1839 while (string.pointer < string.length) { 1839 1840 if (IS_ALPHA(string) 1840 1841 || CHECK(string, ';') || CHECK(string, '/') … … 1875 1876 static int 1876 1877 yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter, 1877 yaml_char_t *value, size_t length, int allow_breaks)1878 { 1879 yaml_ string_t string =STRING(value, length);1878 const yaml_char_t *value, size_t length, int allow_breaks) 1879 { 1880 yaml_istring_t string = ISTRING(value, length); 1880 1881 int spaces = 0; 1881 1882 int breaks = 0; … … 1885 1886 } 1886 1887 1887 while (string.pointer < string. capacity)1888 while (string.pointer < string.length) 1888 1889 { 1889 1890 if (IS_SPACE(string)) … … 1929 1930 static int 1930 1931 yaml_emitter_write_single_quoted_scalar(yaml_emitter_t *emitter, 1931 yaml_char_t *value, size_t length, int allow_breaks)1932 { 1933 yaml_ string_t string =STRING(value, length);1932 const yaml_char_t *value, size_t length, int allow_breaks) 1933 { 1934 yaml_istring_t string = ISTRING(value, length); 1934 1935 int spaces = 0; 1935 1936 int breaks = 0; … … 1938 1939 return 0; 1939 1940 1940 while (string.pointer < string. capacity)1941 while (string.pointer < string.length) 1941 1942 { 1942 1943 if (IS_SPACE(string)) … … 1944 1945 if (allow_breaks && !spaces 1945 1946 && emitter->column > emitter->best_width 1946 && string.pointer != 0 1947 && string.pointer != string.capacity - 1 1947 && string.pointer > 0 && string.pointer < string.length 1948 1948 && !IS_SPACE_AT(string, 1)) { 1949 1949 if (!yaml_emitter_write_indent(emitter)) return 0; … … 1990 1990 static int 1991 1991 yaml_emitter_write_double_quoted_scalar(yaml_emitter_t *emitter, 1992 yaml_char_t *value, size_t length, int allow_breaks)1993 { 1994 yaml_ string_t string =STRING(value, length);1992 const yaml_char_t *value, size_t length, int allow_breaks) 1993 { 1994 yaml_istring_t string = ISTRING(value, length); 1995 1995 int spaces = 0; 1996 1996 … … 1998 1998 return 0; 1999 1999 2000 while (string.pointer < string. capacity)2000 while (string.pointer < string.length) 2001 2001 { 2002 2002 if (!IS_PRINTABLE(string) || (!emitter->is_unicode && !IS_ASCII(string)) … … 2113 2113 if (allow_breaks && !spaces 2114 2114 && emitter->column > emitter->best_width 2115 && string.pointer !=02116 && string.pointer != string.capacity - 1) {2115 && string.pointer > 0 2116 && string.pointer < string.length) { 2117 2117 if (!yaml_emitter_write_indent(emitter)) return 0; 2118 2118 if (IS_SPACE_AT(string, 1)) { … … 2144 2144 static int 2145 2145 yaml_emitter_determine_chomping(yaml_emitter_t *emitter, 2146 yaml_ string_t string)2147 { 2148 string.pointer = string. capacity;2146 yaml_istring_t string) 2147 { 2148 string.pointer = string.length; 2149 2149 if (!string.pointer) 2150 2150 return -1; … … 2167 2167 static int 2168 2168 yaml_emitter_write_literal_scalar(yaml_emitter_t *emitter, 2169 yaml_char_t *value, size_t length)2170 { 2171 yaml_ string_t string =STRING(value, length);2169 const yaml_char_t *value, size_t length) 2170 { 2171 yaml_istring_t string = ISTRING(value, length); 2172 2172 int chomp = yaml_emitter_determine_chomping(emitter, string); 2173 2173 int breaks = 0; … … 2179 2179 return 0; 2180 2180 2181 while (string.pointer < string. capacity)2181 while (string.pointer < string.length) 2182 2182 { 2183 2183 if (IS_BREAK(string)) … … 2203 2203 static int 2204 2204 yaml_emitter_write_folded_scalar(yaml_emitter_t *emitter, 2205 yaml_char_t *value, size_t length)2206 { 2207 yaml_ string_t string =STRING(value, length);2205 const yaml_char_t *value, size_t length) 2206 { 2207 yaml_istring_t string = ISTRING(value, length); 2208 2208 int chomp = yaml_emitter_determine_chomping(emitter, string); 2209 2209 int breaks = 1; … … 2216 2216 return 0; 2217 2217 2218 while (string.pointer < string. capacity)2218 while (string.pointer < string.length) 2219 2219 { 2220 2220 if (IS_BREAK(string)) -
libyaml/trunk/src/parser.c
r263 r264 48 48 #define PEEK_TOKEN(parser) \ 49 49 ((parser->is_token_available || yaml_parser_fetch_more_tokens(parser)) ? \ 50 parser->tokens.list + parser->tokens.head: NULL)50 QUEUE_ITER(parser, parser->tokens, 0) : NULL) 51 51 52 52 /* … … 58 58 parser->tokens_parsed ++, \ 59 59 parser->is_stream_end_produced = \ 60 ( parser->tokens.list[parser->tokens.head].type == YAML_STREAM_END_TOKEN),\60 (QUEUE_ITER(parser, parser->tokens, 0)->type == YAML_STREAM_END_TOKEN), \ 61 61 parser->tokens.head ++) 62 62 … … 66 66 67 67 YAML_DECLARE(int) 68 yaml_parser_parse (yaml_parser_t *parser, yaml_event_t *event);68 yaml_parser_parse_event(yaml_parser_t *parser, yaml_event_t *event); 69 69 70 70 /* … … 156 156 157 157 YAML_DECLARE(int) 158 yaml_parser_parse (yaml_parser_t *parser, yaml_event_t *event)158 yaml_parser_parse_event(yaml_parser_t *parser, yaml_event_t *event) 159 159 { 160 160 assert(parser); /* Non-NULL parser object is expected. */ … … 256 256 257 257 default: 258 assert( 1); /* Invalid state. */258 assert(0); /* Invalid state. */ 259 259 } 260 260 … … 563 563 int idx; 564 564 for (idx = 0; idx < parser->tag_directives.length; idx++) { 565 yaml_tag_directive_t *tag_directive = parser->tag_directives.list + idx; 565 yaml_tag_directive_t *tag_directive = 566 STACK_ITER(parser, parser->tag_directives, idx); 566 567 if (strcmp((char *)tag_directive->handle, (char *)tag_handle) == 0) { 567 568 size_t prefix_len = strlen((char *)tag_directive->prefix); … … 1311 1312 1312 1313 for (idx = 0; idx < parser->tag_directives.length; idx++) { 1313 yaml_tag_directive_t *tag_directive = parser->tag_directives.list + idx; 1314 yaml_tag_directive_t *tag_directive = 1315 STACK_ITER(parser, parser->tag_directives, idx); 1314 1316 if (strcmp((char *)value.handle, (char *)tag_directive->handle) == 0) { 1315 1317 if (allow_duplicates) -
libyaml/trunk/src/reader.c
r263 r264 36 36 /* Ensure that we had enough bytes in the raw buffer. */ 37 37 38 while (!parser->is_eof && parser->raw_input. capacity< 3) {38 while (!parser->is_eof && parser->raw_input.length < 3) { 39 39 if (!yaml_parser_update_raw_buffer(parser)) { 40 40 return 0; … … 44 44 /* Determine the encoding. */ 45 45 46 if (parser->raw_input. capacity>= 246 if (parser->raw_input.length >= 2 47 47 && !memcmp(parser->raw_input.buffer, BOM_UTF16LE, 2)) { 48 48 parser->encoding = YAML_UTF16LE_ENCODING; … … 50 50 parser->offset = 2; 51 51 } 52 else if (parser->raw_input. capacity>= 252 else if (parser->raw_input.length >= 2 53 53 && !memcmp(parser->raw_input.buffer, BOM_UTF16BE, 2)) { 54 54 parser->encoding = YAML_UTF16BE_ENCODING; … … 56 56 parser->offset = 2; 57 57 } 58 else if (parser->raw_input. capacity>= 358 else if (parser->raw_input.length >= 3 59 59 && !memcmp(parser->raw_input.buffer, BOM_UTF8, 3)) { 60 60 parser->encoding = YAML_UTF8_ENCODING; … … 81 81 82 82 if (parser->raw_input.pointer == 0 && 83 parser->raw_input. capacity == RAW_INPUT_BUFFER_CAPACITY)83 parser->raw_input.length == parser->raw_input.capacity) 84 84 return 1; 85 85 … … 92 92 93 93 if (parser->raw_input.pointer > 0 && 94 parser->raw_input.pointer < parser->raw_input. capacity) {94 parser->raw_input.pointer < parser->raw_input.length) { 95 95 memmove(parser->raw_input.buffer, 96 96 parser->raw_input.buffer + parser->raw_input.pointer, 97 parser->raw_input. capacity- parser->raw_input.pointer);98 } 99 parser->raw_input. capacity-= parser->raw_input.pointer;97 parser->raw_input.length - parser->raw_input.pointer); 98 } 99 parser->raw_input.length -= parser->raw_input.pointer; 100 100 parser->raw_input.pointer = 0; 101 101 … … 103 103 104 104 if (!parser->reader(parser->reader_data, 105 parser->raw_input.buffer + parser->raw_input. capacity,106 RAW_INPUT_BUFFER_CAPACITY - parser->raw_input.capacity,105 parser->raw_input.buffer + parser->raw_input.length, 106 parser->raw_input.capacity - parser->raw_input.length, 107 107 &length)) { 108 return READER_ERROR_INIT(parser, " Inputerror", parser->offset);109 } 110 parser->raw_input. capacity+= length;108 return READER_ERROR_INIT(parser, "read handler error", parser->offset); 109 } 110 parser->raw_input.length += length; 111 111 if (!length) { 112 112 parser->is_eof = 1; … … 126 126 yaml_parser_update_buffer(yaml_parser_t *parser, size_t length) 127 127 { 128 size_t old_capacity;129 130 128 assert(parser->reader); /* Read handler must be set. */ 131 129 132 130 /* If the EOF flag is set and the raw buffer is empty, do nothing. */ 133 131 134 if (parser->is_eof && parser->raw_input.pointer == parser->raw_input. capacity)132 if (parser->is_eof && parser->raw_input.pointer == parser->raw_input.length) 135 133 return 1; 136 134 … … 150 148 151 149 if (parser->input.pointer > 0 && 152 parser->input.pointer < parser->input. capacity) {150 parser->input.pointer < parser->input.length) { 153 151 memmove(parser->input.buffer, 154 152 parser->input.buffer + parser->input.pointer, 155 parser->input. capacity- parser->input.pointer);156 parser->input. capacity-= parser->input.pointer;157 } 158 else if (parser->input.pointer == parser->input. capacity) {159 parser->input. capacity= 0;160 } 161 162 /* S et the pointer to the end of the buffer. */163 164 parser->input.pointer = parser->input. capacity;153 parser->input.length - parser->input.pointer); 154 parser->input.length -= parser->input.pointer; 155 } 156 else if (parser->input.pointer == parser->input.length) { 157 parser->input.length = 0; 158 } 159 160 /* Switch the buffer to the output mode. */ 161 162 parser->input.pointer = parser->input.length; 165 163 166 164 /* Fill the buffer until it has enough characters. */ … … 174 172 /* Decode the raw buffer. */ 175 173 176 while (parser->raw_input.pointer != parser->raw_input.capacity)174 while (parser->raw_input.pointer < parser->raw_input.length) 177 175 { 178 176 size_t raw_unread = 179 parser->raw_input. capacity- parser->raw_input.pointer;177 parser->raw_input.length - parser->raw_input.pointer; 180 178 unsigned int value = 0, value2 = 0; 181 179 int is_incomplete = 0; … … 223 221 if (!width) 224 222 return DECODER_ERROR_INIT(parser, 225 " Invalid leading UTF-8 octet",223 "invalid leading UTF-8 octet", 226 224 parser->offset, octet); 227 225 … … 231 229 if (parser->is_eof) { 232 230 return DECODER_ERROR_INIT(parser, 233 " Incomplete UTF-8 octet sequence",231 "incomplete UTF-8 octet sequence", 234 232 parser->offset, -1); 235 233 } … … 255 253 if ((octet & 0xC0) != 0x80) 256 254 return DECODER_ERROR_INIT(parser, 257 " Invalid trailing UTF-8 octet",255 "invalid trailing UTF-8 octet", 258 256 parser->offset+idx, octet); 259 257 … … 270 268 (width == 4 && value >= 0x10000))) 271 269 return DECODER_ERROR_INIT(parser, 272 " Invalid length of a UTF-8 sequence",270 "invalid length of a UTF-8 sequence", 273 271 parser->offset, -1); 274 272 … … 277 275 if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) 278 276 return DECODER_ERROR_INIT(parser, 279 " Invalid Unicode character",277 "invalid Unicode character", 280 278 parser->offset, value); 281 279 … … 319 317 if (parser->is_eof) { 320 318 return DECODER_ERROR_INIT(parser, 321 " Incomplete UTF-16 character",319 "incomplete UTF-16 character", 322 320 parser->offset, -1); 323 321 } … … 335 333 if ((value & 0xFC00) == 0xDC00) 336 334 return DECODER_ERROR_INIT(parser, 337 " Unexpected low surrogate area",335 "unexpected low surrogate area", 338 336 parser->offset, value); 339 337 … … 349 347 if (parser->is_eof) { 350 348 return DECODER_ERROR_INIT(parser, 351 " Incomplete UTF-16 surrogate pair",349 "incomplete UTF-16 surrogate pair", 352 350 parser->offset, -1); 353 351 } … … 365 363 if ((value2 & 0xFC00) != 0xDC00) 366 364 return DECODER_ERROR_INIT(parser, 367 " Expected low surrogate area",365 "expected low surrogate area", 368 366 parser->offset+2, value2); 369 367 … … 380 378 381 379 default: 382 assert( 1); /* Impossible. */380 assert(0); /* Impossible. */ 383 381 } 384 382 … … 401 399 || (value >= 0x10000 && value <= 0x10FFFF))) 402 400 return DECODER_ERROR_INIT(parser, 403 " Control characters are not allowed",401 "control characters are not allowed", 404 402 parser->offset, value); 405 403 … … 446 444 447 445 } 448 /* Swap the pointer with the end of the buffer. */ 449 450 old_capacity = parser->input.capacity; 451 parser->input. capacity= parser->input.pointer;452 parser->input.pointer = old_capacity;446 447 /* Switch the the buffer back to the input mode. */ 448 449 parser->input.length = parser->input.pointer; 450 parser->input.pointer = 0; 453 451 454 452 return 1; -
libyaml/trunk/src/scanner.c
r263 r264 516 516 */ 517 517 518 #define READ(parser, string)\519 ( STRING_EXTEND(parser,string) ?\520 (COPY(string, parser->input),\518 #define READ(parser, string) \ 519 (OSTRING_EXTEND(parser, string) ? \ 520 (COPY(string, parser->input), \ 521 521 parser->mark.index ++, \ 522 522 parser->mark.column ++, \ … … 528 528 */ 529 529 530 #define READ_LINE(parser, string)\531 ( STRING_EXTEND(parser,string) ?\532 (((CHECK_AT(parser->input, '\r',0)\533 && CHECK_AT(parser->input, '\n',1)) ?/* CR LF -> LF */ \530 #define READ_LINE(parser, string) \ 531 (OSTRING_EXTEND(parser, string) ? \ 532 (((CHECK_AT(parser->input, '\r', 0) \ 533 && CHECK_AT(parser->input, '\n', 1)) ? /* CR LF -> LF */ \ 534 534 (JOIN_OCTET(string, (yaml_char_t) '\n'), \ 535 535 parser->input.pointer += 2, \ … … 538 538 parser->mark.line ++, \ 539 539 parser->unread -= 2) : \ 540 (CHECK_AT(parser->input, '\r',0)\541 || CHECK_AT(parser->input, '\n',0)) ?/* CR|LF -> LF */ \542 (JOIN_OCTET(string, (yaml_char_t) '\n'),\540 (CHECK_AT(parser->input, '\r', 0) \ 541 || CHECK_AT(parser->input, '\n', 0)) ? /* CR|LF -> LF */ \ 542 (JOIN_OCTET(string, (yaml_char_t) '\n'), \ 543 543 parser->input.pointer ++, \ 544 544 parser->mark.index ++, \ … … 546 546 parser->mark.line ++, \ 547 547 parser->unread --) : \ 548 (CHECK_AT(parser->input, '\xC2',0)\549 && CHECK_AT(parser->input, '\x85',1)) ?/* NEL -> LF */ \550 (JOIN_OCTET(string, (yaml_char_t) '\n'),\548 (CHECK_AT(parser->input, '\xC2', 0) \ 549 && CHECK_AT(parser->input, '\x85', 1)) ? /* NEL -> LF */ \ 550 (JOIN_OCTET(string, (yaml_char_t) '\n'), \ 551 551 parser->input.pointer += 2, \ 552 552 parser->mark.index ++, \ … … 554 554 parser->mark.line ++, \ 555 555 parser->unread --) : \ 556 (CHECK_AT(parser->input, '\xE2',0) &&\557 CHECK_AT(parser->input, '\x80',1) &&\558 (CHECK_AT(parser->input, '\xA8',2) ||\559 CHECK_AT(parser->input, '\xA9',2))) ?/* LS|PS -> LS|PS */ \560 (COPY_OCTET(string, parser->input),\561 COPY_OCTET(string, parser->input),\562 COPY_OCTET(string, parser->input),\556 (CHECK_AT(parser->input, '\xE2', 0) && \ 557 CHECK_AT(parser->input, '\x80', 1) && \ 558 (CHECK_AT(parser->input, '\xA8', 2) || \ 559 CHECK_AT(parser->input, '\xA9', 2))) ? /* LS|PS -> LS|PS */ \ 560 (COPY_OCTET(string, parser->input), \ 561 COPY_OCTET(string, parser->input), \ 562 COPY_OCTET(string, parser->input), \ 563 563 parser->mark.index ++, \ 564 564 parser->mark.column = 0, \ … … 572 572 573 573 YAML_DECLARE(int) 574 yaml_parser_ scan(yaml_parser_t *parser, yaml_token_t *token);574 yaml_parser_parse_token(yaml_parser_t *parser, yaml_token_t *token); 575 575 576 576 /* … … 709 709 static int 710 710 yaml_parser_scan_uri_escapes(yaml_parser_t *parser, int directive, 711 yaml_mark_t start_mark, yaml_ string_t *string);711 yaml_mark_t start_mark, yaml_ostring_t *string); 712 712 713 713 static int … … 717 717 static int 718 718 yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser, 719 int *indent, yaml_ string_t *breaks,719 int *indent, yaml_ostring_t *breaks, 720 720 yaml_mark_t start_mark, yaml_mark_t *end_mark); 721 721 … … 732 732 733 733 YAML_DECLARE(int) 734 yaml_parser_ scan(yaml_parser_t *parser, yaml_token_t *token)734 yaml_parser_parse_token(yaml_parser_t *parser, yaml_token_t *token) 735 735 { 736 736 assert(parser); /* Non-NULL parser object is expected. */ … … 2093 2093 yaml_mark_t start_mark, yaml_char_t **name) 2094 2094 { 2095 yaml_ string_t string = NULL_STRING;2096 2097 if (! STRING_INIT(parser, string, INITIAL_STRING_CAPACITY))2095 yaml_ostring_t string = NULL_OSTRING; 2096 2097 if (!OSTRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2098 2098 goto error; 2099 2099 … … 2131 2131 2132 2132 error: 2133 STRING_DEL(parser, string);2133 OSTRING_DEL(parser, string); 2134 2134 return 0; 2135 2135 } … … 2312 2312 int length = 0; 2313 2313 yaml_mark_t start_mark, end_mark; 2314 yaml_ string_t string = NULL_STRING;2315 2316 if (! STRING_INIT(parser, string, INITIAL_STRING_CAPACITY))2314 yaml_ostring_t string = NULL_OSTRING; 2315 2316 if (!OSTRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2317 2317 goto error; 2318 2318 … … 2367 2367 2368 2368 error: 2369 STRING_DEL(parser, string);2369 OSTRING_DEL(parser, string); 2370 2370 return 0; 2371 2371 } … … 2496 2496 yaml_mark_t start_mark, yaml_char_t **handle) 2497 2497 { 2498 yaml_ string_t string = NULL_STRING;2499 2500 if (! STRING_INIT(parser, string, INITIAL_STRING_CAPACITY))2498 yaml_ostring_t string = NULL_OSTRING; 2499 2500 if (!OSTRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2501 2501 goto error; 2502 2502 … … 2554 2554 2555 2555 error: 2556 STRING_DEL(parser, string);2556 OSTRING_DEL(parser, string); 2557 2557 return 0; 2558 2558 } … … 2567 2567 { 2568 2568 size_t length = head ? strlen((char *)head) : 0; 2569 yaml_ string_t string = NULL_STRING;2570 2571 if (! STRING_INIT(parser, string, INITIAL_STRING_CAPACITY))2569 yaml_ostring_t string = NULL_OSTRING; 2570 2571 if (!OSTRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2572 2572 goto error; 2573 2573 … … 2575 2575 2576 2576 while (string.capacity <= length) { 2577 if (!yaml_ string_extend(&string.buffer, &string.capacity)) {2577 if (!yaml_ostring_extend(&string.buffer, &string.capacity)) { 2578 2578 MEMORY_ERROR_INIT(parser); 2579 2579 goto error; … … 2633 2633 2634 2634 if (!length) { 2635 if (! STRING_EXTEND(parser, string))2635 if (!OSTRING_EXTEND(parser, string)) 2636 2636 goto error; 2637 2637 … … 2647 2647 2648 2648 error: 2649 STRING_DEL(parser, string);2649 OSTRING_DEL(parser, string); 2650 2650 return 0; 2651 2651 } … … 2657 2657 static int 2658 2658 yaml_parser_scan_uri_escapes(yaml_parser_t *parser, int directive, 2659 yaml_mark_t start_mark, yaml_ string_t *string)2659 yaml_mark_t start_mark, yaml_ostring_t *string) 2660 2660 { 2661 2661 int width = 0; … … 2731 2731 yaml_mark_t start_mark; 2732 2732 yaml_mark_t end_mark; 2733 yaml_ string_t string = NULL_STRING;2734 yaml_ string_t leading_break = NULL_STRING;2735 yaml_ string_t trailing_breaks = NULL_STRING;2733 yaml_ostring_t string = NULL_OSTRING; 2734 yaml_ostring_t leading_break = NULL_OSTRING; 2735 yaml_ostring_t trailing_breaks = NULL_OSTRING; 2736 2736 int chomping = 0; 2737 2737 int increment = 0; … … 2740 2740 int trailing_blank = 0; 2741 2741 2742 if (! STRING_INIT(parser, string, INITIAL_STRING_CAPACITY))2742 if (!OSTRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 2743 2743 goto error; 2744 if (! STRING_INIT(parser, leading_break, INITIAL_STRING_CAPACITY))2744 if (!OSTRING_INIT(parser, leading_break, INITIAL_STRING_CAPACITY)) 2745 2745 goto error; 2746 if (! STRING_INIT(parser, trailing_breaks, INITIAL_STRING_CAPACITY))2746 if (!OSTRING_INIT(parser, trailing_breaks, INITIAL_STRING_CAPACITY)) 2747 2747 goto error; 2748 2748 … … 2881 2881 2882 2882 if (*trailing_breaks.buffer == '\0') { 2883 if (! STRING_EXTEND(parser, string)) goto error;2883 if (!OSTRING_EXTEND(parser, string)) goto error; 2884 2884 JOIN_OCTET(string, ' '); 2885 2885 } … … 2935 2935 start_mark, end_mark); 2936 2936 2937 STRING_DEL(parser, leading_break);2938 STRING_DEL(parser, trailing_breaks);2937 OSTRING_DEL(parser, leading_break); 2938 OSTRING_DEL(parser, trailing_breaks); 2939 2939 2940 2940 return 1; 2941 2941 2942 2942 error: 2943 STRING_DEL(parser, string);2944 STRING_DEL(parser, leading_break);2945 STRING_DEL(parser, trailing_breaks);2943 OSTRING_DEL(parser, string); 2944 OSTRING_DEL(parser, leading_break); 2945 OSTRING_DEL(parser, trailing_breaks); 2946 2946 2947 2947 return 0; … … 2955 2955 static int 2956 2956 yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser, 2957 int *indent, yaml_ string_t *breaks,2957 int *indent, yaml_ostring_t *breaks, 2958 2958 yaml_mark_t start_mark, yaml_mark_t *end_mark) 2959 2959 { … … 3023 3023 yaml_mark_t start_mark; 3024 3024 yaml_mark_t end_mark; 3025 yaml_ string_t string = NULL_STRING;3026 yaml_ string_t leading_break = NULL_STRING;3027 yaml_ string_t trailing_breaks = NULL_STRING;3028 yaml_ string_t whitespaces = NULL_STRING;3025 yaml_ostring_t string = NULL_OSTRING; 3026 yaml_ostring_t leading_break = NULL_OSTRING; 3027 yaml_ostring_t trailing_breaks = NULL_OSTRING; 3028 yaml_ostring_t whitespaces = NULL_OSTRING; 3029 3029 int leading_blanks; 3030 3030 3031 if (! STRING_INIT(parser, string, INITIAL_STRING_CAPACITY))3031 if (!OSTRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 3032 3032 goto error; 3033 if (! STRING_INIT(parser, leading_break, INITIAL_STRING_CAPACITY))3033 if (!OSTRING_INIT(parser, leading_break, INITIAL_STRING_CAPACITY)) 3034 3034 goto error; 3035 if (! STRING_INIT(parser, trailing_breaks, INITIAL_STRING_CAPACITY))3035 if (!OSTRING_INIT(parser, trailing_breaks, INITIAL_STRING_CAPACITY)) 3036 3036 goto error; 3037 if (! STRING_INIT(parser, whitespaces, INITIAL_STRING_CAPACITY))3037 if (!OSTRING_INIT(parser, whitespaces, INITIAL_STRING_CAPACITY)) 3038 3038 goto error; 3039 3039 … … 3089 3089 && CHECK_AT(parser->input, '\'', 1)) 3090 3090 { 3091 if (! STRING_EXTEND(parser, string)) goto error;3091 if (!OSTRING_EXTEND(parser, string)) goto error; 3092 3092 JOIN_OCTET(string, '\''); 3093 3093 SKIP(parser); … … 3120 3120 size_t code_length = 0; 3121 3121 3122 if (! STRING_EXTEND(parser, string)) goto error;3122 if (!OSTRING_EXTEND(parser, string)) goto error; 3123 3123 3124 3124 /* Check the escape character. */ … … 3342 3342 if (leading_break.buffer[0] == '\n') { 3343 3343 if (trailing_breaks.buffer[0] == '\0') { 3344 if (! STRING_EXTEND(parser, string)) goto error;3344 if (!OSTRING_EXTEND(parser, string)) goto error; 3345 3345 JOIN_OCTET(string, ' '); 3346 3346 } … … 3377 3377 start_mark, end_mark); 3378 3378 3379 STRING_DEL(parser, leading_break);3380 STRING_DEL(parser, trailing_breaks);3381 STRING_DEL(parser, whitespaces);3379 OSTRING_DEL(parser, leading_break); 3380 OSTRING_DEL(parser, trailing_breaks); 3381 OSTRING_DEL(parser, whitespaces); 3382 3382 3383 3383 return 1; 3384 3384 3385 3385 error: 3386 STRING_DEL(parser, string);3387 STRING_DEL(parser, leading_break);3388 STRING_DEL(parser, trailing_breaks);3389 STRING_DEL(parser, whitespaces);3386 OSTRING_DEL(parser, string); 3387 OSTRING_DEL(parser, leading_break); 3388 OSTRING_DEL(parser, trailing_breaks); 3389 OSTRING_DEL(parser, whitespaces); 3390 3390 3391 3391 return 0; … … 3401 3401 yaml_mark_t start_mark; 3402 3402 yaml_mark_t end_mark; 3403 yaml_ string_t string = NULL_STRING;3404 yaml_ string_t leading_break = NULL_STRING;3405 yaml_ string_t trailing_breaks = NULL_STRING;3406 yaml_ string_t whitespaces = NULL_STRING;3403 yaml_ostring_t string = NULL_OSTRING; 3404 yaml_ostring_t leading_break = NULL_OSTRING; 3405 yaml_ostring_t trailing_breaks = NULL_OSTRING; 3406 yaml_ostring_t whitespaces = NULL_OSTRING; 3407 3407 int leading_blanks = 0; 3408 3408 int indent = parser->indent+1; 3409 3409 3410 if (! STRING_INIT(parser, string, INITIAL_STRING_CAPACITY))3410 if (!OSTRING_INIT(parser, string, INITIAL_STRING_CAPACITY)) 3411 3411 goto error; 3412 if (! STRING_INIT(parser, leading_break, INITIAL_STRING_CAPACITY))3412 if (!OSTRING_INIT(parser, leading_break, INITIAL_STRING_CAPACITY)) 3413 3413 goto error; 3414 if (! STRING_INIT(parser, trailing_breaks, INITIAL_STRING_CAPACITY))3414 if (!OSTRING_INIT(parser, trailing_breaks, INITIAL_STRING_CAPACITY)) 3415 3415 goto error; 3416 if (! STRING_INIT(parser, whitespaces, INITIAL_STRING_CAPACITY))3416 if (!OSTRING_INIT(parser, whitespaces, INITIAL_STRING_CAPACITY)) 3417 3417 goto error; 3418 3418 … … 3476 3476 if (leading_break.buffer[0] == '\n') { 3477 3477 if (trailing_breaks.buffer[0] == '\0') { 3478 if (! STRING_EXTEND(parser, string)) goto error;3478 if (!OSTRING_EXTEND(parser, string)) goto error; 3479 3479 JOIN_OCTET(string, ' '); 3480 3480 } … … 3580 3580 } 3581 3581 3582 STRING_DEL(parser, leading_break);3583 STRING_DEL(parser, trailing_breaks);3584 STRING_DEL(parser, whitespaces);3582 OSTRING_DEL(parser, leading_break); 3583 OSTRING_DEL(parser, trailing_breaks); 3584 OSTRING_DEL(parser, whitespaces); 3585 3585 3586 3586 return 1; 3587 3587 3588 3588 error: 3589 STRING_DEL(parser, string);3590 STRING_DEL(parser, leading_break);3591 STRING_DEL(parser, trailing_breaks);3592 STRING_DEL(parser, whitespaces);3589 OSTRING_DEL(parser, string); 3590 OSTRING_DEL(parser, leading_break); 3591 OSTRING_DEL(parser, trailing_breaks); 3592 OSTRING_DEL(parser, whitespaces); 3593 3593 3594 3594 return 0; -
libyaml/trunk/src/writer.c
r263 r264 28 28 } 29 29 30 /* Switch the pointer to the beginning of the buffer. */30 /* Switch the buffer into the input mode. */ 31 31 32 emitter->output. capacity= emitter->output.pointer;32 emitter->output.length = emitter->output.pointer; 33 33 emitter->output.pointer = 0; 34 34 … … 38 38 { 39 39 if (emitter->writer(emitter->writer_data, 40 emitter->output.buffer, emitter->output. capacity)) {41 emitter->offset += emitter->output. capacity;42 emitter->output. capacity = OUTPUT_BUFFER_CAPACITY;40 emitter->output.buffer, emitter->output.length)) { 41 emitter->offset += emitter->output.length; 42 emitter->output.length = 0; 43 43 return 1; 44 44 } 45 45 else { 46 return WRITER_ERROR_INIT(emitter, "Write error", emitter->offset); 46 return WRITER_ERROR_INIT(emitter, 47 "write handler error", emitter->offset); 47 48 } 48 49 } … … 53 54 high = (emitter->encoding == YAML_UTF16LE_ENCODING ? 1 : 0); 54 55 55 while (emitter->output.pointer != emitter->output.capacity)56 while (emitter->output.pointer < emitter->output.length) 56 57 { 57 58 unsigned char octet; … … 114 115 emitter->raw_output.buffer, emitter->raw_output.pointer)) { 115 116 emitter->output.pointer = 0; 116 emitter->output. capacity = OUTPUT_BUFFER_CAPACITY;117 emitter->output.length = 0; 117 118 emitter->offset += emitter->raw_output.pointer; 118 119 emitter->raw_output.pointer = 0; … … 120 121 } 121 122 else { 122 return WRITER_ERROR_INIT(emitter, "Write error", emitter->offset); 123 return WRITER_ERROR_INIT(emitter, 124 "write handler error", emitter->offset); 123 125 } 124 126 } -
libyaml/trunk/src/yaml_private.h
r263 r264 29 29 */ 30 30 31 #define ERROR_INIT(error,error_type) \ 32 (memset(&(error), 0, sizeof(error)), \ 33 (error).type = (error_type), \ 31 /* 32 * Generic error initializers; not to be used directly. 33 */ 34 35 #define ERROR_INIT(error, _type) \ 36 (memset(&(error), 0, sizeof(yaml_error_t)), \ 37 (error).type = (_type), \ 34 38 0) 35 39 36 #define READING_ERROR_INIT(error,error_type,error_problem,error_offset,error_value) \ 37 (memset(&(error), 0, sizeof(error)), \ 38 (error).type = (error_type), \ 39 (error).data.reading.problem = (error_problem), \ 40 (error).data.reading.offset = (error_offset), \ 41 (error).data.reading.value = (error_value), \ 40 #define READING_ERROR_INIT(error, _type, _problem, _offset, _value) \ 41 (ERROR_INIT(error, _type), \ 42 (error).data.reading.problem = (_problem), \ 43 (error).data.reading.offset = (_offset), \ 44 (error).data.reading.value = (_value), \ 42 45 0) 43 46 44 #define LOADING_ERROR_INIT(error,error_type,error_problem,error_problem_mark) \ 45 (memset(&(error), 0, sizeof(error)), \ 46 (error).type = (error_type), \ 47 #define LOADING_ERROR_INIT(error, _type, _problem, _problem_mark) \ 48 (ERROR_INIT(error, _type), \ 47 49 (error).data.loading.context = NULL, \ 48 50 (error).data.loading.context_mark.index = 0, \ 49 51 (error).data.loading.context_mark.line = 0, \ 50 52 (error).data.loading.context_mark.column = 0, \ 51 (error).data.loading.problem = ( error_problem),\52 (error).data.loading.problem_mark = ( error_problem_mark),\53 (error).data.loading.problem = (_problem), \ 54 (error).data.loading.problem_mark = (_problem_mark), \ 53 55 0) 54 56 55 #define LOADING_ERROR_WITH_CONTEXT_INIT(error, error_type,error_context,error_context_mark,error_problem,error_problem_mark)\56 (memset(&(error), 0, sizeof(error)),\57 (error).type = (error_type),\58 (error).data.loading.context = ( error_context),\59 (error).data.loading.context_mark = ( error_context_mark),\60 (error).data.loading.problem = ( error_problem),\61 (error).data.loading.problem_mark = ( error_problem_mark),\57 #define LOADING_ERROR_WITH_CONTEXT_INIT(error, _type, _context, _context_mark, \ 58 _problem, _problem_mark) \ 59 (ERROR_INIT(error, _type), \ 60 (error).data.loading.context = (_context), \ 61 (error).data.loading.context_mark = (_context_mark), \ 62 (error).data.loading.problem = (_problem), \ 63 (error).data.loading.problem_mark = (_problem_mark), \ 62 64 0) 63 65 64 #define WRITING_ERROR_INIT(error,error_type,error_problem,error_offset) \ 65 (memset(&(error), 0, sizeof(error)), \ 66 (error).type = (error_type), \ 67 (error).data.writing.problem = (error_problem), \ 68 (error).data.writing.offset = (error_offset), \ 66 #define WRITING_ERROR_INIT(error, _type, _problem, _offset) \ 67 (ERROR_INIT(error, _type), \ 68 (error).data.writing.problem = (_problem), \ 69 (error).data.writing.offset = (_offset), \ 69 70 0) 70 71 71 #define DUMPING_ERROR_INIT(error,error_type,error_problem) \ 72 (memset(&(error), 0, sizeof(error)), \ 73 (error).type = (error_type), \ 74 (error).data.dumping.problem = (error_problem), \ 72 #define DUMPING_ERROR_INIT(error, _type, _problem) \ 73 (ERROR_INIT(error, _type), \ 74 (error).data.dumping.problem = (_problem), \ 75 75 0) 76 76 77 #define RESOLVING_ERROR_INIT(error, _type, _problem) \ 78 (ERROR_INIT(error, _type), \ 79 (error).data.resolving.problem = (_problem), \ 80 0) 81 82 /* 83 * Specific error initializers. 84 */ 85 77 86 #define MEMORY_ERROR_INIT(self) \ 78 ERROR_INIT((self)->error,YAML_MEMORY_ERROR) 79 80 #define READER_ERROR_INIT(self,problem,offset) \ 81 READING_ERROR_INIT((self)->error,YAML_READER_ERROR,problem,offset,-1) 82 83 #define DECODER_ERROR_INIT(self,problem,offset,value) \ 84 READING_ERROR_INIT((self)->error,YAML_DECODER_ERROR,problem,offset,value) 85 86 #define SCANNER_ERROR_INIT(self,problem,problem_mark) \ 87 LOADING_ERROR_INIT((self)->error,YAML_SCANNER_ERROR,problem,problem_mark) 88 89 #define SCANNER_ERROR_WITH_CONTEXT_INIT(self,context,context_mark,problem,problem_mark) \ 90 LOADING_ERROR_WITH_CONTEXT_INIT((self)->error,YAML_SCANNER_ERROR,context,context_mark,problem,problem_mark) 91 92 #define PARSER_ERROR_INIT(self,problem,problem_mark) \ 93 LOADING_ERROR_INIT((self)->error,YAML_PARSER_ERROR,problem,problem_mark) 94 95 #define PARSER_ERROR_WITH_CONTEXT_INIT(self,context,context_mark,problem,problem_mark) \ 96 LOADING_ERROR_WITH_CONTEXT_INIT((self)->error,YAML_PARSER_ERROR,context,context_mark,problem,problem_mark) 97 98 #define COMPOSER_ERROR_INIT(self,problem,problem_mark) \ 99 LOADING_ERROR_INIT((self)->error,YAML_COMPOSER_ERROR,problem,problem_mark) 100 101 #define COMPOSER_ERROR_WITH_CONTEXT_INIT(self,context,context_mark,problem,problem_mark) \ 102 LOADING_ERROR_WITH_CONTEXT_INIT((self)->error,YAML_COMPOSER_ERROR,context,context_mark,problem,problem_mark) 103 104 #define WRITER_ERROR_INIT(self,problem,offset) \ 105 WRITING_ERROR_INIT((self)->error,YAML_WRITER_ERROR,problem,offset) 106 107 #define EMITTER_ERROR_INIT(self,problem) \ 108 DUMPING_ERROR_INIT((self)->error,YAML_EMITTER_ERROR,problem) 109 110 #define SERIALIZER_ERROR_INIT(self,context) \ 111 DUMPING_ERROR_INIT((self)->error,YAML_SERIALIZER_ERROR,problem) 87 ERROR_INIT((self)->error, YAML_MEMORY_ERROR) 88 89 #define READER_ERROR_INIT(self, _problem, _offset) \ 90 READING_ERROR_INIT((self)->error, YAML_READER_ERROR, _problem, _offset, -1) 91 92 #define DECODER_ERROR_INIT(self, _problem, _offset, _value) \ 93 READING_ERROR_INIT((self)->error, YAML_DECODER_ERROR, _problem, _offset, _value) 94 95 #define SCANNER_ERROR_INIT(self, _problem, _problem_mark) \ 96 LOADING_ERROR_INIT((self)->error, YAML_SCANNER_ERROR, _problem, _problem_mark) 97 98 #define SCANNER_ERROR_WITH_CONTEXT_INIT(self, _context, _context_mark, \ 99 _problem, _problem_mark) \ 100 LOADING_ERROR_WITH_CONTEXT_INIT((self)->error, YAML_SCANNER_ERROR, \ 101 _context, _context_mark, _problem, _problem_mark) 102 103 #define PARSER_ERROR_INIT(self, _problem, _problem_mark) \ 104 LOADING_ERROR_INIT((self)->error, YAML_PARSER_ERROR, _problem, _problem_mark) 105 106 #define PARSER_ERROR_WITH_CONTEXT_INIT(self, _context, _context_mark, \ 107 _problem, _problem_mark) \ 108 LOADING_ERROR_WITH_CONTEXT_INIT((self)->error, YAML_PARSER_ERROR, \ 109 _context, _context_mark, _problem, _problem_mark) 110 111 #define COMPOSER_ERROR_INIT(self, _problem, _problem_mark) \ 112 LOADING_ERROR_INIT((self)->error, YAML_COMPOSER_ERROR, _problem, _problem_mark) 113 114 #define COMPOSER_ERROR_WITH_CONTEXT_INIT(self, _context, _context_mark, \ 115 _problem, _problem_mark) \ 116 LOADING_ERROR_WITH_CONTEXT_INIT((self)->error, YAML_COMPOSER_ERROR, \ 117 _context, _context_mark, _problem, _problem_mark) 118 119 #define WRITER_ERROR_INIT(self, _problem, _offset) \ 120 WRITING_ERROR_INIT((self)->error, YAML_WRITER_ERROR, _problem, _offset) 121 122 #define EMITTER_ERROR_INIT(self, _problem) \ 123 DUMPING_ERROR_INIT((self)->error, YAML_EMITTER_ERROR, _problem) 124 125 #define SERIALIZER_ERROR_INIT(self, _problem) \ 126 DUMPING_ERROR_INIT((self)->error, YAML_SERIALIZER_ERROR, _problem) 127 128 #define RESOLVER_ERROR_INIT(self, _problem) \ 129 RESOLVER_ERROR_INIT((self)->error, YAML_RESOLVER_ERROR, _problem) 112 130 113 131 /* … … 153 171 */ 154 172 155 typedef struct yaml_string_s { 173 /* 174 * An immutable string used as an input buffer. 175 */ 176 177 typedef struct yaml_istring_s { 178 const yaml_char_t *buffer; 179 size_t pointer; 180 size_t length; 181 } yaml_istring_t; 182 183 /* 184 * A string that is used as an output buffer. 185 */ 186 187 typedef struct yaml_ostring_s { 156 188 yaml_char_t *buffer; 157 189 size_t pointer; 158 190 size_t capacity; 159 } yaml_string_t; 191 } yaml_ostring_t; 192 193 /* 194 * A string that could be used both as an input and an output buffer. 195 */ 196 197 typedef struct yaml_iostring_s { 198 yaml_char_t *buffer; 199 size_t pointer; 200 size_t length; 201 size_t capacity; 202 } yaml_iostring_t; 203 204 /* 205 * Separate type for non-UTF-8 i/o strings. 206 */ 207 208 typedef struct yaml_raw_iostring_s { 209 unsigned char *buffer; 210 size_t pointer; 211 size_t length; 212 size_t capacity; 213 } yaml_raw_iostring_t; 160 214 161 215 YAML_DECLARE(int) 162 yaml_ string_extend(yaml_char_t **buffer, size_t *capacity);216 yaml_ostring_extend(yaml_char_t **buffer, size_t *capacity); 163 217 164 218 YAML_DECLARE(int) 165 yaml_ string_join(219 yaml_ostring_join( 166 220 yaml_char_t **base_buffer, size_t *base_pointer, size_t *base_capacity, 167 yaml_char_t *adj_buffer, size_t adj_pointer , size_t adj_capacity);168 169 #define NULL_STRING { NULL, 0, 0}170 171 #define STRING(string,capacity) { (string), 0, (capacity)}172 173 #define STRING_INIT(self,string,string_capacity)\174 (((string).buffer = yaml_malloc( string_capacity)) ?\175 ((string).pointer = 0,\176 (string).capacity = ( string_capacity),\177 memset((string).buffer, 0, ( string_capacity)),\221 yaml_char_t *adj_buffer, size_t adj_pointer); 222 223 #define ISTRING(buffer, length) { (buffer), 0, (length) } 224 225 #define NULL_OSTRING { NULL, 0, 0 } 226 227 #define IOSTRING_INIT(self, string, _capacity) \ 228 (((string).buffer = yaml_malloc(_capacity)) ? \ 229 ((string).pointer = (string).length = 0, \ 230 (string).capacity = (_capacity), \ 231 memset((string).buffer, 0, (_capacity)), \ 178 232 1) : \ 179 233 ((self)->error.type = YAML_MEMORY_ERROR, \ 180 234 0)) 181 235 182 #define STRING_DEL(self,string) \ 236 #define IOSTRING_DEL(self, string) \ 237 (yaml_free((string).buffer), \ 238 (string).buffer = NULL, \ 239 ((string).pointer = (string).length = (string).capacity = 0)) 240 241 #define OSTRING_INIT(self, string, _capacity) \ 242 (((string).buffer = yaml_malloc(_capacity)) ? \ 243 ((string).pointer = 0, \ 244 (string).capacity = (_capacity), \ 245 memset((string).buffer, 0, (_capacity)), \ 246 1) : \ 247 ((self)->error.type = YAML_MEMORY_ERROR, \ 248 0)) 249 250 #define OSTRING_DEL(self, string) \ 183 251 (yaml_free((string).buffer), \ 184 252 (string).buffer = NULL, \ 185 253 ((string).pointer = (string).capacity = 0)) 186 254 187 #define STRING_EXTEND(self,string)\255 #define OSTRING_EXTEND(self, string) \ 188 256 ((((string).pointer+5 < (string).capacity) \ 189 || yaml_ string_extend(&(string).buffer, &(string).capacity)) ?\257 || yaml_ostring_extend(&(string).buffer, &(string).capacity)) ? \ 190 258 1 : \ 191 259 ((self)->error.type = YAML_MEMORY_ERROR, \ 192 260 0)) 193 261 194 #define CLEAR(self, string)\262 #define CLEAR(self, string) \ 195 263 ((string).pointer = 0, \ 196 264 memset((string).buffer, 0, (string).capacity)) 197 265 198 #define JOIN(self, base_string,adj_string)\199 ((yaml_ string_join(&(base_string).buffer, &(base_string).pointer,\200 &(base_string).capacity, (adj_string).buffer,\201 (adj_string). pointer, (adj_string).capacity)) ?\266 #define JOIN(self, base_string, adj_string) \ 267 ((yaml_ostring_join(&(base_string).buffer, &(base_string).pointer, \ 268 &(base_string).capacity, \ 269 (adj_string).buffer, (adj_string).pointer)) ? \ 202 270 ((adj_string).pointer = 0, \ 203 271 1) : \ … … 213 281 */ 214 282 215 #define OCTET_AT(string, offset)\283 #define OCTET_AT(string, offset) \ 216 284 ((string).buffer[(string).pointer+(offset)]) 217 285 … … 220 288 */ 221 289 222 #define OCTET(string) OCTET_AT((string), 0)290 #define OCTET(string) OCTET_AT((string), 0) 223 291 224 292 /* … … 226 294 */ 227 295 228 #define CHECK_AT(string, octet,offset)\229 (OCTET_AT((string), (offset)) == (yaml_char_t)(octet))296 #define CHECK_AT(string, octet, offset) \ 297 (OCTET_AT((string), (offset)) == (yaml_char_t)(octet)) 230 298 231 299 /* … … 233 301 */ 234 302 235 #define CHECK(string, octet) CHECK_AT((string),(octet),0)303 #define CHECK(string, octet) CHECK_AT((string), (octet), 0) 236 304 237 305 /* … … 240 308 */ 241 309 242 #define IS_ALPHA_AT(string, offset)\243 ((OCTET_AT((string), (offset)) >= (yaml_char_t) '0' &&\244 OCTET_AT((string), (offset)) <= (yaml_char_t) '9') ||\245 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'A' &&\246 OCTET_AT((string), (offset)) <= (yaml_char_t) 'Z') ||\247 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'a' &&\248 OCTET_AT((string), (offset)) <= (yaml_char_t) 'z') ||\249 OCTET_AT((string), (offset)) == '_' ||\250 OCTET_AT((string), (offset)) == '-')251 252 #define IS_ALPHA(string) IS_ALPHA_AT((string), 0)310 #define IS_ALPHA_AT(string, offset) \ 311 ((OCTET_AT((string), (offset)) >= (yaml_char_t) '0' && \ 312 OCTET_AT((string), (offset)) <= (yaml_char_t) '9') || \ 313 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'A' && \ 314 OCTET_AT((string), (offset)) <= (yaml_char_t) 'Z') || \ 315 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'a' && \ 316 OCTET_AT((string), (offset)) <= (yaml_char_t) 'z') || \ 317 OCTET_AT((string), (offset)) == '_' || \ 318 OCTET_AT((string), (offset)) == '-') 319 320 #define IS_ALPHA(string) IS_ALPHA_AT((string), 0) 253 321 254 322 /* … … 256 324 */ 257 325 258 #define IS_DIGIT_AT(string, offset)\259 ((OCTET_AT((string), (offset)) >= (yaml_char_t) '0' &&\260 OCTET_AT((string), (offset)) <= (yaml_char_t) '9'))261 262 #define IS_DIGIT(string) IS_DIGIT_AT((string), 0)326 #define IS_DIGIT_AT(string, offset) \ 327 ((OCTET_AT((string), (offset)) >= (yaml_char_t) '0' && \ 328 OCTET_AT((string), (offset)) <= (yaml_char_t) '9')) 329 330 #define IS_DIGIT(string) IS_DIGIT_AT((string), 0) 263 331 264 332 /* … … 266 334 */ 267 335 268 #define AS_DIGIT_AT(string, offset)\269 (OCTET_AT((string), (offset)) - (yaml_char_t) '0')270 271 #define AS_DIGIT(string) AS_DIGIT_AT((string), 0)336 #define AS_DIGIT_AT(string, offset) \ 337 (OCTET_AT((string), (offset)) - (yaml_char_t) '0') 338 339 #define AS_DIGIT(string) AS_DIGIT_AT((string), 0) 272 340 273 341 /* … … 275 343 */ 276 344 277 #define IS_HEX_AT(string, offset)\278 ((OCTET_AT((string), (offset)) >= (yaml_char_t) '0' &&\279 OCTET_AT((string), (offset)) <= (yaml_char_t) '9') ||\280 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'A' &&\281 OCTET_AT((string), (offset)) <= (yaml_char_t) 'F') ||\282 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'a' &&\283 OCTET_AT((string), (offset)) <= (yaml_char_t) 'f'))284 285 #define IS_HEX(string) IS_HEX_AT((string), 0)345 #define IS_HEX_AT(string, offset) \ 346 ((OCTET_AT((string), (offset)) >= (yaml_char_t) '0' && \ 347 OCTET_AT((string), (offset)) <= (yaml_char_t) '9') || \ 348 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'A' && \ 349 OCTET_AT((string), (offset)) <= (yaml_char_t) 'F') || \ 350 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'a' && \ 351 OCTET_AT((string), (offset)) <= (yaml_char_t) 'f')) 352 353 #define IS_HEX(string) IS_HEX_AT((string), 0) 286 354 287 355 /* … … 289 357 */ 290 358 291 #define AS_HEX_AT(string, offset)\292 ((OCTET_AT((string), (offset)) >= (yaml_char_t) 'A' &&\293 OCTET_AT((string), (offset)) <= (yaml_char_t) 'F') ?\294 (OCTET_AT((string), (offset)) - (yaml_char_t) 'A' + 10) :\295 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'a' &&\296 OCTET_AT((string), (offset)) <= (yaml_char_t) 'f') ?\297 (OCTET_AT((string), (offset)) - (yaml_char_t) 'a' + 10) :\298 (OCTET_AT((string), (offset)) - (yaml_char_t) '0'))359 #define AS_HEX_AT(string, offset) \ 360 ((OCTET_AT((string), (offset)) >= (yaml_char_t) 'A' && \ 361 OCTET_AT((string), (offset)) <= (yaml_char_t) 'F') ? \ 362 (OCTET_AT((string), (offset)) - (yaml_char_t) 'A' + 10) : \ 363 (OCTET_AT((string), (offset)) >= (yaml_char_t) 'a' && \ 364 OCTET_AT((string), (offset)) <= (yaml_char_t) 'f') ? \ 365 (OCTET_AT((string), (offset)) - (yaml_char_t) 'a' + 10) : \ 366 (OCTET_AT((string), (offset)) - (yaml_char_t) '0')) 299 367 300 #define AS_HEX(string) AS_HEX_AT((string), 0)368 #define AS_HEX(string) AS_HEX_AT((string), 0) 301 369 302 370 /* … … 304 372 */ 305 373 306 #define IS_ASCII_AT(string, offset)\307 (OCTET_AT((string), (offset)) <= (yaml_char_t) '\x7F')308 309 #define IS_ASCII(string) IS_ASCII_AT((string), 0)374 #define IS_ASCII_AT(string, offset) \ 375 (OCTET_AT((string), (offset)) <= (yaml_char_t) '\x7F') 376 377 #define IS_ASCII(string) IS_ASCII_AT((string), 0) 310 378 311 379 /* … … 313 381 */ 314 382 315 #define IS_PRINTABLE_AT(string, offset)\316 ((OCTET_AT((string), (offset)) == 0x0A)/* . == #x0A */ \317 || (OCTET_AT((string), (offset)) >= 0x20/* #x20 <= . <= #x7E */ \318 && OCTET_AT((string), (offset)) <= 0x7E)\319 || (OCTET_AT((string), (offset)) == 0xC2/* #0xA0 <= . <= #xD7FF */ \320 && OCTET_AT((string), (offset)+1) >= 0xA0)\321 || (OCTET_AT((string), (offset)) > 0xC2\322 && OCTET_AT((string), (offset)) < 0xED)\323 || (OCTET_AT((string), (offset)) == 0xED\324 && OCTET_AT((string), (offset)+1) < 0xA0)\325 || (OCTET_AT((string), (offset)) == 0xEE)\326 || (OCTET_AT((string), (offset)) == 0xEF/* #xE000 <= . <= #xFFFD */ \327 && !(OCTET_AT((string), (offset)+1) == 0xBB/* && . != #xFEFF */ \328 && OCTET_AT((string), (offset)+2) == 0xBF)\329 && !(OCTET_AT((string), (offset)+1) == 0xBF\330 && (OCTET_AT((string), (offset)+2) == 0xBE\331 || OCTET_AT((string), (offset)+2) == 0xBF))))332 333 #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string), 0)383 #define IS_PRINTABLE_AT(string, offset) \ 384 ((OCTET_AT((string), (offset)) == 0x0A) /* . == #x0A */ \ 385 || (OCTET_AT((string), (offset)) >= 0x20 /* #x20 <= . <= #x7E */ \ 386 && OCTET_AT((string), (offset)) <= 0x7E) \ 387 || (OCTET_AT((string), (offset)) == 0xC2 /* #0xA0 <= . <= #xD7FF */ \ 388 && OCTET_AT((string), (offset)+1) >= 0xA0) \ 389 || (OCTET_AT((string), (offset)) > 0xC2 \ 390 && OCTET_AT((string), (offset)) < 0xED) \ 391 || (OCTET_AT((string), (offset)) == 0xED \ 392 && OCTET_AT((string), (offset)+1) < 0xA0) \ 393 || (OCTET_AT((string), (offset)) == 0xEE) \ 394 || (OCTET_AT((string), (offset)) == 0xEF /* #xE000 <= . <= #xFFFD */ \ 395 && !(OCTET_AT((string), (offset)+1) == 0xBB /* && . != #xFEFF */ \ 396 && OCTET_AT((string), (offset)+2) == 0xBF) \ 397 && !(OCTET_AT((string), (offset)+1) == 0xBF \ 398 && (OCTET_AT((string), (offset)+2) == 0xBE \ 399 || OCTET_AT((string), (offset)+2) == 0xBF)))) 400 401 #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string), 0) 334 402 335 403 /* … … 337 405 */ 338 406 339 #define IS_Z_AT(string, offset) CHECK_AT((string),'\0',(offset))340 341 #define IS_Z(string) IS_Z_AT((string), 0)407 #define IS_Z_AT(string, offset) CHECK_AT((string), '\0', (offset)) 408 409 #define IS_Z(string) IS_Z_AT((string), 0) 342 410 343 411 /* … … 345 413 */ 346 414 347 #define IS_BOM_AT(string, offset)\348 (CHECK_AT((string), '\xEF',(offset))\349 && CHECK_AT((string), '\xBB',(offset)+1)\350 && CHECK_AT((string), '\xBF',(offset)+2))/* BOM (#xFEFF) */351 352 #define IS_BOM(string) IS_BOM_AT(string, 0)415 #define IS_BOM_AT(string, offset) \ 416 (CHECK_AT((string), '\xEF', (offset)) \ 417 && CHECK_AT((string), '\xBB', (offset)+1) \ 418 && CHECK_AT((string), '\xBF', (offset)+2)) /* BOM (#xFEFF) */ 419 420 #define IS_BOM(string) IS_BOM_AT(string, 0) 353 421 354 422 /* … … 356 424 */ 357 425 358 #define IS_SPACE_AT(string, offset) CHECK_AT((string),' ',(offset))359 360 #define IS_SPACE(string) IS_SPACE_AT((string), 0)426 #define IS_SPACE_AT(string, offset) CHECK_AT((string), ' ', (offset)) 427 428 #define IS_SPACE(string) IS_SPACE_AT((string), 0) 361 429 362 430 /* … … 364 432 */ 365 433 366 #define IS_TAB_AT(string, offset) CHECK_AT((string),'\t',(offset))367 368 #define IS_TAB(string) IS_TAB_AT((string), 0)434 #define IS_TAB_AT(string, offset) CHECK_AT((string), '\t', (offset)) 435 436 #define IS_TAB(string) IS_TAB_AT((string), 0) 369 437 370 438 /* … … 372 440 */ 373 441 374 #define IS_BLANK_AT(string, offset)\375 (IS_SPACE_AT((string), (offset)) || IS_TAB_AT((string),(offset)))376 377 #define IS_BLANK(string) IS_BLANK_AT((string), 0)442 #define IS_BLANK_AT(string, offset) \ 443 (IS_SPACE_AT((string), (offset)) || IS_TAB_AT((string), (offset))) 444 445 #define IS_BLANK(string) IS_BLANK_AT((string), 0) 378 446 379 447 /* … … 381 449 */ 382 450 383 #define IS_BREAK_AT(string, offset)\384 (CHECK_AT((string), '\r',(offset)) /* CR (#xD)*/\385 || CHECK_AT((string), '\n',(offset)) /* LF (#xA) */\386 || (CHECK_AT((string), '\xC2',(offset))\387 && CHECK_AT((string), '\x85',(offset)+1)) /* NEL (#x85) */\388 || (CHECK_AT((string), '\xE2',(offset))\389 && CHECK_AT((string), '\x80',(offset)+1)\390 && CHECK_AT((string), '\xA8',(offset)+2)) /* LS (#x2028) */\391 || (CHECK_AT((string), '\xE2',(offset))\392 && CHECK_AT((string), '\x80',(offset)+1)\393 && CHECK_AT((string), '\xA9',(offset)+2)))/* PS (#x2029) */394 395 #define IS_BREAK(string) IS_BREAK_AT((string), 0)396 397 #define IS_CRLF_AT(string, offset)\398 (CHECK_AT((string), '\r',(offset)) && CHECK_AT((string),'\n',(offset)+1))399 400 #define IS_CRLF(string) IS_CRLF_AT((string), 0)451 #define IS_BREAK_AT(string, offset) \ 452 (CHECK_AT((string), '\r', (offset)) /* CR (#xD)*/ \ 453 || CHECK_AT((string), '\n', (offset)) /* LF (#xA) */ \ 454 || (CHECK_AT((string), '\xC2', (offset)) \ 455 && CHECK_AT((string), '\x85', (offset)+1)) /* NEL (#x85) */ \ 456 || (CHECK_AT((string), '\xE2', (offset)) \ 457 && CHECK_AT((string), '\x80', (offset)+1) \ 458 && CHECK_AT((string), '\xA8', (offset)+2)) /* LS (#x2028) */ \ 459 || (CHECK_AT((string), '\xE2', (offset)) \ 460 && CHECK_AT((string), '\x80', (offset)+1) \ 461 && CHECK_AT((string), '\xA9', (offset)+2))) /* PS (#x2029) */ 462 463 #define IS_BREAK(string) IS_BREAK_AT((string), 0) 464 465 #define IS_CRLF_AT(string, offset) \ 466 (CHECK_AT((string), '\r', (offset)) && CHECK_AT((string), '\n', (offset)+1)) 467 468 #define IS_CRLF(string) IS_CRLF_AT((string), 0) 401 469 402 470 /* … … 404 472 */ 405 473 406 #define IS_BREAKZ_AT(string, offset)\407 (IS_BREAK_AT((string), (offset)) || IS_Z_AT((string),(offset)))408 409 #define IS_BREAKZ(string) IS_BREAKZ_AT((string), 0)474 #define IS_BREAKZ_AT(string, offset) \ 475 (IS_BREAK_AT((string), (offset)) || IS_Z_AT((string), (offset))) 476 477 #define IS_BREAKZ(string) IS_BREAKZ_AT((string), 0) 410 478 411 479 /* … … 413 481 */ 414 482 415 #define IS_SPACEZ_AT(string, offset)\416 (IS_SPACE_AT((string), (offset)) || IS_BREAKZ_AT((string),(offset)))417 418 #define IS_SPACEZ(string) IS_SPACEZ_AT((string), 0)483 #define IS_SPACEZ_AT(string, offset) \ 484 (IS_SPACE_AT((string), (offset)) || IS_BREAKZ_AT((string), (offset))) 485 486 #define IS_SPACEZ(string) IS_SPACEZ_AT((string), 0) 419 487 420 488 /* … … 422 490 */ 423 491 424 #define IS_BLANKZ_AT(string, offset)\425 (IS_BLANK_AT((string), (offset)) || IS_BREAKZ_AT((string),(offset)))426 427 #define IS_BLANKZ(string) IS_BLANKZ_AT((string), 0)492 #define IS_BLANKZ_AT(string, offset) \ 493 (IS_BLANK_AT((string), (offset)) || IS_BREAKZ_AT((string), (offset))) 494 495 #define IS_BLANKZ(string) IS_BLANKZ_AT((string), 0) 428 496 429 497 /* … … 431 499 */ 432 500 433 #define WIDTH_AT(string, offset)\434 ((OCTET_AT((string), (offset)) & 0x80) == 0x00 ? 1 :\435 (OCTET_AT((string), (offset)) & 0xE0) == 0xC0 ? 2 :\436 (OCTET_AT((string), (offset)) & 0xF0) == 0xE0 ? 3 :\437 (OCTET_AT((string), (offset)) & 0xF8) == 0xF0 ? 4 : 0)438 439 #define WIDTH(string) WIDTH_AT((string), 0)501 #define WIDTH_AT(string, offset) \ 502 ((OCTET_AT((string), (offset)) & 0x80) == 0x00 ? 1 : \ 503 (OCTET_AT((string), (offset)) & 0xE0) == 0xC0 ? 2 : \ 504 (OCTET_AT((string), (offset)) & 0xF0) == 0xE0 ? 3 : \ 505 (OCTET_AT((string), (offset)) & 0xF8) == 0xF0 ? 4 : 0) 506 507 #define WIDTH(string) WIDTH_AT((string), 0) 440 508 441 509 /* … … 449 517 */ 450 518 451 #define JOIN_OCTET(string, octet)\519 #define JOIN_OCTET(string, octet) \ 452 520 ((string).buffer[(string).pointer++] = (octet)) 453 521 … … 456 524 */ 457 525 458 #define COPY_OCTET( string_a,string_b)\459 (( string_a).buffer[(string_a).pointer++]\460 = (s tring_b).buffer[(string_b).pointer++])526 #define COPY_OCTET(target_string, source_string) \ 527 ((target_string).buffer[(target_string).pointer++] \ 528 = (source_string).buffer[(source_string).pointer++]) 461 529 462 530 /* … … 464 532 */ 465 533 466 #define COPY( string_a,string_b)\467 ((OCTET(s tring_b) & 0x80) == 0x00 ?\468 COPY_OCTET(( string_a),(string_b)) :\469 (OCTET(s tring_b) & 0xE0) == 0xC0 ?\470 (COPY_OCTET(( string_a),(string_b)),\471 COPY_OCTET(( string_a),(string_b))) :\472 (OCTET(s tring_b) & 0xF0) == 0xE0 ?\473 (COPY_OCTET(( string_a),(string_b)),\474 COPY_OCTET(( string_a),(string_b)),\475 COPY_OCTET(( string_a),(string_b))) :\476 (OCTET(s tring_b) & 0xF8) == 0xF0 ?\477 (COPY_OCTET(( string_a),(string_b)),\478 COPY_OCTET(( string_a),(string_b)),\479 COPY_OCTET(( string_a),(string_b)),\480 COPY_OCTET(( string_a),(string_b))) : 0) \534 #define COPY(target_string, source_string) \ 535 ((OCTET(source_string) & 0x80) == 0x00 ? \ 536 COPY_OCTET((target_string), (source_string)) : \ 537 (OCTET(source_string) & 0xE0) == 0xC0 ? \ 538 (COPY_OCTET((target_string), (source_string)), \ 539 COPY_OCTET((target_string), (source_string))) : \ 540 (OCTET(source_string) & 0xF0) == 0xE0 ? \ 541 (COPY_OCTET((target_string), (source_string)), \ 542 COPY_OCTET((target_string), (source_string)), \ 543 COPY_OCTET((target_string), (source_string))) : \ 544 (OCTET(source_string) & 0xF8) == 0xF0 ? \ 545 (COPY_OCTET((target_string), (source_string)), \ 546 COPY_OCTET((target_string), (source_string)), \ 547 COPY_OCTET((target_string), (source_string)), \ 548 COPY_OCTET((target_string), (source_string))) : 0) 481 549 482 550 /* … … 491 559 size_t *head, size_t *tail, size_t *capacity); 492 560 493 #define STACK_INIT(self, stack,stack_capacity)\494 (((stack).list = yaml_malloc(( stack_capacity)*sizeof(*(stack).list))) ?\561 #define STACK_INIT(self, stack, _capacity) \ 562 (((stack).list = yaml_malloc((_capacity)*sizeof(*(stack).list))) ? \ 495 563 ((stack).length = 0, \ 496 (stack).capacity = ( stack_capacity),\564 (stack).capacity = (_capacity), \ 497 565 1) : \ 498 566 ((self)->error.type = YAML_MEMORY_ERROR, \ 499 567 0)) 500 568 501 #define STACK_DEL(self, stack)\569 #define STACK_DEL(self, stack) \ 502 570 (yaml_free((stack).list), \ 503 571 (stack).list = NULL, \ 504 572 (stack).length = (stack).capacity = 0) 505 573 506 #define STACK_EMPTY(self, stack)\574 #define STACK_EMPTY(self, stack) \ 507 575 ((stack).length == 0) 508 576 509 #define PUSH(self,stack,value) \ 577 #define STACK_ITER(self, stack, index) \ 578 ((stack).list + index) 579 580 #define PUSH(self, stack, value) \ 510 581 (((stack).length < (stack).capacity \ 511 582 || yaml_stack_extend((void **)&(stack).list, sizeof(*(stack).list), \ … … 516 587 0)) 517 588 518 #define POP(self, stack)\589 #define POP(self, stack) \ 519 590 ((stack).list[--(stack).length]) 520 591 521 #define QUEUE_INIT(self, queue,queue_capacity)\522 (((queue).list = yaml_malloc(( queue_capacity)*sizeof(*(queue).list))) ?\592 #define QUEUE_INIT(self, queue, _capacity) \ 593 (((queue).list = yaml_malloc((_capacity)*sizeof(*(queue).list))) ? \ 523 594 ((queue).head = (queue).tail = 0, \ 524 (queue).capacity = ( queue_capacity),\595 (queue).capacity = (_capacity), \ 525 596 1) : \ 526 597 ((self)->error.type = YAML_MEMORY_ERROR, \ 527 598 0)) 528 599 529 #define QUEUE_DEL(self, queue)\600 #define QUEUE_DEL(self, queue) \ 530 601 (yaml_free((queue).list), \ 531 602 (queue).list = NULL, \ 532 603 (queue).head = (queue).tail = (queue).capacity = 0) 533 604 534 #define QUEUE_EMPTY(self, queue)\605 #define QUEUE_EMPTY(self, queue) \ 535 606 ((queue).head == (queue).tail) 536 607 537 #define ENQUEUE(self,queue,value) \ 608 #define QUEUE_ITER(self, queue, index) \ 609 ((queue).list + (queue).head + index) 610 611 #define ENQUEUE(self, queue, value) \ 538 612 (((queue).tail != (queue).capacity \ 539 613 || yaml_queue_extend((void **)&(queue).list, sizeof(*(queue).list), \ … … 544 618 0)) 545 619 546 #define DEQUEUE(self, queue)\620 #define DEQUEUE(self, queue) \ 547 621 ((queue).list[(queue).head++]) 548 622 549 #define QUEUE_INSERT(self, queue,index,value)\623 #define QUEUE_INSERT(self, queue, index, value) \ 550 624 (((queue).tail != (queue).capacity \ 551 625 || yaml_queue_extend((void **)&(queue).list, sizeof(*(queue).list), \ … … 564 638 */ 565 639 566 #define TOKEN_INIT(token, token_type,token_start_mark,token_end_mark)\640 #define TOKEN_INIT(token, _type, _start_mark, _end_mark) \ 567 641 (memset(&(token), 0, sizeof(yaml_token_t)), \ 568 (token).type = ( token_type),\569 (token).start_mark = ( token_start_mark),\570 (token).end_mark = ( token_end_mark))571 572 #define STREAM_START_TOKEN_INIT(token, token_encoding,start_mark,end_mark) \573 (TOKEN_INIT((token), YAML_STREAM_START_TOKEN,(start_mark),(end_mark)),\574 (token).data.stream_start.encoding = ( token_encoding))575 576 #define STREAM_END_TOKEN_INIT(token, start_mark,end_mark)\577 (TOKEN_INIT((token), YAML_STREAM_END_TOKEN,(start_mark),(end_mark)))578 579 #define ALIAS_TOKEN_INIT(token, token_value,start_mark,end_mark) \580 (TOKEN_INIT((token), YAML_ALIAS_TOKEN,(start_mark),(end_mark)),\581 (token).data.alias.value = ( token_value))582 583 #define ANCHOR_TOKEN_INIT(token, token_value,start_mark,end_mark) \584 (TOKEN_INIT((token), YAML_ANCHOR_TOKEN,(start_mark),(end_mark)),\585 (token).data.anchor.value = ( token_value))586 587 #define TAG_TOKEN_INIT(token, token_handle,token_suffix,start_mark,end_mark)\588 (TOKEN_INIT((token), YAML_TAG_TOKEN,(start_mark),(end_mark)),\589 (token).data.tag.handle = ( token_handle),\590 (token).data.tag.suffix = ( token_suffix))591 592 #define SCALAR_TOKEN_INIT(token, token_value,token_length,token_style,start_mark,end_mark) \593 (TOKEN_INIT((token), YAML_SCALAR_TOKEN,(start_mark),(end_mark)),\594 (token).data.scalar.value = ( token_value),\595 (token).data.scalar.length = ( token_length),\596 (token).data.scalar.style = ( token_style))597 598 #define VERSION_DIRECTIVE_TOKEN_INIT(token, token_major,token_minor,start_mark,end_mark)\599 (TOKEN_INIT((token), YAML_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)),\600 (token).data.version_directive.major = ( token_major),\601 (token).data.version_directive.minor = ( token_minor))602 603 #define TAG_DIRECTIVE_TOKEN_INIT(token, token_handle,token_prefix,start_mark,end_mark)\604 (TOKEN_INIT((token), YAML_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)),\605 (token).data.tag_directive.handle = ( token_handle),\606 (token).data.tag_directive.prefix = ( token_prefix))642 (token).type = (_type), \ 643 (token).start_mark = (_start_mark), \ 644 (token).end_mark = (_end_mark)) 645 646 #define STREAM_START_TOKEN_INIT(token, _encoding, _start_mark, _end_mark) \ 647 (TOKEN_INIT((token), YAML_STREAM_START_TOKEN, (_start_mark), (_end_mark)), \ 648 (token).data.stream_start.encoding = (_encoding)) 649 650 #define STREAM_END_TOKEN_INIT(token, _start_mark, _end_mark) \ 651 (TOKEN_INIT((token), YAML_STREAM_END_TOKEN, (_start_mark), (_end_mark))) 652 653 #define ALIAS_TOKEN_INIT(token, _value, _start_mark, _end_mark) \ 654 (TOKEN_INIT((token), YAML_ALIAS_TOKEN, (_start_mark), (_end_mark)), \ 655 (token).data.alias.value = (_value)) 656 657 #define ANCHOR_TOKEN_INIT(token, _value, _start_mark, _end_mark) \ 658 (TOKEN_INIT((token), YAML_ANCHOR_TOKEN, (_start_mark), (_end_mark)), \ 659 (token).data.anchor.value = (_value)) 660 661 #define TAG_TOKEN_INIT(token, _handle, _suffix, _start_mark, _end_mark) \ 662 (TOKEN_INIT((token), YAML_TAG_TOKEN, (_start_mark), (_end_mark)), \ 663 (token).data.tag.handle = (_handle), \ 664 (token).data.tag.suffix = (_suffix)) 665 666 #define SCALAR_TOKEN_INIT(token, _value, _length, _style, _start_mark, _end_mark) \ 667 (TOKEN_INIT((token), YAML_SCALAR_TOKEN, (_start_mark), (_end_mark)), \ 668 (token).data.scalar.value = (_value), \ 669 (token).data.scalar.length = (_length), \ 670 (token).data.scalar.style = (_style)) 671 672 #define VERSION_DIRECTIVE_TOKEN_INIT(token, _major, _minor, _start_mark, _end_mark) \ 673 (TOKEN_INIT((token), YAML_VERSION_DIRECTIVE_TOKEN, (_start_mark), (_end_mark)), \ 674 (token).data.version_directive.major = (_major), \ 675 (token).data.version_directive.minor = (_minor)) 676 677 #define TAG_DIRECTIVE_TOKEN_INIT(token, _handle, _prefix, _start_mark, _end_mark) \ 678 (TOKEN_INIT((token), YAML_TAG_DIRECTIVE_TOKEN, (_start_mark), (_end_mark)), \ 679 (token).data.tag_directive.handle = (_handle), \ 680 (token).data.tag_directive.prefix = (_prefix)) 607 681 608 682 /* … … 610 684 */ 611 685 612 #define EVENT_INIT(event, event_type,event_start_mark,event_end_mark)\686 #define EVENT_INIT(event, _type, _start_mark, _end_mark) \ 613 687 (memset(&(event), 0, sizeof(yaml_event_t)), \ 614 (event).type = (event_type), \ 615 (event).start_mark = (event_start_mark), \ 616 (event).end_mark = (event_end_mark)) 617 618 #define STREAM_START_EVENT_INIT(event,event_encoding,start_mark,end_mark) \ 619 (EVENT_INIT((event),YAML_STREAM_START_EVENT,(start_mark),(end_mark)), \ 620 (event).data.stream_start.encoding = (event_encoding)) 621 622 #define STREAM_END_EVENT_INIT(event,start_mark,end_mark) \ 623 (EVENT_INIT((event),YAML_STREAM_END_EVENT,(start_mark),(end_mark))) 624 625 #define DOCUMENT_START_EVENT_INIT(event,event_version_directive, \ 626 event_tag_directives_list,event_tag_directives_length, \ 627 event_tag_directives_capacity,event_is_implicit,start_mark,end_mark) \ 628 (EVENT_INIT((event),YAML_DOCUMENT_START_EVENT,(start_mark),(end_mark)), \ 629 (event).data.document_start.version_directive = (event_version_directive), \ 630 (event).data.document_start.tag_directives.list = (event_tag_directives_list), \ 631 (event).data.document_start.tag_directives.length = (event_tag_directives_length), \ 632 (event).data.document_start.tag_directives.capacity = (event_tag_directives_capacity), \ 633 (event).data.document_start.is_implicit = (event_is_implicit)) 634 635 #define DOCUMENT_END_EVENT_INIT(event,event_is_implicit,start_mark,end_mark) \ 636 (EVENT_INIT((event),YAML_DOCUMENT_END_EVENT,(start_mark),(end_mark)), \ 637 (event).data.document_end.is_implicit = (event_is_implicit)) 638 639 #define ALIAS_EVENT_INIT(event,event_anchor,start_mark,end_mark) \ 640 (EVENT_INIT((event),YAML_ALIAS_EVENT,(start_mark),(end_mark)), \ 641 (event).data.alias.anchor = (event_anchor)) 642 643 #define SCALAR_EVENT_INIT(event,event_anchor,event_tag,event_value, \ 644 event_length,event_is_plain_implicit,event_is_quoted_implicit, \ 645 event_style,start_mark,end_mark) \ 646 (EVENT_INIT((event),YAML_SCALAR_EVENT,(start_mark),(end_mark)), \ 647 (event).data.scalar.anchor = (event_anchor), \ 648 (event).data.scalar.tag = (event_tag), \ 649 (event).data.scalar.value = (event_value), \ 650 (event).data.scalar.length = (event_length), \ 651 (event).data.scalar.is_plain_implicit = (event_is_plain_implicit), \ 652 (event).data.scalar.is_quoted_implicit = (event_is_quoted_implicit), \ 653 (event).data.scalar.style = (event_style)) 654 655 #define SEQUENCE_START_EVENT_INIT(event,event_anchor,event_tag, \ 656 event_is_implicit,event_style,start_mark,end_mark) \ 657 (EVENT_INIT((event),YAML_SEQUENCE_START_EVENT,(start_mark),(end_mark)), \ 658 (event).data.sequence_start.anchor = (event_anchor), \ 659 (event).data.sequence_start.tag = (event_tag), \ 660 (event).data.sequence_start.is_implicit = (event_is_implicit), \ 661 (event).data.sequence_start.style = (event_style)) 662 663 #define SEQUENCE_END_EVENT_INIT(event,start_mark,end_mark) \ 664 (EVENT_INIT((event),YAML_SEQUENCE_END_EVENT,(start_mark),(end_mark))) 665 666 #define MAPPING_START_EVENT_INIT(event,event_anchor,event_tag, \ 667 event_is_implicit,event_style,start_mark,end_mark) \ 668 (EVENT_INIT((event),YAML_MAPPING_START_EVENT,(start_mark),(end_mark)), \ 669 (event).data.mapping_start.anchor = (event_anchor), \ 670 (event).data.mapping_start.tag = (event_tag), \ 671 (event).data.mapping_start.is_implicit = (event_is_implicit), \ 672 (event).data.mapping_start.style = (event_style)) 673 674 #define MAPPING_END_EVENT_INIT(event,start_mark,end_mark) \ 675 (EVENT_INIT((event),YAML_MAPPING_END_EVENT,(start_mark),(end_mark))) 688 (event).type = (_type), \ 689 (event).start_mark = (_start_mark), \ 690 (event).end_mark = (_end_mark)) 691 692 #define STREAM_START_EVENT_INIT(event, _encoding, _start_mark, _end_mark) \ 693 (EVENT_INIT((event), YAML_STREAM_START_EVENT, (_start_mark), (_end_mark)), \ 694 (event).data.stream_start.encoding = (_encoding)) 695 696 #define STREAM_END_EVENT_INIT(event, _start_mark, _end_mark) \ 697 (EVENT_INIT((event), YAML_STREAM_END_EVENT, (_start_mark), (_end_mark))) 698 699 #define DOCUMENT_START_EVENT_INIT(event, _version_directive, \ 700 _tag_directives_list, _tag_directives_length, _tag_directives_capacity, \ 701 _is_implicit, _start_mark, _end_mark) \ 702 (EVENT_INIT((event), YAML_DOCUMENT_START_EVENT, (_start_mark),(_end_mark)), \ 703 (event).data.document_start.version_directive = (_version_directive), \ 704 (event).data.document_start.tag_directives.list = (_tag_directives_list), \ 705 (event).data.document_start.tag_directives.length = (_tag_directives_length), \ 706 (event).data.document_start.tag_directives.capacity = (_tag_directives_capacity), \ 707 (event).data.document_start.is_implicit = (_is_implicit)) 708 709 #define DOCUMENT_END_EVENT_INIT(event, _is_implicit, _start_mark, _end_mark) \ 710 (EVENT_INIT((event), YAML_DOCUMENT_END_EVENT, (_start_mark), (_end_mark)), \ 711 (event).data.document_end.is_implicit = (_is_implicit)) 712 713 #define ALIAS_EVENT_INIT(event, _anchor, _start_mark, _end_mark) \ 714 (EVENT_INIT((event), YAML_ALIAS_EVENT, (_start_mark), (_end_mark)), \ 715 (event).data.alias.anchor = (_anchor)) 716 717 #define SCALAR_EVENT_INIT(event, _anchor, _tag, _value, _length, \ 718 _is_plain_implicit, _is_quoted_implicit, _style, _start_mark, _end_mark) \ 719 (EVENT_INIT((event), YAML_SCALAR_EVENT, (_start_mark), (_end_mark)), \ 720 (event).data.scalar.anchor = (_anchor), \ 721 (event).data.scalar.tag = (_tag), \ 722 (event).data.scalar.value = (_value), \ 723 (event).data.scalar.length = (_length), \ 724 (event).data.scalar.is_plain_implicit = (_is_plain_implicit), \ 725 (event).data.scalar.is_quoted_implicit = (_is_quoted_implicit), \ 726 (event).data.scalar.style = (_style)) 727 728 #define SEQUENCE_START_EVENT_INIT(event, _anchor, _tag, _is_implicit, _style, \ 729 _start_mark, _end_mark) \ 730 (EVENT_INIT((event), YAML_SEQUENCE_START_EVENT, (_start_mark), (_end_mark)), \ 731 (event).data.sequence_start.anchor = (_anchor), \ 732 (event).data.sequence_start.tag = (_tag), \ 733 (event).data.sequence_start.is_implicit = (_is_implicit), \ 734 (event).data.sequence_start.style = (_style)) 735 736 #define SEQUENCE_END_EVENT_INIT(event, _start_mark, _end_mark) \ 737 (EVENT_INIT((event), YAML_SEQUENCE_END_EVENT, (_start_mark), (_end_mark))) 738 739 #define MAPPING_START_EVENT_INIT(event, _anchor, _tag, _is_implicit, _style, \ 740 _start_mark, _end_mark) \ 741 (EVENT_INIT((event), YAML_MAPPING_START_EVENT, (_start_mark), (_end_mark)), \ 742 (event).data.mapping_start.anchor = (_anchor), \ 743 (event).data.mapping_start.tag = (_tag), \ 744 (event).data.mapping_start.is_implicit = (_is_implicit), \ 745 (event).data.mapping_start.style = (_style)) 746 747 #define MAPPING_END_EVENT_INIT(event, _start_mark, _end_mark) \ 748 (EVENT_INIT((event), YAML_MAPPING_END_EVENT, (_start_mark), (_end_mark))) 749 750 #if 0 676 751 677 752 /* … … 728 803 (node).data.mapping.pairs.top = (node_pairs_start), \ 729 804 (node).data.mapping.style = (node_style)) 805 806 #endif 730 807 731 808 /* … … 818 895 typedef union yaml_standard_reader_data_u { 819 896 /* String input data. */ 820 yaml_ string_t string;897 yaml_istring_t string; 821 898 /* File input data. */ 822 899 FILE *file; … … 852 929 853 930 /* The working buffer. */ 854 struct { 855 yaml_char_t *buffer; 856 size_t pointer; 857 size_t capacity; 858 } input; 931 yaml_iostring_t input; 859 932 860 933 /* The number of unread characters in the buffer. */ … … 862 935 863 936 /* The raw buffer. */ 864 struct { 865 unsigned char *buffer; 866 size_t pointer; 867 size_t capacity; 868 } raw_input; 937 yaml_raw_iostring_t raw_input; 869 938 870 939 /* The input encoding. */ … … 1023 1092 typedef union yaml_standard_writer_data_u { 1024 1093 /* String output data. */ 1025 yaml_ string_t string;1094 yaml_ostring_t string; 1026 1095 size_t *length; 1027 1096 /* File output data. */ … … 1055 1124 1056 1125 /* The working buffer. */ 1057 struct { 1058 yaml_char_t *buffer; 1059 size_t pointer; 1060 size_t capacity; 1061 } output; 1126 yaml_iostring_t output; 1062 1127 1063 1128 /* The raw buffer. */ 1064 struct { 1065 yaml_char_t *buffer; 1066 size_t pointer; 1067 size_t capacity; 1068 } raw_output; 1129 yaml_raw_iostring_t raw_output; 1069 1130 1070 1131 /* The offset of the current position (in bytes). */ … … 1148 1209 struct { 1149 1210 /* The anchor value. */ 1150 yaml_char_t *anchor;1211 const yaml_char_t *anchor; 1151 1212 /* The anchor length. */ 1152 1213 size_t anchor_length; … … 1158 1219 struct { 1159 1220 /* The tag handle. */ 1160 yaml_char_t *handle;1221 const yaml_char_t *handle; 1161 1222 /* The tag handle length. */ 1162 1223 size_t handle_length; 1163 1224 /* The tag suffix. */ 1164 yaml_char_t *suffix;1225 const yaml_char_t *suffix; 1165 1226 /* The tag suffix length. */ 1166 1227 size_t suffix_length; … … 1170 1231 struct { 1171 1232 /* The scalar value. */ 1172 yaml_char_t *value;1233 const yaml_char_t *value; 1173 1234 /* The scalar length. */ 1174 1235 size_t length; -
libyaml/trunk/tests/run-scanner.c
r263 r264 24 24 yaml_parser_t *parser; 25 25 yaml_token_t token; 26 yaml_error_t error; 27 char error_buffer[256]; 26 28 int done = 0; 27 29 int count = 0; 28 int error= 0;30 int failed = 0; 29 31 30 32 printf("[%d] Scanning '%s': ", number, argv[number]); … … 40 42 while (!done) 41 43 { 42 if (!yaml_parser_ scan(parser, &token)) {43 error= 1;44 if (!yaml_parser_parse_token(parser, &token)) { 45 failed = 1; 44 46 break; 45 47 } … … 52 54 } 53 55 56 yaml_parser_get_error(parser, &error); 57 54 58 yaml_parser_delete(parser); 55 59 56 60 assert(!fclose(file)); 57 61 58 printf("%s (%d tokens)\n", (error ? "FAILURE" : "SUCCESS"), count); 62 yaml_error_message(&error, error_buffer, 256); 63 64 printf("%s (%d tokens) -> %s\n", 65 (failed ? "FAILURE" : "SUCCESS"), 66 count, error_buffer); 59 67 } 60 68
Note: See TracChangeset
for help on using the changeset viewer.
