| @@ -745,6 +745,78 @@ error: · 744 unmodified lines |
| 745 | 745 | |
| 746 | 746 | |
| 747 | 747 | |
| 748 | + |
| 749 | +//----------------------------------------------------------------------------- |
| 750 | +// name: expandfilePath() |
| 751 | +// desc: expand file path, e.g., ~ on unix systems | 1.5.0.4 (ge) moved here |
| 752 | +//----------------------------------------------------------------------------- |
| 753 | +std::string expandFilePath( const string & directory ) |
| 754 | +{ |
| 755 | + // expansion |
| 756 | + string exp; |
| 757 | + |
| 758 | +#ifndef __PLATFORM_WIN32__ |
| 759 | +#ifndef __DISABLE_WORDEXP__ |
| 760 | + // 1.5.0.0 (ge) added (for ~) |
| 761 | + wordexp_t exp_result; |
| 762 | + // "perform shell-style word expansions" |
| 763 | + wordexp( directory.c_str(), &exp_result, 0 ); |
| 764 | + // concatenate in case there are spaces in the path |
| 765 | + for( t_CKINT i = 0; i < exp_result.we_wordc; i++ ) |
| 766 | + exp += string(i > 0 ? " " : "") + exp_result.we_wordv[i]; |
| 767 | + // free |
| 768 | + wordfree( &exp_result ); |
| 769 | +#endif |
| 770 | +#endif |
| 771 | + |
| 772 | + // if exp still empty, no change |
| 773 | + if( exp == "" ) exp = directory; |
| 774 | + |
| 775 | + // done |
| 776 | + return exp; |
| 777 | +} |
| 778 | + |
| 779 | + |
| 780 | + |
| 781 | + |
| 782 | +//----------------------------------------------------------------------------- |
| 783 | +// name: getDirEntryAttribute() |
| 784 | +// desc: get directory entry attribute | 1.5.0.4 (ge) moved into function |
| 785 | +//----------------------------------------------------------------------------- |
| 786 | +t_CKBOOL getDirEntryAttribute( dirent * de, t_CKBOOL & isDirectory, t_CKBOOL & isRegular ) |
| 787 | +{ |
| 788 | +#if defined(__PLATFORM_WIN32__) |
| 789 | + isDirectory = de->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; |
| 790 | + isRegular = ((de->data.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || |
| 791 | + (de->data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) || |
| 792 | + (de->data.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)); |
| 793 | +#elif defined(__WINDOWS_PTHREAD__) // Cygwin -- doesn't have dirent d_type |
| 794 | + std::string absolute_path = std::string(directory) + "/" + de->d_name; |
| 795 | + struct stat st; |
| 796 | + if( stat(absolute_path.c_str(), &st) == 0 ) |
| 797 | + { |
| 798 | + isDirectory = st.st_mode & S_IFDIR; |
| 799 | + isRegular = st.st_mode & S_IFREG; |
| 800 | + } |
| 801 | + else |
| 802 | + { |
| 803 | + // uhh ... |
| 804 | + EM_log( CK_LOG_INFO, |
| 805 | + "unable to open file '%s', ignoring for chugins", |
| 806 | + absolute_path.c_str() ); |
| 807 | + return false; |
| 808 | + } |
| 809 | +#else |
| 810 | + isDirectory = de->d_type == DT_DIR; |
| 811 | + isRegular = de->d_type == DT_REG; |
| 812 | +#endif |
| 813 | + |
| 814 | + return true; |
| 815 | +} |
| 816 | + |
| 817 | + |
| 818 | + |
| 819 | + |
| 748 | 820 | //----------------------------------------------------------------------------- |
| 749 | 821 | // name: load_external_module_at_path() |
| 750 | 822 | // desc: ... |
| @@ -789,116 +861,82 @@ t_CKBOOL load_external_module_at_path( Chuck_Compiler * compiler, · 38 unmodified lines |
| 789 | 861 | |
| 790 | 862 | //----------------------------------------------------------------------------- |
| 791 | 863 | // name: load_external_modules_in_directory() |
| 792 | | −// desc: ... |
| 864 | +// desc: load all external modules by extension within a directory |
| 793 | 865 | //----------------------------------------------------------------------------- |
| 794 | 866 | t_CKBOOL load_external_modules_in_directory( Chuck_Compiler * compiler, |
| 795 | 867 | const char * directory, |
| 796 | | − const char * extension ) |
| 868 | + const char * extension, |
| 869 | + t_CKBOOL recursiveSearch = FALSE ) |
| 797 | 870 | { |
| 798 | | − static const t_CKBOOL RECURSIVE_SEARCH = false; |
| 799 | | − |
| 800 | | − // directory path |
| 801 | | − string path = directory, exp = ""; |
| 802 | | − |
| 803 | | −#ifndef __PLATFORM_WIN32__ |
| 804 | | −#ifndef __DISABLE_WORDEXP__ |
| 805 | | − // 1.5.0.0 (ge) added (for ~) |
| 806 | | − wordexp_t exp_result; |
| 807 | | − // "perform shell-style word expansions" |
| 808 | | − wordexp( directory, &exp_result, 0 ); |
| 809 | | − // concatenate in case there are spaces in the path |
| 810 | | − for( t_CKINT i = 0; i < exp_result.we_wordc; i++ ) |
| 811 | | − exp += string(i > 0 ? " " : "") + exp_result.we_wordv[i]; |
| 812 | | − // replace |
| 813 | | − path = exp; |
| 814 | | −#endif |
| 815 | | −#endif |
| 816 | | − |
| 871 | + // expand directory path |
| 872 | + string path = expandFilePath( directory ); |
| 817 | 873 | // open the directory |
| 818 | 874 | DIR * dir = opendir( path.c_str() ); |
| 819 | 875 | |
| 876 | + // log |
| 877 | + EM_log( CK_LOG_INFO, "examining directory for chugins..." ); |
| 878 | + // push |
| 879 | + EM_pushlog(); |
| 880 | + // print directory to examine |
| 881 | + EM_log( CK_LOG_INFO, "'%s'", directory ); |
| 882 | + |
| 820 | 883 | // if successful |
| 821 | 884 | if( dir ) |
| 822 | 885 | { |
| 823 | | − // log |
| 824 | | − EM_log( CK_LOG_INFO, "examining directory '%s' for chugins", directory ); |
| 825 | | − |
| 826 | 886 | // do first read | 1.5.0.0 (ge + eito) #chunreal |
| 827 | 887 | struct dirent * de = readdir(dir); |
| 828 | | − |
| 829 | | − // while( (de = readdir(dir)) ) <- in ge's opinion clearer than what UE5 forces us to do |
| 888 | + // while( (de = readdir(dir)) ) <- UE5 forces us to not do this |
| 830 | 889 | while( de != NULL ) |
| 831 | 890 | { |
| 832 | 891 | t_CKBOOL is_regular = false; |
| 833 | 892 | t_CKBOOL is_directory = false; |
| 893 | + // get attributes |
| 894 | + if( !getDirEntryAttribute( de, is_directory, is_regular ) ) continue; |
| 834 | 895 | |
| 835 | | −#if defined(__PLATFORM_WIN32__) |
| 836 | | − is_directory = de->data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; |
| 837 | | − is_regular = ((de->data.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || |
| 838 | | − (de->data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) || |
| 839 | | − (de->data.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)); |
| 840 | | −#elif defined(__WINDOWS_PTHREAD__) // Cygwin -- doesn't have dirent d_type |
| 841 | | − std::string absolute_path = std::string(directory) + "/" + de->d_name; |
| 842 | | − struct stat st; |
| 843 | | − if( stat(absolute_path.c_str(), &st) == 0 ) |
| 844 | | − { |
| 845 | | − is_directory = st.st_mode & S_IFDIR; |
| 846 | | − is_regular = st.st_mode & S_IFREG; |
| 847 | | − } |
| 848 | | − else |
| 849 | | − { |
| 850 | | − // uhh ... |
| 851 | | − EM_log( CK_LOG_INFO, |
| 852 | | − "unable to open file '%s', ignoring for chugins", |
| 853 | | − absolute_path.c_str() ); |
| 854 | | − continue; |
| 855 | | − } |
| 856 | | −#else |
| 857 | | − is_directory = de->d_type == DT_DIR; |
| 858 | | − is_regular = de->d_type == DT_REG; |
| 859 | | −#endif |
| 860 | | − |
| 861 | | − if( is_regular ) // TODO: follow links? |
| 896 | + // check | TODO: follow links? |
| 897 | + if( is_regular ) |
| 862 | 898 | { |
| 863 | | − if( extension_matches(de->d_name, extension) ) |
| 899 | + // check for ck files to pre-load |
| 900 | + if( extension_matches(de->d_name, ".ck") ) |
| 864 | 901 | { |
| 902 | + // construct absolute path |
| 865 | 903 | std::string absolute_path = std::string(directory) + "/" + de->d_name; |
| 866 | | − |
| 867 | | − load_external_module_at_path(compiler, de->d_name, |
| 868 | | − absolute_path.c_str()); |
| 904 | + // append file path |
| 905 | + compiler->m_cklibs_to_preload.push_back(absolute_path); |
| 869 | 906 | } |
| 870 | | − else if( extension_matches(de->d_name, ".ck") ) |
| 907 | + // check extension passed in |
| 908 | + else if( extension_matches(de->d_name, extension) ) |
| 871 | 909 | { |
| 910 | + // construct absolute path |
| 872 | 911 | std::string absolute_path = std::string(directory) + "/" + de->d_name; |
| 873 | | − compiler->m_cklibs_to_preload.push_back(absolute_path); |
| 912 | + // load module |
| 913 | + load_external_module_at_path( compiler, de->d_name, absolute_path.c_str() ); |
| 874 | 914 | } |
| 875 | 915 | } |
| 876 | | − else if( RECURSIVE_SEARCH && is_directory ) |
| 916 | + else if( recursiveSearch && is_directory ) |
| 877 | 917 | { |
| 878 | | − // recurse |
| 879 | | − // TODO: max depth? |
| 918 | + // recurse | TODO: max depth? |
| 880 | 919 | if( strncmp(de->d_name, ".", sizeof(".")) != 0 && |
| 881 | 920 | strncmp(de->d_name, "..", sizeof("..")) != 0 ) |
| 882 | 921 | { |
| 922 | + // construct absolute path |
| 883 | 923 | std::string absolute_path = std::string(directory) + "/" + de->d_name; |
| 884 | | − load_external_modules_in_directory(compiler, |
| 885 | | − absolute_path.c_str(), |
| 886 | | − extension); |
| 924 | + // search in sub-directory |
| 925 | + load_external_modules_in_directory( compiler, absolute_path.c_str(), extension); |
| 887 | 926 | } |
| 888 | 927 | } |
| 889 | 928 | #ifdef __PLATFORM_MACOSX__ |
| 890 | | − // #if __APPLE__ probably cleaner but using the above for consistency for now (ge) |
| 891 | | − // --- |
| 892 | | − // On macOS, a chugin can either be a regular file (a .dylib simply renamed to .chug) |
| 893 | | − // or it can be a MODULE like using CMake with add_library(FooChugin MODULE foo.cpp) |
| 894 | | − // If it's a module bundle, then because .chug is a nonstandard extension, |
| 895 | | − // on the filesystem it shows up as a directory ending in .chug. |
| 896 | | − // If we see one of these directories, we can dive directly to the Contents/MacOS subfolder |
| 897 | | − // and look for a regular file. | 1.5.0.1 (dbraun) added |
| 898 | | − else if (is_directory && extension_matches(de->d_name, extension)) { |
| 929 | + else if( is_directory && extension_matches(de->d_name, extension) ) |
| 930 | + { |
| 931 | + // On macOS, a chugin can either be a regular file (a .dylib simply renamed to .chug) |
| 932 | + // or it can be a MODULE like using CMake with add_library(FooChugin MODULE foo.cpp) |
| 933 | + // If it's a module bundle, then because .chug is a nonstandard extension, |
| 934 | + // on the filesystem it shows up as a directory ending in .chug. |
| 935 | + // If we see one of these directories, we can dive directly to the Contents/MacOS subfolder |
| 936 | + // and look for a regular file. | 1.5.0.1 (dbraun) added |
| 899 | 937 | std::string absolute_path = std::string(directory) + "/" + de->d_name + "/Contents/MacOS"; |
| 900 | | − const char* subdirectory = absolute_path.c_str(); |
| 901 | | − load_external_modules_in_directory(compiler, subdirectory, ""); |
| 938 | + const char * subdirectory = absolute_path.c_str(); |
| 939 | + load_external_modules_in_directory( compiler, subdirectory, "" ); |
| 902 | 940 | } |
| 903 | 941 | #endif // #ifdef __PLATFORM_MACOSX__ |
| 904 | 942 | |
| @@ -912,19 +950,14 @@ t_CKBOOL load_external_modules_in_directory( Chuck_Compiler * compiler, · 7 unmodified lines |
| 912 | 950 | else |
| 913 | 951 | { |
| 914 | 952 | // log (1.3.1.2: changed to 2 lines to stay within 80 chars) |
| 915 | | − EM_log( CK_LOG_INFO, "unable to open directory:" ); |
| 916 | 953 | EM_pushlog(); |
| 917 | | − EM_log( CK_LOG_INFO, "'%s'", directory ); |
| 954 | + EM_log( CK_LOG_INFO, "unable to open directory..." ); |
| 918 | 955 | EM_log( CK_LOG_INFO, "ignoring for chugins..." ); |
| 919 | 956 | EM_poplog(); |
| 920 | 957 | } |
| 921 | 958 | |
| 922 | | −#ifndef __PLATFORM_WIN32__ |
| 923 | | −#ifndef __DISABLE_WORDEXP__ |
| 924 | | − // free | 1.5.0.0 (ge) added |
| 925 | | − wordfree( &exp_result ); |
| 926 | | −#endif |
| 927 | | −#endif |
| 959 | + // pop log |
| 960 | + EM_poplog(); |
| 928 | 961 | |
| 929 | 962 | return TRUE; |
| 930 | 963 | } |
| @@ -934,11 +967,12 @@ t_CKBOOL load_external_modules_in_directory( Chuck_Compiler * compiler, · 3 unmodified lines |
| 934 | 967 | |
| 935 | 968 | //----------------------------------------------------------------------------- |
| 936 | 969 | // name: load_external_modules() |
| 937 | | −// desc: ... |
| 970 | +// desc: load external modules (e.g., .chug and .ck library files) |
| 938 | 971 | //----------------------------------------------------------------------------- |
| 939 | | −t_CKBOOL Chuck_Compiler:: load_external_modules( const char * extension, |
| 940 | | − std::list<std::string> & chugin_search_paths, |
| 941 | | − std::list<std::string> & named_dls ) |
| 972 | +t_CKBOOL Chuck_Compiler::load_external_modules( const char * extension, |
| 973 | + std::list<std::string> & chugin_search_paths, |
| 974 | + std::list<std::string> & named_dls, |
| 975 | + t_CKBOOL recursiveSearch ) |
| 942 | 976 | { |
| 943 | 977 | // get env |
| 944 | 978 | Chuck_Env * env = this->env(); |
| @@ -949,23 +983,25 @@ t_CKBOOL Chuck_Compiler:: load_external_modules( const char * extension, · 4 unmodified lines |
| 949 | 983 | // load it |
| 950 | 984 | type_engine_load_context( env, context ); |
| 951 | 985 | |
| 952 | | − /* first load dynamic libraries explicitly named on the command line */ |
| 953 | | − for(std::list<std::string>::iterator i_dl = named_dls.begin(); |
| 954 | | − i_dl != named_dls.end(); i_dl++) |
| 986 | + // first load dynamic libraries explicitly named on the command line |
| 987 | + for( std::list<std::string>::iterator i_dl = named_dls.begin(); |
| 988 | + i_dl != named_dls.end(); i_dl++ ) |
| 955 | 989 | { |
| 990 | + // get chugin name |
| 956 | 991 | std::string & dl_path = *i_dl; |
| 957 | | − if(!extension_matches(dl_path.c_str(), extension)) |
| 992 | + // check extension, append if no match |
| 993 | + if( !extension_matches(dl_path.c_str(), extension) ) |
| 958 | 994 | dl_path += extension; |
| 959 | | − |
| 960 | | − load_external_module_at_path(this, dl_path.c_str(), |
| 961 | | − dl_path.c_str()); |
| 995 | + // load the module |
| 996 | + load_external_module_at_path( this, dl_path.c_str(), dl_path.c_str() ); |
| 962 | 997 | } |
| 963 | 998 | |
| 964 | | − /* now recurse through search paths and load any DLs or .ck files found */ |
| 965 | | − for(std::list<std::string>::iterator i_sp = chugin_search_paths.begin(); |
| 966 | | − i_sp != chugin_search_paths.end(); i_sp++) |
| 999 | + // now recurse through search paths and load any DLs or .ck files found |
| 1000 | + for( std::list<std::string>::iterator i_sp = chugin_search_paths.begin(); |
| 1001 | + i_sp != chugin_search_paths.end(); i_sp++ ) |
| 967 | 1002 | { |
| 968 | | − load_external_modules_in_directory(this, (*i_sp).c_str(), extension); |
| 1003 | + // search directory and load contents |
| 1004 | + load_external_modules_in_directory( this, (*i_sp).c_str(), extension, recursiveSearch ); |
| 969 | 1005 | } |
| 970 | 1006 | |
| 971 | 1007 | // clear context |
| @@ -975,18 +1011,207 @@ t_CKBOOL Chuck_Compiler:: load_external_modules( const char * extension, · 3 unmodified lines |
| 975 | 1011 | env->global()->commit(); |
| 976 | 1012 | |
| 977 | 1013 | return TRUE; |
| 978 | | − /* |
| 979 | | −error: |
| 1014 | +} |
| 980 | 1015 | |
| 981 | | − // probably dangerous: rollback |
| 982 | | − env->global()->rollback(); |
| 983 | 1016 | |
| 984 | | − // clear context |
| 985 | | − type_engine_unload_context( env ); |
| 986 | 1017 | |
| 987 | | − // pop indent level |
| 1018 | + |
| 1019 | +//----------------------------------------------------------------------------- |
| 1020 | +// name: probe_external_module_at_path() |
| 1021 | +// desc: probe external module |
| 1022 | +//----------------------------------------------------------------------------- |
| 1023 | +t_CKBOOL probe_external_module_at_path( const char * name, const char * dl_path ) |
| 1024 | +{ |
| 1025 | + // create dynamic module |
| 1026 | + Chuck_DLL * dll = new Chuck_DLL( NULL, name ); |
| 1027 | + |
| 1028 | + // load the dll, lazy mode |
| 1029 | + if( dll->load(dl_path, CK_QUERY_FUNC, TRUE) ) |
| 1030 | + { |
| 1031 | + // probe it |
| 1032 | + dll->probe(); |
| 1033 | + // print |
| 1034 | + EM_log( CK_LOG_SYSTEM, "chugin %s [version %d.%d]", name, dll->versionMajor(), dll->versionMinor() ); |
| 1035 | + // if not compatible |
| 1036 | + if( !dll->compatible() ) |
| 1037 | + { |
| 1038 | + // push |
| 1039 | + EM_pushlog(); |
| 1040 | + EM_log( CK_LOG_SYSTEM, "VERSION MISMATCH with host %d.%d", CK_DLL_VERSION_MAJOR, CK_DLL_VERSION_MINOR ); |
| 1041 | + EM_poplog(); |
| 1042 | + } |
| 1043 | + } |
| 1044 | + else |
| 1045 | + { |
| 1046 | + // print |
| 1047 | + EM_log( CK_LOG_SYSTEM, "chugin: '%s' FAILED to load...", name ); |
| 1048 | + } |
| 1049 | + |
| 1050 | + // done |
| 1051 | + return TRUE; |
| 1052 | +} |
| 1053 | + |
| 1054 | + |
| 1055 | + |
| 1056 | + |
| 1057 | +//----------------------------------------------------------------------------- |
| 1058 | +// name: probe_external_modules_in_directory() |
| 1059 | +// desc: probe all external modules by extension within a directory |
| 1060 | +//----------------------------------------------------------------------------- |
| 1061 | +t_CKBOOL probe_external_modules_in_directory( const char * directory, |
| 1062 | + const char * extension, |
| 1063 | + t_CKBOOL recursiveSearch, |
| 1064 | + std::list<std::string> & ck_libs ) |
| 1065 | +{ |
| 1066 | + // expand directory path |
| 1067 | + string path = expandFilePath( directory ); |
| 1068 | + // open the directory |
| 1069 | + DIR * dir = opendir( path.c_str() ); |
| 1070 | + |
| 1071 | + // log |
| 1072 | + // EM_log( CK_LOG_SYSTEM, "examining directory for chugins..." ); |
| 1073 | + // print directory to examine |
| 1074 | + EM_log( CK_LOG_SYSTEM, "%s", directory ); |
| 1075 | + // push |
| 1076 | + EM_pushlog(); |
| 1077 | + |
| 1078 | + // if successful |
| 1079 | + if( dir ) |
| 1080 | + { |
| 1081 | + // do first read | 1.5.0.0 (ge + eito) #chunreal |
| 1082 | + struct dirent * de = readdir(dir); |
| 1083 | + // while( (de = readdir(dir)) ) <- UE5 forces us to not do this |
| 1084 | + while( de != NULL ) |
| 1085 | + { |
| 1086 | + t_CKBOOL is_regular = false; |
| 1087 | + t_CKBOOL is_directory = false; |
| 1088 | + // get attributes |
| 1089 | + if( !getDirEntryAttribute( de, is_directory, is_regular ) ) continue; |
| 1090 | + |
| 1091 | + // check | TODO: follow links? |
| 1092 | + if( is_regular ) |
| 1093 | + { |
| 1094 | + // check for ck files to pre-load |
| 1095 | + if( extension_matches(de->d_name, ".ck") ) |
| 1096 | + { |
| 1097 | + // print |
| 1098 | + // EM_log( CK_LOG_SYSTEM, "module %s", de->d_name ); |
| 1099 | + |
| 1100 | + // construct absolute path |
| 1101 | + std::string absolute_path = std::string(directory) + "/" + de->d_name; |
| 1102 | + // append file path |
| 1103 | + ck_libs.push_back(absolute_path); |
| 1104 | + } |
| 1105 | + // check extension passed in |
| 1106 | + else if( extension_matches(de->d_name, extension) ) |
| 1107 | + { |
| 1108 | + // construct absolute path |
| 1109 | + std::string absolute_path = std::string(directory) + "/" + de->d_name; |
| 1110 | + // load module |
| 1111 | + probe_external_module_at_path( de->d_name, absolute_path.c_str() ); |
| 1112 | + } |
| 1113 | + } |
| 1114 | + else if( recursiveSearch && is_directory ) |
| 1115 | + { |
| 1116 | + // recurse | TODO: max depth? |
| 1117 | + if( strncmp(de->d_name, ".", sizeof(".")) != 0 && |
| 1118 | + strncmp(de->d_name, "..", sizeof("..")) != 0 ) |
| 1119 | + { |
| 1120 | + // construct absolute path |
| 1121 | + std::string absolute_path = std::string(directory) + "/" + de->d_name; |
| 1122 | + // search in sub-directory |
| 1123 | + probe_external_modules_in_directory( absolute_path.c_str(), extension, TRUE, ck_libs ); |
| 1124 | + } |
| 1125 | + } |
| 1126 | +#ifdef __PLATFORM_MACOSX__ |
| 1127 | + else if( is_directory && extension_matches(de->d_name, extension) ) |
| 1128 | + { |
| 1129 | + // On macOS, a chugin can either be a regular file (a .dylib simply renamed to .chug) |
| 1130 | + // or it can be a MODULE like using CMake with add_library(FooChugin MODULE foo.cpp) |
| 1131 | + // If it's a module bundle, then because .chug is a nonstandard extension, |
| 1132 | + // on the filesystem it shows up as a directory ending in .chug. |
| 1133 | + // If we see one of these directories, we can dive directly to the Contents/MacOS subfolder |
| 1134 | + // and look for a regular file. | 1.5.0.1 (dbraun) added |
| 1135 | + std::string absolute_path = std::string(directory) + "/" + de->d_name + "/Contents/MacOS"; |
| 1136 | + const char * subdirectory = absolute_path.c_str(); |
| 1137 | + probe_external_modules_in_directory( subdirectory, "", FALSE, ck_libs ); |
| 1138 | + } |
| 1139 | +#endif // #ifdef __PLATFORM_MACOSX__ |
| 1140 | + |
| 1141 | + // read next | 1.5.0.0 (ge) moved here due to #chunreal |
| 1142 | + de = readdir( dir ); |
| 1143 | + } |
| 1144 | + |
| 1145 | + // close |
| 1146 | + closedir( dir ); |
| 1147 | + } |
| 1148 | + else |
| 1149 | + { |
| 1150 | + // log (1.3.1.2: changed to 2 lines to stay within 80 chars) |
| 1151 | + EM_pushlog(); |
| 1152 | + EM_log( CK_LOG_SYSTEM, "unable to open directory..." ); |
| 1153 | + EM_log( CK_LOG_SYSTEM, "ignoring for chugins..." ); |
| 1154 | + EM_poplog(); |
| 1155 | + } |
| 1156 | + |
| 1157 | + // pop log |
| 988 | 1158 | EM_poplog(); |
| 989 | 1159 | |
| 990 | | − return FALSE; |
| 991 | | − */ |
| 1160 | + return TRUE; |
| 1161 | +} |
| 1162 | + |
| 1163 | + |
| 1164 | + |
| 1165 | + |
| 1166 | +//----------------------------------------------------------------------------- |
| 1167 | +// name: probe_external_modules() |
| 1168 | +// desc: probe external modules (e.g., .chug and .ck library files) |
| 1169 | +//----------------------------------------------------------------------------- |
| 1170 | +t_CKBOOL Chuck_Compiler::probe_external_modules( const char * extension, |
| 1171 | + std::list<std::string> & chugin_search_paths, |
| 1172 | + std::list<std::string> & named_dls, |
| 1173 | + t_CKBOOL recursiveSearch, |
| 1174 | + std::list<std::string> & ck_libs ) |
| 1175 | +{ |
| 1176 | + // print |
| 1177 | + EM_log( CK_LOG_SYSTEM, "probing specified chugins..." ); |
| 1178 | + // push |
| 1179 | + EM_pushlog(); |
| 1180 | + |
| 1181 | + // first load dynamic libraries explicitly named on the command line |
| 1182 | + for( std::list<std::string>::iterator i_dl = named_dls.begin(); |
| 1183 | + i_dl != named_dls.end(); i_dl++ ) |
| 1184 | + { |
| 1185 | + // get chugin name |
| 1186 | + std::string & dl_path = *i_dl; |
| 1187 | + // check extension, append if no match |
| 1188 | + if( !extension_matches(dl_path.c_str(), extension) ) |
| 1189 | + dl_path += extension; |
| 1190 | + // load the module |
| 1191 | + probe_external_module_at_path( dl_path.c_str(), dl_path.c_str() ); |
| 1192 | + } |
| 1193 | + |
| 1194 | + // check |
| 1195 | + if( named_dls.size() == 0 ) |
| 1196 | + EM_log( CK_LOG_SYSTEM, "(none specified)" ); |
| 1197 | + |
| 1198 | + // pop |
| 1199 | + EM_poplog(); |
| 1200 | + // print |
| 1201 | + EM_log( CK_LOG_SYSTEM, "probing chugins in search paths..." ); |
| 1202 | + // push |
| 1203 | + EM_pushlog(); |
| 1204 | + |
| 1205 | + // now recurse through search paths and load any DLs or .ck files found |
| 1206 | + for( std::list<std::string>::iterator i_sp = chugin_search_paths.begin(); |
| 1207 | + i_sp != chugin_search_paths.end(); i_sp++ ) |
| 1208 | + { |
| 1209 | + // search directory and load contents |
| 1210 | + probe_external_modules_in_directory( (*i_sp).c_str(), extension, recursiveSearch, ck_libs ); |
| 1211 | + } |
| 1212 | + |
| 1213 | + // pop |
| 1214 | + EM_poplog(); |
| 1215 | + |
| 1216 | + return TRUE; |
| 992 | 1217 | } |