/** * Loads a Lua file and pushes the contents on the stack. * - Arg 1: string containing the file name. * - Ret 1: the loaded contents of the file */ int load_file(lua_State *L) { std::string m = luaL_checkstring(L, -1); std::string current_dir = ""; lua_Debug ar; if(lua_getstack(L, 1, &ar)) { lua_getinfo(L, "S", &ar); if(ar.source[0] == '@') { current_dir = filesystem::directory_name(std::string(ar.source + 1)); } } if(!resolve_filename(m, current_dir)) { return luaL_argerror(L, -1, "file not found"); } std::string p = filesystem::get_wml_location(m); if (p.empty()) { return luaL_argerror(L, -1, "file not found"); } try { if(lua_filestream::lua_loadfile(L, p, m)) { return lua_error(L); } } catch(const std::exception & ex) { luaL_argerror(L, -1, ex.what()); } lua_remove(L, -2); //remove the filename from the stack return 1; }
//----------------------------------------------------------------------------- //start threads //----------------------------------------------------------------------------- void CDataLoader::start_threads() { int N = m_chunkNum[0] * m_chunkNum[1] * m_chunkNum[2]; if(m_threads){ delete[] m_threads; m_threads = 0; } if(m_threads == 0) m_threads = new boost::thread[N]; //allocate data pointer for all N chunks; //if data too large may not need to allocate all N, maybe smaller number if(m_data_chunks == 0) m_data_chunks = (void**)malloc(N * sizeof(void*)); int fileOrigin[4] = {0,0,0,0}; for(int i=0; i<N; i++) { char filename[128]; resolve_filename(filename, i); //each chunk in separate file m_threads[i] = boost::thread(boost::bind(&read_data_fromfile, m_data_chunks[i], m_fileType, m_dataType, m_component, m_chunkDims, filename, m_datasetName.c_str(), fileOrigin, m_chunkDims)); resolve_chunk_origin(i); } }
//----------------------------------------------------------------------------- //used in application init, load data in full amount, ***NON-PROGRESSIVE*** //----------------------------------------------------------------------------- void CDataLoader::load_data() { //DL_SINGLE + DL_BLOCKING = NON-PROGRESSING DATA LOADING assert(m_dataDist == DL_SINGLE && m_dataLoadmode == DL_BLOCKING); //no chunks. Read in the whole brick char filename[128]; resolve_filename(filename, -1); //std::cout << filename <<"\n"; //read_data_fromfile is static function read_data_fromfile(m_data, m_fileType, m_dataType, m_component, &m_full_dataDims[0], filename, m_datasetName.c_str(), m_brickOrigin, m_brickDims); memcpy(m_avDims, m_brickDims, 3*sizeof(int)); memset(m_avOrigin, 0, 4*sizeof(int)); memcpy(m_avPadding, m_brickPadding, 6*sizeof(int)); //this is wrong. av is relative to the brick(include brick padding) //, origin[0, 0, 0], dim equals to brick dim //for(int i=0; i<3; i++) m_avOrigin[i] -= m_avPadding[2*i]; }
/** * Checks if a file exists (not necessarily a Lua script). * - Arg 1: string containing the file name. * - Arg 2: if true, the file must be a real file and not a directory * - Ret 1: boolean */ int intf_have_file(lua_State *L) { std::string m = luaL_checkstring(L, 1); if(!resolve_filename(m, get_calling_file(L))) { lua_pushboolean(L, false); } else if(luaW_toboolean(L, 2)) { lua_pushboolean(L, !filesystem::is_directory(m)); } else { lua_pushboolean(L, true); } return 1; }
/** * Reads a file into a string, or a directory into a list of files therein. * - Arg 1: string containing the file name. * - Ret 1: string */ int intf_read_file(lua_State *L) { std::string p = luaL_checkstring(L, 1); if(!resolve_filename(p, get_calling_file(L))) { return luaL_argerror(L, -1, "file not found"); } if(filesystem::is_directory(p)) { std::vector<std::string> files, dirs; filesystem::get_files_in_dir(p, &files, &dirs); filesystem::default_blacklist.remove_blacklisted_files_and_dirs(files, dirs); std::size_t ndirs = dirs.size(); std::copy(files.begin(), files.end(), std::back_inserter(dirs)); lua_push(L, dirs); lua_pushnumber(L, ndirs); lua_setfield(L, -2, "ndirs"); return 1; } const std::unique_ptr<std::istream> fs(filesystem::istream_file(p)); fs->exceptions(std::ios_base::goodbit); std::size_t size = 0; fs->seekg(0, std::ios::end); if(!fs->good()) { return luaL_error(L, "Error when reading file"); } size = fs->tellg(); fs->seekg(0, std::ios::beg); if(!fs->good()) { return luaL_error(L, "Error when reading file"); } luaL_Buffer b; luaL_buffinit(L, &b); //throws an exception if malloc failed. char* out = luaL_prepbuffsize(&b, size); fs->read(out, size); if(fs->good()) { luaL_addsize(&b, size); } luaL_pushresult(&b); return 1; }
/** * Checks if a file exists (not necessarily a Lua script). * - Arg 1: string containing the file name. * - Ret 1: string */ int intf_read_file(lua_State *L) { std::string m = luaL_checkstring(L, 1); std::string current_dir = ""; lua_Debug ar; if(lua_getstack(L, 1, &ar)) { lua_getinfo(L, "S", &ar); if(ar.source[0] == '@') { current_dir = filesystem::directory_name(std::string(ar.source + 1)); } } if(!resolve_filename(m, current_dir)) { return luaL_argerror(L, -1, "file not found"); } std::string p = filesystem::get_wml_location(m); if(p.empty()) { return luaL_argerror(L, -1, "file not found"); } boost::scoped_ptr<std::istream> fs(filesystem::istream_file(p)); fs->exceptions(std::ios_base::goodbit); size_t size = 0; fs->seekg(0, std::ios::end); if(!fs->good()) { return luaL_error(L, "Error when reading file"); } size = fs->tellg(); fs->seekg(0, std::ios::beg); if(!fs->good()) { return luaL_error(L, "Error when reading file"); } luaL_Buffer b; luaL_buffinit(L, &b); //throws an exception if malloc failed. char* out = luaL_prepbuffsize(&b, size); fs->read(out, size); if(fs->good()) { luaL_addsize(&b, size); } luaL_pushresult(&b); return 1; }
int pvfsopen( pfile * pf,char * file_name , char *mode) { int ret = 0 ; //file_object src; memset(pf, 0 , sizeof(struct file_object_s)); resolve_filename(pf, file_name); if ('r' == *mode) { ret=generic_open(pf, &credentials,0,0,NULL,OPEN_SRC); } if('w' == *mode) { ret=generic_open(pf, &credentials,0,0,NULL,OPEN_DEST); } if( ret < 0) { fprintf(stderr, "Could not open"); return (-1); } }
//----------------------------------------------------------------------------- //load a chunk in progressive data loading, DL_BLOCKING + DL_CHUNK //----------------------------------------------------------------------------- void CDataLoader::loaddata_chunk(int cid) { char filename[128]; resolve_filename(filename, cid); //std::cout << "chunk: " << cid << ", filename: " << filename <<"\n"; int fileOrigin[4] = {0,0,0,0}; read_data_fromfile(m_data, m_fileType, m_dataType, m_component, m_chunkDims, filename, m_datasetName.c_str(), fileOrigin, m_chunkDims); resolve_chunk_origin(cid); resolve_av_attr(); }
/** * Loads a Lua file and pushes the contents on the stack. * - Arg 1: string containing the file name. * - Ret 1: the loaded contents of the file */ int load_file(lua_State *L) { std::string p = luaL_checkstring(L, -1); std::string rel; if(!resolve_filename(p, get_calling_file(L), &rel)) { return luaL_argerror(L, -1, "file not found"); } try { if(lua_filestream::lua_loadfile(L, p, rel)) { return lua_error(L); } } catch(const std::exception & ex) { luaL_argerror(L, -1, ex.what()); } lua_remove(L, -2); //remove the filename from the stack return 1; }
/****************************************************************** * HtmlHelpW (HHCTRL.OCX.15) */ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data) { WCHAR fullname[MAX_PATH]; TRACE("(%p, %s, command=%s, data=%lx)\n", caller, debugstr_w( filename ), command_to_string( command ), data); switch (command) { case HH_DISPLAY_TOPIC: case HH_DISPLAY_TOC: case HH_DISPLAY_SEARCH:{ static const WCHAR delimW[] = {':',':',0}; HHInfo *info; BOOL res; WCHAR chm_file[MAX_PATH]; const WCHAR *index; FIXME("Not all HH cases handled correctly\n"); if (!filename) return NULL; index = strstrW(filename, delimW); if (index) { memcpy(chm_file, filename, (index-filename)*sizeof(WCHAR)); chm_file[index-filename] = 0; filename = chm_file; index += 2; /* advance beyond "::" for calling NavigateToChm() later */ } if (!resolve_filename(filename, fullname, MAX_PATH)) { WARN("can't find %s\n", debugstr_w(filename)); return 0; } info = CreateHelpViewer(fullname); if(!info) return NULL; if(!index) index = info->WinType.pszFile; res = NavigateToChm(info, info->pCHMInfo->szFile, index); if(!res) { ReleaseHelpViewer(info); return NULL; } return info->WinType.hwndHelp; } case HH_HELP_CONTEXT: { HHInfo *info; LPWSTR url; if (!filename) return NULL; if (!resolve_filename(filename, fullname, MAX_PATH)) { WARN("can't find %s\n", debugstr_w(filename)); return 0; } info = CreateHelpViewer(fullname); if(!info) return NULL; url = FindContextAlias(info->pCHMInfo, data); if(!url) { ReleaseHelpViewer(info); return NULL; } NavigateToUrl(info, url); heap_free(url); return info->WinType.hwndHelp; } case HH_PRETRANSLATEMESSAGE: { static BOOL warned = FALSE; if (!warned) { FIXME("HH_PRETRANSLATEMESSAGE unimplemented\n"); warned = TRUE; } return 0; } default: FIXME("HH case %s not handled.\n", command_to_string( command )); } return 0; }