/** * Load or generate the case handling tables. * * The case tables are defined in UCS2 and don't depend on any * configured parameters, so they never need to be reloaded. **/ void load_case_tables(void) { static int initialised; int i; if (initialised) return; initialised = 1; upcase_table = map_file(lib_path("upcase.dat"), 0x20000); lowcase_table = map_file(lib_path("lowcase.dat"), 0x20000); /* we would like Samba to limp along even if these tables are not available */ if (!upcase_table) { DEBUG(1,("creating lame upcase table\n")); upcase_table = malloc(0x20000); for (i=0;i<0x10000;i++) { smb_ucs2_t v; SSVAL(&v, 0, i); upcase_table[v] = i; } for (i=0;i<256;i++) { smb_ucs2_t v; SSVAL(&v, 0, UCS2_CHAR(i)); upcase_table[v] = UCS2_CHAR(islower(i)?toupper(i):i); } } if (!lowcase_table) { DEBUG(1,("creating lame lowcase table\n")); lowcase_table = malloc(0x20000); for (i=0;i<0x10000;i++) { smb_ucs2_t v; SSVAL(&v, 0, i); lowcase_table[v] = i; } for (i=0;i<256;i++) { smb_ucs2_t v; SSVAL(&v, 0, UCS2_CHAR(i)); lowcase_table[v] = UCS2_CHAR(isupper(i)?tolower(i):i); } } }
int main(int argc, char *argv[]) { std::string lib_path("../../../lib"); std::string grammar_path("./grammar"); if (argc >= 2 && argv[1]) { std::cout << "Using user specified search path for jars." << std::endl; lib_path = argv[1]; } else { std::cout << "Using default search path for jars." << std::endl; std::cout << "If this doesn't work, try passing a jar search path as the first argument." << std::endl; } std::cout << "Looking for jars in " << lib_path << std::endl; if (argc >= 3 && argv[2]) { std::cout << "Using user specified grammar search path." << std::endl; grammar_path = argv[2]; } else { std::cout << "Using default grammar search path." << std::endl; std::cout << "If this doesn't work, try passing a grammar search path as the second argument." << std::endl; } std::cout << "Looking for .gram grammar files in " << grammar_path << std::endl; voce::init(lib_path, false, true, grammar_path, "digits"); std::cout << "This is a speech recognition test. " << "Speak digits from 0-9 into the microphone. " << "Speak 'quit' to quit." << std::endl; bool quit = false; while (!quit) { // Normally, applications would do application-specific things // here. For this sample, we'll just sleep for a little bit. #ifdef WIN32 ::Sleep(200); #else usleep(200); #endif while (voce::getRecognizerQueueSize() > 0) { std::string s = voce::popRecognizedString(); // Check if the string contains 'quit'. if (std::string::npos != s.rfind("quit")) { quit = true; } std::cout << "You said: " << s << std::endl; //voce::synthesize(s); } } voce::destroy(); return 0; }
HMODULE LoadLibrarySystem(const std::wstring& library_name, std::wstring* out_path) { std::unique_ptr<wchar_t[]> system_directory(new wchar_t[MAX_PATH]); GetSystemDirectoryW(system_directory.get(), MAX_PATH); std::wstring lib_path(system_directory.get()); StringPathAppend(&lib_path, library_name); if (out_path) *out_path = lib_path; return LoadLibraryW(lib_path.c_str()); }
static void shim_load_libGL() { if(!libGL) { libGL = dlopen(lib_path("libGL.so"), RTLD_LAZY); fprintf(stderr, "%s\n", lib_path("libGL.so")); if(!libGL) { fputs(dlerror(), stderr); exit(1); } _glXSwapBuffers = (void (*)(Display*, GLXDrawable))real_dlsym(libGL, "glXSwapBuffers"); _glXGetProcAddress = (void (*(*)(const GLubyte *procName))())real_dlsym(libGL, "glXGetProcAddressARB"); const char *error; if((error = dlerror())) { fputs(error, stderr); exit(1); } } }
int main(int argc, char* argv[]) { /*<-*/ b2_workarounds::argv_to_path_guard guard(argc, argv); /*->*/ boost::filesystem::path lib_path(argv[1]); // argv[1] contains path to directory with our plugin library boost::shared_ptr<my_plugin_api> plugin; // variable to hold a pointer to plugin variable std::cout << "Loading the plugin" << std::endl; plugin = dll::import<my_plugin_api>( // type of imported symbol is located between `<` and `>` lib_path / "my_plugin_sum", // path to the library and library name "plugin", // name of the symbol to import dll::load_mode::append_decorations // makes `libmy_plugin_sum.so` or `my_plugin_sum.dll` from `my_plugin_sum` ); std::cout << "plugin->calculate(1.5, 1.5) call: " << plugin->calculate(1.5, 1.5) << std::endl; }
int main(int argc, char* argv[]) { std::cout << "Application started" << std::endl; /*<-*/ BOOST_ASSERT(argc >= 2); /*->*/ // argv[1] contains path to our plugin library boost::filesystem::path lib_path(argv[1]); boost::shared_ptr<my_plugin_api> plugin; // variable to hold a pointer to plugin variable std::cout << "Loading the plugin" << std::endl; plugin = dll::import_alias<my_plugin_api>( // type of imported symbol is located between `<` and `>` lib_path / "my_plugin_sum"/*<-*/ BOOST_B2_LIBRARY_DECORATIONS /*->*/, // path to the library and library name "plugin", // name of the symbol to import dll::load_mode::append_decorations // makes `libmy_plugin_sum.so` or `my_plugin_sum.dll` from `my_plugin_sum` ); std::cout << "Plugin Version: " << plugin->version() << std::endl; std::cout << "Plugin Method: " << plugin->calculate(1.5, 1.5) << std::endl; }
static void shim_load_libEGL() { if(!libEGL) { libEGL = dlopen(lib_path("libEGL.so"), RTLD_LAZY); if(!libEGL) { fputs(dlerror(), stderr); exit(1); } _eglSwapBuffers = (EGLBoolean (*)(EGLDisplay, EGLSurface))dlsym(libEGL, "eglSwapBuffers"); const char *error; if((error = dlerror())) { fputs(error, stderr); exit(1); } } }
void init_valid_table(void) { static int mapped_file; int i; const char *allowed = ".!#$%&'()_-@^`~"; uint8 *valid_file; if (mapped_file) { /* Can't unmap files, so stick with what we have */ return; } valid_file = map_file(lib_path("valid.dat"), 0x10000); if (valid_file) { valid_table = valid_file; mapped_file = 1; valid_table_use_unmap = True; return; } /* Otherwise, we're using a dynamically created valid_table. * It might need to be regenerated if the code page changed. * We know that we're not using a mapped file, so we can * free() the old one. */ if (valid_table) SAFE_FREE(valid_table); /* use free rather than unmap */ valid_table_use_unmap = False; DEBUG(2,("creating default valid table\n")); valid_table = SMB_MALLOC(0x10000); for (i=0;i<128;i++) { valid_table[i] = isalnum(i) || strchr(allowed,i); } for (;i<0x10000;i++) { smb_ucs2_t c; SSVAL(&c, 0, i); valid_table[i] = check_dos_char(c); } }
void *dlsym(void *handle, const char *name) { if(!real_dlsym) { fprintf(stderr, "with_smaa: Getting real dlsym...\n"); void *libdl = dlopen(lib_path("libdl.so"), RTLD_NOW); real_dlsym = __libc_dlsym(libdl, "dlsym"); fprintf(stderr, "with_smaa: real_dlsym=%p\n", real_dlsym); } if (!strcmp(name, "dlsym")) { return (void*) dlsym; } else if(!strcmp(name, "glXGetProcAddressARB")) { fprintf(stderr, "with_smaa: dlsym: redirecting glXGetProcAddressARB\n"); return (void*) glXGetProcAddress; } else if(!strcmp(name, "glXGetProcAddress")) { fprintf(stderr, "with_smaa: dlsym: redirecting glXGetProcAddress\n"); return (void*) glXGetProcAddress; } else if(!strcmp(name, "glXSwapBuffers")) { fprintf(stderr, "with_smaa: dlsym: redirecting glXSwapBuffers\n"); return (void*) glXSwapBuffers; } return real_dlsym(handle, name); }
void load_case_tables(void) { static int initialised; char *old_locale = NULL, *saved_locale = NULL; int i; if (initialised) { return; } initialised = 1; upcase_table = map_file(lib_path("upcase.dat"), 0x20000); upcase_table_use_unmap = ( upcase_table != NULL ); lowcase_table = map_file(lib_path("lowcase.dat"), 0x20000); lowcase_table_use_unmap = ( lowcase_table != NULL ); #ifdef HAVE_SETLOCALE /* Get the name of the current locale. */ old_locale = setlocale(LC_ALL, NULL); if (old_locale) { /* Save it as it is in static storage. */ saved_locale = SMB_STRDUP(old_locale); } /* We set back the locale to C to get ASCII-compatible toupper/lower functions. */ setlocale(LC_ALL, "C"); #endif /* we would like Samba to limp along even if these tables are not available */ if (!upcase_table) { DEBUG(1,("creating lame upcase table\n")); upcase_table = SMB_MALLOC(0x20000); for (i=0;i<0x10000;i++) { smb_ucs2_t v; SSVAL(&v, 0, i); upcase_table[v] = i; } for (i=0;i<256;i++) { smb_ucs2_t v; SSVAL(&v, 0, UCS2_CHAR(i)); upcase_table[v] = UCS2_CHAR(islower(i)?toupper(i):i); } } if (!lowcase_table) { DEBUG(1,("creating lame lowcase table\n")); lowcase_table = SMB_MALLOC(0x20000); for (i=0;i<0x10000;i++) { smb_ucs2_t v; SSVAL(&v, 0, i); lowcase_table[v] = i; } for (i=0;i<256;i++) { smb_ucs2_t v; SSVAL(&v, 0, UCS2_CHAR(i)); lowcase_table[v] = UCS2_CHAR(isupper(i)?tolower(i):i); } } #ifdef HAVE_SETLOCALE /* Restore the old locale. */ if (saved_locale) { setlocale (LC_ALL, saved_locale); SAFE_FREE(saved_locale); } #endif }
/* initialise the message translation subsystem. If the "lang" argument is NULL then get the language from the normal environment variables */ BOOL lang_tdb_init(const char *lang) { char *path = NULL; char *msg_path = NULL; struct stat st; static int initialised; time_t loadtime; BOOL result = False; /* we only want to init once per process, unless given an override */ if (initialised && !lang) return True; if (initialised) { /* we are re-initialising, free up any old init */ if (tdb) { tdb_close(tdb); tdb = NULL; } SAFE_FREE(current_lang); } initialised = 1; if (!lang) { /* no lang given, use environment */ lang = get_lang(); } /* if no lang then we don't translate */ if (!lang) return True; asprintf(&msg_path, "%s.msg", lib_path((const char *)lang)); if (stat(msg_path, &st) != 0) { /* the msg file isn't available */ DEBUG(10, ("lang_tdb_init: %s: %s\n", msg_path, strerror(errno))); goto done; } asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang); DEBUG(10, ("lang_tdb_init: loading %s\n", path)); tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644); if (!tdb) { tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { DEBUG(10, ("lang_tdb_init: %s: %s\n", path, strerror(errno))); goto done; } current_lang = SMB_STRDUP(lang); result = True; goto done; } loadtime = tdb_fetch_int32(tdb, "/LOADTIME/"); if (loadtime == -1 || loadtime < st.st_mtime) { load_msg(msg_path); tdb_store_int32(tdb, "/LOADTIME/", (int)time(NULL)); } current_lang = SMB_STRDUP(lang); result = True; done: SAFE_FREE(msg_path); SAFE_FREE(path); return result; }