Changeset 7c3fb9b in mainline for uspace/lib/bithenge/src/script.c
- Timestamp:
- 2018-05-17T08:29:01Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6ff23ff
- Parents:
- fac0ac7
- git-author:
- Jiri Svoboda <jiri@…> (2018-05-16 17:28:17)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-05-17 08:29:01)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/bithenge/src/script.c
rfac0ac7 r7c3fb9b 55 55 /** @cond internal 56 56 * Single-character symbols are represented by the character itself. Every 57 * other token uses one of these values: */ 57 * other token uses one of these values: 58 */ 58 59 typedef enum { 59 60 TOKEN_ERROR = -128, … … 98 99 typedef struct { 99 100 /** Rather than constantly checking return values, the parser uses this 100 * to indicate whether an error has occurred. */ 101 * to indicate whether an error has occurred. 102 */ 101 103 errno_t error; 102 104 … … 109 111 FILE *file; 110 112 /** The buffer that holds script code. There is always a '\0' after the 111 * current position to prevent reading too far. */ 113 * current position to prevent reading too far. 114 */ 112 115 char buffer[BUFFER_SIZE]; 113 116 /** The start position within the buffer of the next unread token. */ … … 124 127 union { 125 128 /** The value of a TOKEN_IDENTIFIER token. Unless changed to 126 * NULL, it will be freed when the next token is read. */ 129 * NULL, it will be freed when the next token is read. 130 */ 127 131 char *token_string; 128 132 /** The value of a TOKEN_INTEGER token. */ … … 139 143 140 144 /** Free the previous token's data. This must be called before changing 141 * state->token. */ 145 * state->token. 146 */ 142 147 static void done_with_token(state_t *state) 143 148 { … … 346 351 /** Allocate memory and handle failure by setting the error in the state. The 347 352 * caller must check the state for errors before using the return value of this 348 * function. */ 353 * function. 354 */ 349 355 static void *state_malloc(state_t *state, size_t size) 350 356 { … … 358 364 359 365 /** Reallocate memory and handle failure by setting the error in the state. If 360 * an error occurs, the existing pointer will be returned. */ 366 * an error occurs, the existing pointer will be returned. 367 */ 361 368 static void *state_realloc(state_t *state, void *ptr, size_t size) 362 369 { … … 372 379 373 380 /** Expect and consume a certain token. If the next token is of the wrong type, 374 * an error is caused. */ 381 * an error is caused. 382 */ 375 383 static void expect(state_t *state, token_type_t type) 376 384 { … … 383 391 384 392 /** Expect and consume an identifier token. If the next token is not an 385 * identifier, an error is caused and this function returns null. */ 393 * identifier, an error is caused and this function returns null. 394 */ 386 395 static char *expect_identifier(state_t *state) 387 396 { … … 397 406 398 407 /** Find a transform by name. A reference will be added to the transform. 399 * @return The found transform, or NULL if none was found. */ 408 * @return The found transform, or NULL if none was found. 409 */ 400 410 static bithenge_transform_t *get_named_transform(state_t *state, 401 411 const char *name) … … 419 429 420 430 /** Add a named transform. This function takes ownership of the name and a 421 * reference to the transform. If an error has occurred, either may be null. */ 431 * reference to the transform. If an error has occurred, either may be null. 432 */ 422 433 static void add_named_transform(state_t *state, bithenge_transform_t *xform, char *name) 423 434 { … … 809 820 /** Create a transform that just produces an empty node. 810 821 * @param state The parser state. 811 * @return The new transform, or NULL on error. */ 822 * @return The new transform, or NULL on error. 823 */ 812 824 static bithenge_transform_t *make_empty_transform(state_t *state) 813 825 { … … 1139 1151 1140 1152 /** Parse a transform without composition. 1141 * @return The parsed transform, or NULL if an error occurred. */ 1153 * @return The parsed transform, or NULL if an error occurred. 1154 */ 1142 1155 static bithenge_transform_t *parse_transform_no_compose(state_t *state) 1143 1156 { … … 1188 1201 1189 1202 /** Parse a transform. 1190 * @return The parsed transform, or NULL if an error occurred. */ 1203 * @return The parsed transform, or NULL if an error occurred. 1204 */ 1191 1205 static bithenge_transform_t *parse_transform(state_t *state) 1192 1206 { … … 1320 1334 * @param[out] out Stores the "main" transform. 1321 1335 * @return EOK on success, EINVAL on syntax error, or an error code from 1322 * errno.h. */ 1336 * errno.h. 1337 */ 1323 1338 errno_t bithenge_parse_script(const char *filename, bithenge_transform_t **out) 1324 1339 {
Note:
See TracChangeset
for help on using the changeset viewer.