static int win_CreateDir(lua_State *L) { BOOL result, opt_tolerant, opt_original; const wchar_t* path = check_utf8_string(L, 1, NULL); const char* flags = ""; if (lua_type(L,2) == LUA_TSTRING) flags = lua_tostring(L,2); else if (lua_toboolean(L,2)) flags = "t"; opt_tolerant = strchr(flags,'t') != NULL; opt_original = strchr(flags,'o') != NULL; if(dir_exist(path)) { if (opt_tolerant) return lua_pushboolean(L,1), 1; return lua_pushnil(L), lua_pushliteral(L, "directory already exists"), 2; } result = opt_original ? CreateDirectoryW(path,NULL) : mkdir(path); if(result) return lua_pushboolean(L, 1), 1; return SysErrorReturn(L); }
void Plugin_Scan(std::string Path) { DIR *pdir; struct dirent *dirp; if ((pdir = opendir(Path.c_str()))) { while ((dirp = readdir(pdir))) { if ((strcmp(dirp->d_name, ".")) && (strcmp(dirp->d_name, ".."))) { std::string filename = Path + "/" + dirp->d_name; if (dir_exist(filename.c_str())) Plugin_Scan(filename); else { if (!strcmp(&dirp->d_name[strlen(dirp->d_name)-strlen(PluginEXT)], PluginEXT)) { void *handle = dlopen(filename.c_str(), RTLD_LAZY); if (handle) { #ifdef WIN32 void (*CallBack_Plugin)(void**) = (void(*)(void**))dlsym(handle, "CallBack_Plugin"); if (CallBack_Plugin) (CallBack_Plugin)(CallBack_Plugin_Link); #endif plugin_t* Plugin_l = (plugin_t*)dlsym(handle, "Plugin"); Plugin_l->handle = handle; Plugin_l->init(); dlclose(handle); handle = NULL; } } } } } closedir(pdir); } }
struct ext2_dir_entry_2 * recurse_inode(struct ext2_inode *inode_ptr, char *path_array[10], int path_array_len, int index, int bg_inode_table) { int block_id; // to record the number of used block if(path_array_len == 1) { // case: path is the root path int i = 0; while(i < 11) { if (inode_ptr->i_block[i] > 0) { // the block is in use block_id = inode_ptr->i_block[i]; struct ext2_dir_entry_2 *ptr_dir = (struct ext2_dir_entry_2 *)(ptr_disk + EXT2_BLOCK_SIZE * block_id); return ptr_dir; } i++; } } int i = 0; while (i < 12) { if (inode_ptr->i_block[i] > 0) { block_id = inode_ptr->i_block[i]; struct ext2_dir_entry_2 *ptr_dir = (struct ext2_dir_entry_2 *)(ptr_disk + EXT2_BLOCK_SIZE * block_id); // check if the dir exists and find its inode number int dir_inode_ptr = dir_exist(ptr_dir, path_array[index]); if(dir_inode_ptr != 0) { // case: the dir exists if(path_array_len - index == 2) { struct ext2_inode *inode_ptr2 = (struct ext2_inode *)(ptr_disk + EXT2_BLOCK_SIZE * bg_inode_table); inode_ptr2 += dir_inode_ptr-1; block_id = inode_ptr2->i_block[i ]; ptr_dir = (struct ext2_dir_entry_2 *)(ptr_disk + EXT2_BLOCK_SIZE * block_id); return ptr_dir; } else if (path_array_len - index == 1){ return 0; } else { struct ext2_inode *inode_ptr2 = (struct ext2_inode *)(ptr_disk + EXT2_BLOCK_SIZE * bg_inode_table); inode_ptr2 += dir_inode_ptr-1; return recurse_inode(inode_ptr2, path_array, path_array_len, index+1, bg_inode_table); } } } i ++; } return 0; }
obj3D * model3D_mgr::add_InternalObj(string name) { string repertory=obj3DDir+"/"+name; if ( dir_exist(repertory) ) { if ( (file_exist(repertory+"/"+name+"_1L.obj")) && (file_exist(repertory+"/"+name+"_2M.obj")) && (file_exist(repertory+"/"+name+"_3H.obj")) ) { obj3D *tmp = new obj3D; tmp->name= name; tmp->low = new model3D(); tmp->low->init(name+"/"+name+"_1L"); tmp->medium = new model3D(); tmp->medium->init(name+"/"+name+"_2M"); tmp->high = new model3D(); tmp->high->init(name+"/"+name+"_3H"); if (tmp->low->getOk() && tmp->medium->getOk() && tmp->high->getOk()) { //~ printf("correct\n"); obj3DList.push_back(tmp); return tmp; } else { printf("erreur de chargement d'un model3D\n"); //on détruit l'objet puisqu'il n'est pas complet delete tmp; return NULL; } } else { printf("le dossier du model3D n'existe pas\n"); return NULL; } //pour que le compilateur ne rale pas return NULL; } else return NULL; }
void Plugin_Scan(std::string Path) { DIR *pdir; struct dirent *dirp; if ((pdir = opendir(Path.c_str()))) { while ((dirp = readdir(pdir))) { if ((strcmp(dirp->d_name, ".")) && (strcmp(dirp->d_name, ".."))) { std::string filename = Path + "/" + dirp->d_name; if (dir_exist(filename.c_str())) Plugin_Scan(filename); else { if (!strcmp(&dirp->d_name[strlen(dirp->d_name)-strlen(PluginEXT)], PluginEXT)) { void *handle = dlopen(filename.c_str(), RTLD_LAZY); if (handle) { #ifdef WIN32 void (*CallBack_Plugin)(void**) = (void(*)(void**))dlsym(handle, "CallBack_Plugin"); if (CallBack_Plugin) (CallBack_Plugin)(CallBack_Plugin_Link); #endif plugin_t* Plugin_l = (plugin_t*)dlsym(handle, "Plugin"); Plugin_l->handle = handle; if (Plugin_l->init) Plugin_l->init(); DEBUG("-->\n"); for (int i=0; Plugin_l->recv && Plugin_l->recv[i].name; i++) { DEBUG(" %s\n", Plugin_l->recv[i].name); if (Plugin_l->recv[i].func) Sharun->OpCodes.Set_Recv(Plugin_l->recv[i].name, Plugin_l->recv[i].func); } /* dlclose(handle); handle = NULL;*/ } } } } } closedir(pdir); } }
void prepare_input(dr_metalib_builder_t builder, error_monitor_t em) { int i; for(i = 0; i < input->count; ++i) { const char * filename; size_t filename_len; filename = input->filename[i]; filename_len = strlen(filename); if (filename[filename_len - 1] == '\\' || filename[filename_len - 1] == '/') { ((char *)filename)[filename_len - 1] = 0; } if (dir_exist(filename, em)) { dir_search(&g_input_search_visitor, builder, filename, 5, em, NULL); } else if (file_exist(input->filename[i], em)) { dr_metalib_builder_add_file(builder, NULL, filename); } else { CPE_ERROR(em, "input %s not exist!", filename); } } }
bool assure_dir_exist( const std::string &path ) { return do_mkdir( path, 0777 ) || ( errno == EEXIST && dir_exist( path ) ); }
bool assure_dir_exist( const std::string &path ) { return dir_exist( path ) || do_mkdir( path, 0777 ); }
int vfu_get_dir_name( const char *prompt, VString &target, int should_exist ) { int res = -1; /* #ifdef _TARGET_UNIX_ leaveok(stdscr, FALSE); #endif */ VArray dir_list; say1(prompt); say2(""); int pos = 0; int page = 0; int ch = 0; int insert = 1; int firsthit = 1; pos = str_len( target ); //------------------------------------------------------------------ con_cshow(); say2( target, firsthit ? cINPUT2 : cINPUT ); while(1) { int mx = con_max_x() - 1; VString target_out = target; if ( (pos < page) || (pos+1 > page + mx) || (page > 0 && pos == page) ) page = pos - mx / 2; if ( page < 0 ) page = 0; str_trim_left( target_out, page ); str_sleft( target_out, mx ); str_pad( target_out, -mx ); if ( page > 0 ) str_set_ch( target_out, 0, '<' ); if ( str_len( target ) - page > mx ) str_set_ch( target_out, mx-1, '>' ); say2( target_out, firsthit ? cINPUT2 : cINPUT ); con_xy( pos-page+1, con_max_y() ); if (ch == 0) ch = con_getch(); if (ch == '\\') ch = '/'; /* dos hack :)) */ if ( ch == '/' && str_find( target, '/' ) == -1 && target[0] == '~' ) { target = tilde_expand( target ); str_fix_path( target ); pos = str_len( target ); ch = 0; } if ((ch == 8 || ch == KEY_BACKSPACE) && pos > 0) { pos--; str_del( target, pos, 1 ); } else if (ch == KEY_CTRL_A && str_len( target ) > 0) { int z = str_len( target )-1; if ( str_get_ch(target, z) == '/' ) z--; while ( z > 0 && str_get_ch(target,z) != '/' ) z--; z++; str_sleft(target,z); pos = z; } else if ( ch == 9 && str_len( target ) > 0) { int z; dir_list.undef(); VString dmain; /* main/base path */ VString dtail; /* item that should be expanded/glob */ dmain = str_file_path( target ); dtail = str_file_name_ext( target ); /* int lastslash = str_rfind(target, '/'); if ( lastslash == -1 ) { dmain = ""; dtail = target; } else { dmain = target; dtail = target; str_sleft( dmain, lastslash+1 ); str_trim_left( dtail, lastslash+1 ); } */ __glob_gdn( dmain, dtail, dir_list ); z = dir_list.count()-1; if (dir_list.count()) { if ( dir_list.count() > 1) { int mc = 0; /* match count */ int mi = 0; /* match letter index */ while(4) { mc = 0; int li; /* counter */ for ( li = 0; li < dir_list.count(); li++ ) { if ( str_get_ch( dir_list[ 0], mi ) == str_get_ch( dir_list[li], mi ) ) mc++; } if ( mc != dir_list.count() ) break; mi++; } target.setn( dmain + dir_list[0], str_len( dmain ) + mi ); pos = str_len( target ); say2( target, cINPUT ); con_xy( pos+1, con_max_y() ); vfu_beep(); ch = con_getch(); if ( ch != 9 ) { dir_list.undef(); continue; } dir_list.sort(); con_chide(); z = vfu_menu_box( 10, 5, "Complete...", &dir_list ); con_cshow(); ch = 0; } else ch = 0; if ( z != -1 ) { while( str_len( target ) > 0 && target[-1] != '/' ) str_chop( target ); target += dir_list[z]; } pos = str_len( target ); dir_list.undef(); if (ch != 0) continue; } else { /* no match found -- cannot complete */ vfu_beep(); } } else if (ch == 13) { res = 1; break; } else if (ch == 27) { target = ""; res = 0; break; } if (ch == KEY_CTRL_U) { target = ""; pos = 0; } else if (ch == KEY_CTRL_X) { char t[MAX_PATH]; if ( target[0] == '~' ) target = tilde_expand( target ); expand_path( target, t ); str_fix_path( t ); target = t; pos = str_len( target ); } else if (ch >= 32 && ch <= 255 ) // && pos < 70) { if (firsthit) { target = ""; pos = 0; } if (!insert) str_del( target, pos, 1 ); str_ins_ch( target, pos, ch ); pos++; } else if( ch == KEY_LEFT ) { if (pos > 0) pos--; } else if( ch == KEY_RIGHT ) { if (pos < str_len( target )) pos++; } else if ( ch == KEY_IC ) insert = !insert; else if ( ch == KEY_HOME ) pos = 0; else if ( ch == KEY_END ) pos = str_len(target); else if ( ch == KEY_DC && pos < str_len(target) ) str_del( target, pos, 1 ); else if ( ch == KEY_NPAGE || ch == KEY_PPAGE ) { con_chide(); int zz = vfu_hist_menu( 5, 5, ( ch == KEY_PPAGE ) ? "Dir Entry History" : "ChDir History", ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR ); con_cshow(); if (zz != -1) { const char* pc = vfu_hist_get( ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR, zz ); if ( pc ) { target = pc; pos = str_len( target ); } } } ch = 0; firsthit = 0; } con_chide(); //------------------------------------------------------------------ str_cut_spc( target ); if ( res == 1 && target[0] == '~' ) { target = tilde_expand( target ); str_fix_path( target ); } /* if ( target.len() > 0 ) { // well this tmp is kind of s... ama k'vo da pravi chovek :) // FIXME: dos version? if ( __ExpandGetDirName && target[0] != '/' #ifdef _TARGET_GO32_ && !( target[1] == ':' && target[2] == '/' ) #endif ) target = CPath + target; StrFixPath( target ); // add trailing slash if not exist } */ /* #ifdef _TARGET_UNIX_ leaveok(stdscr, TRUE); #endif */ if ( res == 1 && str_len( target ) > 0 && should_exist && !dir_exist( target )) { vfu_beep(); int ch = tolower( vfu_ask( "Directory does not exist! Create? " "( ENTER=Yes, ESC=cancel )", "\033\rcC" )); if ( ch == 27 ) { res = 0; target = ""; } else if ( ch == 13 ) if (make_path( target )) { if(tolower( vfu_ask( "Cannot create path! ( ESC=cancel, C=continue-anyway )", "\033Cc" )) == 27) { res = 0; target = ""; } } } say1(" "); say2(" "); if ( str_len( target ) > 0) { str_fix_path( target ); vfu_hist_add( HID_GETDIR, target ); } str_cut_spc( target ); ASSERT( res == 0 || res == 1 ); return res; }
void vfu_chdir( const char *a_new_dir ) { char t[MAX_PATH]; VString target; if ( a_new_dir && a_new_dir[0] ) { target = a_new_dir; str_fix_path( target ); } else { target = vfu_hist_get( HID_CHDIR, 0 ); if (!vfu_get_dir_name( "ChDir to? (TAB, PageUp, PageDown, ^X, ^A)", target, 0 )) return; /* get_dir_name canceled */ } /* get_dir_name confirmed */ /* if ( work_path[0] != target[0] && DirTreeChanged && opt.AutoTree ) SaveTree(); */ if ( work_mode == WM_ARCHIVE ) { archive_name = ""; archive_path = ""; } vfu_hist_add( HID_CHDIR, work_path ); char ch = work_path[0]; if (opt.tree_cd) if (!dir_exist( target )) { int z = 0; if ( dir_tree.count() == 0 ) tree_load(); mb.undef(); z = tree_find( target, &mb ); if (z > 1) { z = vfu_menu_box( 10, 5, "Change dir to..." ); if (z > -1) target = mb.get(z); else return; } else if (z == 1) target = mb.get(0); } VString str = target; str_cut_spc( str ); #ifdef _TARGET_GO32_ if ( str[0] == '/' ) { str_ins_ch( str, 0, ':' ); str_ins_ch( str, 0, work_path[0] ); } else if ( str[1] == ':' && str[2] == 0 ) /* c: d: e: */ { expand_path( str, t ); str = t; } if ( str[1] == ':' && str[2] == '/' ) #else /* _TARGET_GO32_ -> i.e. _TARGET_UNIX_ here*/ if (str[0] == '/') #endif /* _TARGET_GO32_ */ { /* root directory */ target = str; } else { str = work_path + str; str_fix_path( str ); target = str_reduce_path( str ); } if (chdir( target ) != 0) { sprintf( t, "chdir: %s", target.data() ); say1( t ); say2errno(); return; } else { work_path = target; if ( work_mode == WM_ARCHIVE ) work_mode = WM_NORMAL; } if ( ch != work_path[0] ) tree_drop(); /* drop tree--it is for another drive*/ vfu_read_files(); }