| 789 | |
| 790 | |
| 791 | LIST * glob_recursive( char const * pattern ) |
| 792 | { |
| 793 | LIST * result = L0; |
| 794 | |
| 795 | /* Check if there's metacharacters in pattern */ |
| 796 | if ( !has_wildcards( pattern ) ) |
| 797 | { |
| 798 | /* No metacharacters. Check if the path exists. */ |
| 799 | OBJECT * const p = object_new( pattern ); |
| 800 | result = append_if_exists( result, p ); |
| 801 | object_free( p ); |
| 802 | } |
| 803 | else |
| 804 | { |
| 805 | /* Have metacharacters in the pattern. Split into dir/name. */ |
| 806 | PATHNAME path[ 1 ]; |
| 807 | path_parse( pattern, path ); |
| 808 | |
| 809 | if ( path->f_dir.ptr ) |
| 810 | { |
| 811 | LIST * dirs = L0; |
| 812 | string dirname[ 1 ]; |
| 813 | string basename[ 1 ]; |
| 814 | string_new( dirname ); |
| 815 | string_new( basename ); |
| 816 | |
| 817 | string_append_range( dirname, path->f_dir.ptr, |
| 818 | path->f_dir.ptr + path->f_dir.len ); |
| 819 | |
| 820 | path->f_grist.ptr = 0; |
| 821 | path->f_grist.len = 0; |
| 822 | path->f_dir.ptr = 0; |
| 823 | path->f_dir.len = 0; |
| 824 | path_build( path, basename ); |
| 825 | |
| 826 | dirs = has_wildcards( dirname->value ) |
| 827 | ? glob_recursive( dirname->value ) |
| 828 | : list_push_back( dirs, object_new( dirname->value ) ); |
| 829 | |
| 830 | if ( has_wildcards( basename->value ) ) |
| 831 | { |
| 832 | OBJECT * const b = object_new( basename->value ); |
| 833 | LISTITER iter = list_begin( dirs ); |
| 834 | LISTITER const end = list_end( dirs ); |
| 835 | for ( ; iter != end; iter = list_next( iter ) ) |
| 836 | result = list_append( result, glob1( list_item( iter ), b ) |
| 837 | ); |
| 838 | object_free( b ); |
| 839 | } |
| 840 | else |
| 841 | { |
| 842 | LISTITER iter = list_begin( dirs ); |
| 843 | LISTITER const end = list_end( dirs ); |
| 844 | string file_string[ 1 ]; |
| 845 | string_new( file_string ); |
| 846 | |
| 847 | /* No wildcard in basename. */ |
| 848 | for ( ; iter != end; iter = list_next( iter ) ) |
no test coverage detected