int char_driver(int nr,int type,int cn,int ret,int last_action) { int n,val=0; if (nr==0) { if (type==0) player_driver(cn,ret,last_action); return 1; } if (nr<0 || nr>=MAXDRV) { elog("ERROR: Character driver %d out of bounds",nr); return 0; } if ((n=fast_chdrv[nr]) && libs[n].used && load_lib(libs+n) && (val=libs[n].driver(type,nr,cn,ret,last_action))) return val; //xlog("Fast lookup failed for character driver %d.",nr); for (n=1; n<MAXLIB; n++) if (libs[n].used && load_lib(libs+n) && (val=libs[n].driver(type,nr,cn,ret,last_action))) break; if (n==MAXLIB) { elog("ERROR: Could not find character driver %d in any library",nr); return 0; } fast_chdrv[nr]=n; return val; }
static void init_final(void) { char *libname; char *libnames[] = { "libpsport4all.so", "libpsport4gm.so", "libpsport4openib.so", "libpsport4mvapi.so", "libpsport4.so", NULL }; char *libdirs[] = { "", LIBDIR, NULL }; char **ln_p; char **ld_p; char buf[400]; static int initialized = 0; if (initialized) { return; } initialized = 1; intgetenv(&env_debug, ENV_DEBUG); libname = getenv(ENV_LIB); if (libname) { DPRINT(1, "set %s = %s", ENV_LIB, libname); if (load_lib(libname)) return; DPRINT(1, "loading %s failed!", libname); } else { DPRINT(2, "%s not set", ENV_LIB); } for (ln_p = libnames; *ln_p; ln_p++) { for (ld_p = libdirs; *ld_p; ld_p++) { strcpy(buf, *ld_p); strcat(buf, *ln_p); if (load_lib(buf)) return; } } fprintf(stderr, "Cant load one of "); for (ln_p = libnames; *ln_p; ln_p++) { fprintf(stderr, "%s ", *ln_p); } fprintf(stderr, ".\n"); exit(1); }
int script_global_init(lua_State* lua) { load_lib(lua, "_G", luaopen_base); load_lib(lua, LUA_TABLIBNAME, luaopen_table); load_lib(lua, LUA_STRLIBNAME, luaopen_string); load_lib(lua, LUA_IOLIBNAME, luaopen_io); lua_pushcfunction(lua, _syslog); lua_setglobal(lua, "_syslog"); init_qtun_state(lua); init_qtun_conf(lua); init_qtun_log(lua); return 1; }
int main () { int i; pthread_t * tid_srvs; names * nm; ircserver * srvs, * srv; nm = load_names ("configs.xml"); srvs = load_servers ("configs.xml", nm); srv = srvs; load_lib ("/usr/lib/libbbot.so"); load_module ("modules/pong.so"); tid_srvs = (pthread_t *) alloca (servlen (srvs) * sizeof (pthread_t)); for (i = 0; i < servlen (srvs); i++) { pthread_create (&tid_srvs[i], NULL, new_server, (void *) srv); srv = srv->next; } for (i = 0; i < servlen (srvs); i++) pthread_join (tid_srvs[i], NULL); return 0; }
static void * create_frei0r_item ( mlt_profile profile, mlt_service_type type, const char *id, void *arg){ mlt_tokeniser tokeniser = mlt_tokeniser_init ( ); int dircount=mlt_tokeniser_parse_new ( tokeniser, getenv("MLT_FREI0R_PLUGIN_PATH") ? getenv("MLT_FREI0R_PLUGIN_PATH") : FREI0R_PLUGIN_PATH, ":" ); void* ret=NULL; while (dircount--){ char soname[1024]=""; char *save_firstptr = NULL; char *firstname=strtok_r(strdup(id),".",&save_firstptr); firstname=strtok_r(NULL,".",&save_firstptr); sprintf(soname,"%s/%s.so", mlt_tokeniser_get_string( tokeniser , dircount ) , firstname ); if (firstname){ void* handle=dlopen(soname,RTLD_LAZY); if (handle ){ ret=load_lib ( profile , type , handle ); }else{ dlerror(); } } } mlt_tokeniser_close ( tokeniser ); return ret; }
int lamelib_open(void) { int result; result = load_lib(); if (result != 0) { free_lib(); } return result; }
dbc_switch_t * switch_lib::get_switch(int table_id) { dbct_ctx *DBCT = dbct_ctx::instance(); dbc_bboard_t *bbp = DBCT->_DBCT_bbp; if (bbp == NULL || bbversion != bbp->bbparms.bbversion) { if (!load_lib()) return NULL; } return dbc_switch[table_id]; }
const std::string& switch_lib::get_md5sum() { dbct_ctx *DBCT = dbct_ctx::instance(); dbc_bboard_t *bbp = DBCT->_DBCT_bbp; if (bbp == NULL || bbversion != bbp->bbparms.bbversion) { if (!load_lib()) md5sum = ""; } return md5sum; }
static void add_lib(char *name) { int n; for (n=1; n<MAXLIB; n++) { if (!libs[n].used) { libs[n].used=1; strcpy(libs[n].name,name); load_lib(libs+n); return; } } }
/* main */ int main(int argc, char * argv[]) { printf("# 01a-cc\n"); printf("1..16\n"); /* tests */ create_exe(); /* 1-2 make testexe.c and testexe.exe */ run_exe(); /* 2-5 run testexe.exe */ remove_exe(); /* 6-7 remove testexe.c and testexe.exe */ create_lib(); /* 8-9 make testlib.c and testlib.so */ load_lib(); /* 10-14 load and call testfunction */ remove_lib(); /* 15-17 remove testexe.c .o and .so */ return 0; }
static void * create_frei0r_item ( mlt_profile profile, mlt_service_type type, const char *id, void *arg){ mlt_tokeniser tokeniser = mlt_tokeniser_init ( ); char *frei0r_path = get_frei0r_path(); int dircount=mlt_tokeniser_parse_new ( tokeniser, frei0r_path, ":" ); void* ret=NULL; while (dircount--){ char soname[PATH_MAX]; char *myid = strdup( id ); #ifdef WIN32 char *firstname = strtok( myid, "." ); #else char *save_firstptr = NULL; char *firstname = strtok_r( myid, ".", &save_firstptr ); #endif char* directory = mlt_tokeniser_get_string (tokeniser, dircount); #ifdef WIN32 firstname = strtok( NULL, "." ); #else firstname = strtok_r( NULL, ".", &save_firstptr ); #endif if (strncmp(directory, "$HOME", 5)) snprintf(soname, PATH_MAX, "%s/%s" LIBSUF, directory, firstname ); else snprintf(soname, PATH_MAX, "%s%s/%s" LIBSUF, getenv("HOME"), strchr(directory, '/'), firstname ); if (firstname){ void* handle=dlopen(soname,RTLD_LAZY); if (handle ){ ret=load_lib ( profile , type , handle, firstname ); }else{ dlerror(); } } free( myid ); } mlt_tokeniser_close ( tokeniser ); free( frei0r_path ); return ret; }
//Pinyin Phrase Library PinyinPhraseLib::PinyinPhraseLib (const PinyinCustomSettings &custom, const PinyinValidator *validator, PinyinTable *pinyin_table, const char *libfile, const char *pylibfile, const char *idxfile) : m_pinyin_table (pinyin_table), m_validator (validator), m_pinyin_key_less (custom), m_pinyin_key_equal (custom), m_pinyin_phrase_less_by_offset (this, custom), m_pinyin_phrase_equal_by_offset (this, custom) { if (!m_validator) m_validator = PinyinValidator::get_default_pinyin_validator (); load_lib (libfile, pylibfile, idxfile); }
JNIEXPORT void JNICALL Java_com_seleuco_mame4droid_Emulator_init (JNIEnv *env, jclass c, jstring s1, jstring s2) { __android_log_print(ANDROID_LOG_INFO, "mame4droid-jni", "init"); const char *str1 = (*env)->GetStringUTFChars(env, s1, 0); load_lib(str1); (*env)->ReleaseStringUTFChars(env, s1, str1); __android_log_print(ANDROID_LOG_INFO, "mame4droid-jni","calling setVideoCallbacks"); if(setVideoCallbacks!=NULL) setVideoCallbacks(&myJNI_initVideo,&myJNI_dumpVideo,&myJNI_changeVideo); __android_log_print(ANDROID_LOG_INFO, "mame4droid-jni","calling setAudioCallbacks"); if(setAudioCallbacks!=NULL) setAudioCallbacks(&myJNI_openAudio,&myJNI_dumpAudio,&myJNI_closeAudio); __android_log_print(ANDROID_LOG_INFO, "mame4droid-jni","calling setNetplayCallbacks"); if(setNetplayCallbacks!=NULL) setNetplayCallbacks(&myJNI_netplayWarn); const char *str2 = (*env)->GetStringUTFChars(env, s2, 0); __android_log_print(ANDROID_LOG_INFO, "mame4droid-jni", "path %s",str2); setGlobalPath(str2); (*env)->ReleaseStringUTFChars(env, s2, str2); //int i = pthread_create(&main_tid, NULL, app_Thread_Start, NULL); //if(i!=0)__android_log_print(ANDROID_LOG_ERROR, "mame4droid-jni", "Error setting creating pthread %d",i); //struct sched_param param; //param.sched_priority = 63; //param.sched_priority = 46; //param.sched_priority = 100; /* if(pthread_setschedparam(main_tid, SCHED_RR, ¶m) != 0) { __android_log_print(ANDROID_LOG_ERROR, "mame4droid-jni", "Error setting pthread priority"); return; } */ }
void init_libs() { char **lib_physfs_list; char **i; lib_details *d, *tmp; printf("lib_tools.c:init_libs() - Locate libraries:\n"); lib_physfs_list = PHYSFS_enumerateFiles("libs"); for(i=lib_physfs_list; *i != NULL; i++) { printf("%s\n",*i); #ifdef __APPLE__ if(strlen(*i) > 6 && !strcmp(*i + strlen(*i) - 6, ".dylib")) { #elif __MINGW32__ if(strlen(*i) > 4 && !strcmp(*i + strlen(*i) - 4, ".dll")) { #else if(strlen(*i) > 3 && !strcmp(*i + strlen(*i) - 3, ".so")) { #endif // I know this isn't portable, but f**k it d = malloc(sizeof(lib_details)); strncpy(d->filename,*i,MAX_LIBFN_LEN); d->loaded = 0; LL_APPEND(libs_list,d); printf("lib_tools.c:init_libs() - Located %s\n", *i); } } PHYSFS_freeList(lib_physfs_list); printf("lib_tools.c:init_libs() - Start cache system:\n"); init_lib_cache(); printf("lib_tools.c:init_libs() - Refreshing cache:\n"); LL_FOREACH_SAFE(libs_list,d,tmp) { refresh_lib_cache(d->filename); } printf("lib_tools.c:init_libs() - Loading libs:\n"); LL_FOREACH_SAFE(libs_list,d,tmp) { printf("lib_tools.c:init_libs() - Loading %s:\n",d->filename); load_lib(d->filename); } }
int main(int argc,char *argv[]) { void *wam; char *query; char *answer; if(load_lib("cproject")>0) return 1; /* instead of argc, argv command line args - we set up ours here */ { int my_argc=3; char *my_argv[]={ argv[0], /* passes arg[0] as such */ "call((println(hello)))", /* goal to be pased to BinProlog */ "-q2", /* level of 'quietness'; more/less output' */ NULL }; wam=(*ptr_init_bp)(my_argc,my_argv,NULL,NULL); if(NULL==wam) return 1; } query="__X:-member(__X,[10,20])"; answer=(*ptr_run_bp)(wam,query); if(NULL==answer) answer="no"; printf("query=>%s\nanswer=>%s\n",query,answer); query="assert(a(newly_asserted(3)))"; answer=(*ptr_run_bp)(wam,query); query="Xs:-findall(X,a(X),Xs)"; answer=(*ptr_run_bp)(wam,query); if(NULL==answer) answer="no"; printf("query=>%s\nanswer=>%s\n",query,answer); //query="main"; //answer=(*ptr_run_bp)(wam,query); free_bp_lib(); return 0; }
int main() { complex_t a, b, res; int op; void *lib; DIR *dir; struct dirent *entry; int n_dir; dir = opendir("./lib"); if (!dir) { perror("diropen"); exit(1); } for (n_dir = 0; (entry = readdir(dir)) != NULL; n_dir++) ; closedir(dir); char **arr_dir = (char **) calloc(n_dir, sizeof(char**)); if (!arr_dir) { printf("Ошибка при распределении памяти\n"); exit(1); } printf("\n"); while(1) { printf("Введите два числа:\n"); printf("a.re: "); scanf("%f", &a.r); printf("a.im: "); scanf("%f", &a.i); printf("b.re: "); scanf("%f", &b.r); printf("b.im: "); scanf("%f", &b.i); dir = opendir("./lib"); int c = 0; printf("\nВыберите библиотеку:\n"); while ((entry = readdir(dir)) != NULL) { if (strcmp(".", entry->d_name) && strcmp("..", entry->d_name)) { printf("%d) %s\n", c+1, entry->d_name); arr_dir[c] = (char *) calloc(200, sizeof(char)); strcpy(arr_dir[c], entry->d_name); c++; } } printf("> "); scanf("%d", &op); char tmp_path[strlen(arr_dir[op-1]) + 6]; bzero(tmp_path, sizeof(tmp_path)); strcat(tmp_path, "./lib/"); strcat(tmp_path, arr_dir[op-1]); printf("%s\n", arr_dir[op-1]); lib = load_lib(tmp_path); complex_t (*cplx_op_ptr) (complex_t a, complex_t b); /* Вырезаем lib и .so (libcplx_add.so -> cplx_add)*/ for (c = 3; arr_dir[op-1][c] != '.'; c++) tmp_path[c-3] = arr_dir[op-1][c]; tmp_path[c-3] = '\0'; cplx_op_ptr = dlsym(lib, tmp_path); res = (*cplx_op_ptr)(a, b); cplx_out(res); dlclose(lib); } int i; for (i = 0; i < n_dir; i++) free(arr_dir[i]); free(arr_dir); return 0; }
int item_driver(int nr,int in,int cn) { int n,tmp=0; if (nr==0) { if (cn) look_item(cn,it+in); return 1; } if (nr>=1000) return 1; // identity tag if (nr<0 || nr>=MAXDRV) { elog("ERROR: Item driver %d out of bounds",nr); return 0; } switch(nr) { case IDR_BONEBRIDGE: if (areaID!=18) { if (cn) log_char(cn,LOG_SYSTEM,0,"This does not work outside its area."); return 1; } break; case IDR_BONEHINT: if (areaID!=18) { if (cn) log_char(cn,LOG_SYSTEM,0,"This does not work outside its area."); return 1; } break; case IDR_NOMADDICE: if (areaID!=19) { if (cn) log_char(cn,LOG_SYSTEM,0,"This does not work outside its area."); return 1; } break; case IDR_STAFFER2: if (areaID!=29) { if (cn) log_char(cn,LOG_SYSTEM,0,"This does not work outside its area."); return 1; } break; case IDR_OXYPOTION: if (areaID!=31) { if (cn) log_char(cn,LOG_SYSTEM,0,"This does not work outside its area."); return 1; } break; case IDR_LIZARDFLOWER: if (areaID!=31) { if (cn) log_char(cn,LOG_SYSTEM,0,"This does not work outside its area."); return 1; } break; case IDR_CALIGAR: if (areaID!=36) { if (cn) log_char(cn,LOG_SYSTEM,0,"This does not work outside its area."); return 1; } break; case IDR_ARKHATA: if (areaID!=37) { if (cn) log_char(cn,LOG_SYSTEM,0,"This does not work outside its area."); return 1; } break; } if ((n=fast_itdrv[nr]) && libs[n].used && load_lib(libs+n) && (tmp=libs[n].driver(CDT_ITEM,nr,in,cn,0))) return tmp; //xlog("Fast lookup failed for item driver %d.",nr); for (n=1; n<MAXLIB; n++) if (libs[n].used && load_lib(libs+n) && (tmp=libs[n].driver(CDT_ITEM,nr,in,cn,0))) break; if (n==MAXLIB) { elog("ERROR: Could not find item driver %d in any library",nr); return 0; } fast_itdrv[nr]=n; return tmp; }