Changeset 32eb01b in mainline
- Timestamp:
- 2012-07-28T04:19:00Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f85ca3f
- Parents:
- 4056ad0
- Location:
- uspace/app/bithenge
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bithenge/helenos/os.h
r4056ad0 r32eb01b 82 82 static inline int bithenge_parse_int(const char *start, bithenge_int_t *result) 83 83 { 84 return str_uint64_t(start, NULL, 10, false, result); 84 const char *real_start = *start == '-' ? start + 1 : start; 85 uint64_t val; 86 int rc = str_uint64_t(real_start, NULL, 10, false, &val); 87 *result = val; 88 if (*start == '-') 89 *result = -*result; 90 return rc; 85 91 } 86 92 -
uspace/app/bithenge/script.c
r4056ad0 r32eb01b 74 74 * to indicate whether an error has occurred. */ 75 75 int error; 76 76 77 /** The list of named transforms. */ 77 78 transform_list_t *transform_list; 79 78 80 /** The name of the script file. */ 79 81 const char *filename; … … 91 93 /** Added to a buffer position to find the column number. */ 92 94 int line_offset; 95 93 96 /** The type of the current token. */ 94 97 token_type_t token; … … 100 103 bithenge_int_t token_int; 101 104 }; 105 106 /** The names of the current transform's parameters. */ 107 char **parameter_names; 108 /** The number of parameters. */ 109 int num_params; 102 110 } state_t; 103 111 … … 340 348 341 349 return expr; 350 } else if (state->token == TOKEN_IDENTIFIER) { 351 int i; 352 for (i = 0; i < state->num_params; i++) 353 if (!str_cmp(state->parameter_names[i], 354 state->token_string)) 355 break; 356 357 if (i == state->num_params) { 358 syntax_error(state, "unknown identifier"); 359 return NULL; 360 } 361 362 bithenge_expression_t *expr; 363 int rc = bithenge_param_expression(&expr, i); 364 if (rc != EOK) { 365 error_errno(state, rc); 366 return NULL; 367 } 368 369 next_token(state); 370 371 return expr; 342 372 } else { 343 373 syntax_error(state, "expression expected"); … … 494 524 expect(state, TOKEN_TRANSFORM); 495 525 char *name = expect_identifier(state); 526 527 if (state->token == '(') { 528 next_token(state); 529 while (state->error == EOK && state->token != ')') { 530 if (state->num_params) 531 expect(state, ','); 532 state->parameter_names = state_realloc(state, 533 state->parameter_names, 534 (state->num_params + 1)*sizeof(*state->parameter_names)); 535 if (state->error != EOK) 536 break; 537 state->parameter_names[state->num_params++] = 538 expect_identifier(state); 539 } 540 expect(state, ')'); 541 } 542 496 543 expect(state, '='); 497 544 bithenge_transform_t *xform = parse_transform(state); 498 545 expect(state, ';'); 546 547 if (state->error == EOK && state->num_params) { 548 int rc = bithenge_new_param_transform(&xform, xform, 549 state->num_params); 550 if (rc != EOK) { 551 xform = NULL; 552 error_errno(state, rc); 553 } 554 } 555 499 556 add_named_transform(state, xform, name); 557 558 for (int i = 0; i < state->num_params; i++) 559 free(state->parameter_names[i]); 560 free(state->parameter_names); 561 state->parameter_names = NULL; 562 state->num_params = 0; 500 563 } 501 564 … … 505 568 state->error = EOK; 506 569 state->transform_list = NULL; 570 state->parameter_names = NULL; 571 state->num_params = 0; 507 572 state->token = TOKEN_ERROR; 508 573 state->old_buffer_pos = state->buffer_pos = BUFFER_SIZE - 1; … … 532 597 entry = next; 533 598 } 599 for (int i = 0; i < state->num_params; i++) 600 free(state->parameter_names[i]); 601 free(state->parameter_names); 534 602 } 535 603 -
uspace/app/bithenge/transform.c
r4056ad0 r32eb01b 385 385 bithenge_node_t base; 386 386 struct struct_transform *transform; 387 bithenge_scope_t *scope;387 bithenge_scope_t scope; 388 388 bithenge_blob_t *blob; 389 389 } struct_node_t; … … 491 491 for (size_t i = 0; subxforms[i].transform; i++) { 492 492 rc = struct_node_for_one(subxforms[i].name, 493 subxforms[i].transform, struct_node->scope, &blob, func,493 subxforms[i].transform, &struct_node->scope, &blob, func, 494 494 data); 495 495 if (rc != EOK) … … 516 516 bithenge_transform_dec_ref(struct_as_transform(node->transform)); 517 517 bithenge_blob_dec_ref(node->blob); 518 bithenge_scope_destroy(&node->scope); 518 519 free(node); 519 520 } … … 533 534 if (!node) 534 535 return ENOMEM; 535 int rc = bithenge_init_internal_node(struct_as_node(node), 536 bithenge_scope_init(&node->scope); 537 int rc = bithenge_scope_copy(&node->scope, scope); 538 if (rc != EOK) { 539 free(node); 540 return rc; 541 } 542 rc = bithenge_init_internal_node(struct_as_node(node), 536 543 &struct_node_ops); 537 544 if (rc != EOK) { 545 bithenge_scope_destroy(&node->scope); 538 546 free(node); 539 547 return rc; … … 542 550 node->transform = self; 543 551 bithenge_node_inc_ref(in); 544 node->scope = scope;545 552 node->blob = bithenge_node_as_blob(in); 546 553 *out = struct_as_node(node); -
uspace/app/bithenge/transform.h
r4056ad0 r32eb01b 88 88 } 89 89 90 /** Copy a scope. 91 * @param[out] out The scope to fill in; must have been initialized with @a 92 * bithenge_scope_init. 93 * @param scope The scope to copy. 94 * @return EOK on success or an error code from errno.h. */ 95 static inline int bithenge_scope_copy(bithenge_scope_t *out, 96 bithenge_scope_t *scope) 97 { 98 out->params = malloc(sizeof(*out->params) * scope->num_params); 99 if (!out->params) 100 return ENOMEM; 101 memcpy(out->params, scope->params, sizeof(*out->params) * 102 scope->num_params); 103 out->num_params = scope->num_params; 104 for (int i = 0; i < out->num_params; i++) 105 bithenge_node_inc_ref(out->params[i]); 106 return EOK; 107 } 108 90 109 /** Allocate parameters. The parameters must then be set with @a 91 110 * bithenge_scope_set_param.
Note:
See TracChangeset
for help on using the changeset viewer.