| 645 | */ |
| 646 | |
| 647 | RULE * lookup_rule( OBJECT * rulename, module_t * m, int local_only ) |
| 648 | { |
| 649 | RULE * r; |
| 650 | RULE * result = 0; |
| 651 | module_t * original_module = m; |
| 652 | |
| 653 | if ( m->class_module ) |
| 654 | m = m->class_module; |
| 655 | |
| 656 | if ( m->rules && ( r = (RULE *)hash_find( m->rules, rulename ) ) ) |
| 657 | result = r; |
| 658 | else if ( !local_only && m->imported_modules ) |
| 659 | { |
| 660 | /* Try splitting the name into module and rule. */ |
| 661 | char * p = strchr( object_str( rulename ), '.' ) ; |
| 662 | if ( p ) |
| 663 | { |
| 664 | /* Now, r->name keeps the module name, and p + 1 keeps the rule |
| 665 | * name. |
| 666 | */ |
| 667 | OBJECT * rule_part = object_new( p + 1 ); |
| 668 | OBJECT * module_part; |
| 669 | { |
| 670 | string buf[ 1 ]; |
| 671 | string_new( buf ); |
| 672 | string_append_range( buf, object_str( rulename ), p ); |
| 673 | module_part = object_new( buf->value ); |
| 674 | string_free( buf ); |
| 675 | } |
| 676 | if ( hash_find( m->imported_modules, module_part ) ) |
| 677 | result = lookup_rule( rule_part, bindmodule( module_part ), 1 ); |
| 678 | object_free( module_part ); |
| 679 | object_free( rule_part ); |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | if ( result ) |
| 684 | { |
| 685 | if ( local_only && !result->exported ) |
| 686 | result = 0; |
| 687 | else if ( original_module != m ) |
| 688 | { |
| 689 | /* Lookup started in class module. We have found a rule in class |
| 690 | * module, which is marked for execution in that module, or in some |
| 691 | * instance. Mark it for execution in the instance where we started |
| 692 | * the lookup. |
| 693 | */ |
| 694 | int const execute_in_class = result->module == m; |
| 695 | int const execute_in_some_instance = |
| 696 | result->module->class_module == m; |
| 697 | if ( execute_in_class || execute_in_some_instance ) |
| 698 | result->module = original_module; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | return result; |
| 703 | } |
| 704 |
no test coverage detected