int main(int argc, char **argv) { assert_cmpnum(argc, 2); int openfd = dup(1); int dirfd = -1; assert_cmpnum_op(openfd, >, 0); std::string exepath(argv[1]); std::string::size_type slpos = exepath.rfind('/'); exepath.erase(slpos); check_guard(openfd, dirfd, exepath); check_notdir(argv[1], exepath); assert_cmpnum_op(dirfd, >, 0); struct stat st; // the descriptors should be closed now, so fstat() should fail assert_cmpnum(fstat(openfd, &st), -1); assert_cmpnum(fstat(dirfd, &st), -1); return 0; }
void rbenv_initialize(char *argv0) { if (!rbenv_exepath) { rbenv_exepath = exepath(argv0); rbenv_initialize_debug_mode(); rbenv_initialize_root(); rbenv_initialize_dir(); rbenv_initialize_path(); rbenv_initialize_hook_path(); } }
/* * Print the path to this executable. */ int main() { wchar_t *path; path = exepath(); if (path == NULL) { wprintf(L"Sorry, an error occured.\n"); return 1; } wprintf(L"Path to executable: %ls\n", path); free(path); return 0; }
int main (int argc, char * const argv[]) { chdir(exepath(argv[0])); script = argv[1]; // char path[1024]; // getcwd(path, 1024); // //printf("cwd %s\n", path); al::Lua L; al::AudioIO audioIO(1024, 44100, audioCB, &L, 2,2); io = &audioIO; L.dostring("print(jit.version)"); L.dostring("print(package.path)"); L.preloadlib("audio", luaopen_audio); // run main script... L.dofile(script); L.push(audioIO.framesPerBuffer()); L.setglobal("blocksize"); L.push(audioIO.framesPerSecond()); L.setglobal("samplerate"); audioIO.start(); active = 1; // wait for input while (active and getchar()) { // sleep or wait on repl //al_sleep(0.01); script = argv[1]; } printf("done\n"); audioIO.stop(); return 0; }
previewer::ParticleData Previewer::Load() { char pathbuf[MAX_PATH]; GetModuleFileNameA(NULL, pathbuf, MAX_PATH); // Remove executable name from path int len = 0; std::string exepath(pathbuf); for (unsigned i = exepath.length() - 1; i > 0; i--) { if (exepath.at(i) == '\\') { exepath.erase(exepath.begin() + i + 1, exepath.end()); break; } } // Tell the particle simulation to load data //paramfile* splotchParams = Previewer::parameterInfo.GetParamFileReference(); particles.Load(); return particles; }
std::vector<std::string> default_search_paths() { std::vector<std::string> paths; #ifdef CHAISCRIPT_WINDOWS // force no unicode CHAR path[4096]; int size = GetModuleFileNameA(0, path, sizeof(path) - 1); std::string exepath(path, size); size_t lastslash = exepath.rfind('\\'); size_t secondtolastslash = exepath.rfind('\\', lastslash - 1); if (lastslash != std::string::npos) { paths.push_back(exepath.substr(0, lastslash)); } if (secondtolastslash != std::string::npos) { return{ exepath.substr(0, secondtolastslash) + "\\lib\\chaiscript\\" }; } #else std::string exepath; std::vector<char> buf(2048); ssize_t size = -1; if ((size = readlink("/proc/self/exe", &buf.front(), buf.size())) > 0) { exepath = std::string(&buf.front(), static_cast<size_t>(size)); } if (exepath.empty()) { if ((size = readlink("/proc/curproc/file", &buf.front(), buf.size())) > 0) { exepath = std::string(&buf.front(), static_cast<size_t>(size)); } } if (exepath.empty()) { if ((size = readlink("/proc/self/path/a.out", &buf.front(), buf.size())) > 0) { exepath = std::string(&buf.front(), static_cast<size_t>(size)); } } if (exepath.empty()) { Dl_info rInfo; memset(&rInfo, 0, sizeof(rInfo)); if (!dladdr(cast_module_symbol(&default_search_paths), &rInfo) || !rInfo.dli_fname) { return paths; } exepath = std::string(rInfo.dli_fname); } size_t lastslash = exepath.rfind('/'); size_t secondtolastslash = exepath.rfind('/', lastslash - 1); if (lastslash != std::string::npos) { paths.push_back(exepath.substr(0, lastslash)); } if (secondtolastslash != std::string::npos) { paths.push_back(exepath.substr(0, secondtolastslash) + "/lib/chaiscript/"); } #endif return paths; }
std::string getExecutablePath() { #if ARX_PLATFORM == ARX_PLATFORM_MACOSX uint32_t bufsize = 0; // Obtain required size _NSGetExecutablePath(NULL, &bufsize); std::vector<char> exepath(bufsize); if(_NSGetExecutablePath(&exepath.front(), &bufsize) == 0) { char exerealpath[MAXPATHLEN]; if(realpath(&exepath.front(), exerealpath)) { return exerealpath; } } #elif defined(ARX_HAVE_WINAPI) std::vector<char> buffer; buffer.resize(MAX_PATH); if(GetModuleFileNameA(NULL, buffer.data(), buffer.size()) > 0) { return std::string(buffer.data(), buffer.size()); } #else // Try to get the path from OS-specific procfs entries #ifdef ARX_HAVE_READLINK std::vector<char> buffer(1024); // Linux if(try_readlink(buffer, "/proc/self/exe")) { return std::string(buffer.begin(), buffer.end()); } // BSD if(try_readlink(buffer, "/proc/curproc/file")) { return std::string(buffer.begin(), buffer.end()); } // Solaris if(try_readlink(buffer, "/proc/self/path/a.out")) { return std::string(buffer.begin(), buffer.end()); } #endif // FreeBSD #if defined(ARX_HAVE_SYSCTL) && defined(CTL_KERN) && defined(KERN_PROC) \ && defined(KERN_PROC_PATHNAME) && ARX_PLATFORM == ARX_PLATFORM_BSD \ && defined(PATH_MAX) int mib[4]; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; char pathname[PATH_MAX]; size_t size = sizeof(pathname); int error = sysctl(mib, 4, pathname, &size, NULL, 0); if(error != -1 && size > 0 && size < sizeof(pathname)) { return util::loadString(pathname, size); } #endif // Solaris #ifdef ARX_HAVE_GETEXECNAME const char * execname = getexecname(); if(execname != NULL) { return execname; } #endif // Fall back to argv[0] if possible if(executablePath != NULL) { std::string path(executablePath); if(path.find('/') != std::string::npos) { return path; } } #endif // Give up - we couldn't determine the exe path. return std::string(); }
int main(int argc, char **argv) { int argno; const char *dir = (char *)0; #ifdef AMIGA char *startdir = (char *)0; #endif if (!dir) dir = getenv("NETHACKDIR"); if (!dir) dir = getenv("HACKDIR"); #ifdef FILE_AREAS if (!dir) dir = FILE_AREA_LEVL; #endif #if defined(EXEPATH) if (!dir) dir = exepath(argv[0]); #endif if (argc == 1 || (argc == 2 && !strcmp(argv[1], "-"))) { Fprintf(stderr, "Usage: %s [ -d directory ] base1 [ base2 ... ]\n", argv[0]); #if defined(WIN32) || defined(MSDOS) if (dir) { Fprintf(stderr, "\t(Unless you override it with -d, recover will look \n"); Fprintf(stderr, "\t in the %s directory on your system)\n", dir); } #endif exit(EXIT_FAILURE); } argno = 1; if (!strncmp(argv[argno], "-d", 2)) { dir = argv[argno]+2; if (*dir == '=' || *dir == ':') dir++; if (!*dir && argc > argno) { argno++; dir = argv[argno]; } if (!*dir) { Fprintf(stderr, "%s: flag -d must be followed by a directory name.\n", argv[0]); exit(EXIT_FAILURE); } argno++; } #if defined(SECURE) && !defined(VMS) if (dir # ifdef HACKDIR && strcmp(dir, HACKDIR) # endif ) { (void) setgid(getgid()); (void) setuid(getuid()); } #endif /* SECURE && !VMS */ #ifdef HACKDIR if (!dir) dir = HACKDIR; #endif #ifdef AMIGA startdir = getcwd(0,255); #endif if (dir && chdir((char *) dir) < 0) { Fprintf(stderr, "%s: cannot chdir to %s.\n", argv[0], dir); exit(EXIT_FAILURE); } while (argc > argno) { if (restore_savefile(argv[argno], dir) == 0) Fprintf(stderr, "recovered \"%s\" to %s\n", argv[argno], savename); argno++; } #ifdef AMIGA if (startdir) (void)chdir(startdir); #endif exit(EXIT_SUCCESS); /*NOTREACHED*/ return 0; }
std::string default_search_path() { #ifdef CHAISCRIPT_WINDOWS TCHAR path[2048]; int size = GetModuleFileName(0, path, sizeof(path)-1); std::string exepath(path, size); size_t secondtolastslash = exepath.rfind('\\', exepath.rfind('\\') - 1); if (secondtolastslash != std::string::npos) { return exepath.substr(0, secondtolastslash) + "\\lib\\chaiscript\\"; } else { return ""; } #else std::string exepath; std::vector<char> buf(2048); ssize_t size = -1; if ((size = readlink("/proc/self/exe", &buf.front(), buf.size())) != -1) { exepath = std::string(&buf.front(), size); } if (exepath.empty()) { if ((size = readlink("/proc/curproc/file", &buf.front(), buf.size())) != -1) { exepath = std::string(&buf.front(), size); } } if (exepath.empty()) { if ((size = readlink("/proc/self/path/a.out", &buf.front(), buf.size())) != -1) { exepath = std::string(&buf.front(), size); } } if (exepath.empty()) { Dl_info rInfo; memset( &rInfo, 0, sizeof(rInfo) ); if ( !dladdr(cast_module_symbol(&default_search_path), &rInfo) || !rInfo.dli_fname ) { return ""; } exepath = std::string(rInfo.dli_fname); } size_t secondtolastslash = exepath.rfind('/', exepath.rfind('/') - 1); if (secondtolastslash != std::string::npos) { return exepath.substr(0, secondtolastslash) + "/lib/chaiscript/"; } else { return ""; } #endif }
/** * @brief Initializes main window. */ MainFrame::MainFrame() :wxFrame(NULL,wxID_ANY,wxT("UltraDefrag")) { g_mainFrame = this; m_vList = NULL; m_cMap = NULL; m_currentJob = NULL; m_busy = false; m_paused = false; // set main window icon SetIcons(wxICON(appicon)); // read configuration ReadAppConfiguration(); ProcessCommandEvent(ID_ReadUserPreferences); // set main window title wxString *instdir = new wxString(); //genBTC re-arranged the below, A LOT. wxStandardPaths stdpaths; wxFileName exepath(stdpaths.GetExecutablePath()); wxString cd = exepath.GetPath(); if((wxGetEnv(wxT("UD_INSTALL_DIR"),instdir))&&(cd.CmpNoCase(*instdir) == 0)) { itrace("current directory matches installation location, so it isn't portable"); itrace("installation location: %ls",instdir->wc_str()); m_title = new wxString(wxT(VERSIONINTITLE)); } else { itrace("current directory differs from installation location, so it is portable"); itrace("current directory: %ls",cd.wc_str()); wxSetEnv(wxT("UD_IS_PORTABLE"),wxT("1")); m_title = new wxString(wxT(VERSIONINTITLE_PORTABLE)); } //genBTC re-arranged the above, A LOT. ProcessCommandEvent(ID_SetWindowTitle); delete instdir; // set main window size and position SetSize(m_width,m_height); if(!m_saved){ CenterOnScreen(); GetPosition(&m_x,&m_y); } Move(m_x,m_y); if(m_maximized) Maximize(true); SetMinSize(wxSize(DPI(MAIN_WINDOW_MIN_WIDTH),DPI(MAIN_WINDOW_MIN_HEIGHT))); // create menu, tool and status bars InitMenu(); InitToolbar(); InitStatusBar(); //make sizer1 to hold the the tabbed "notebook". And make the notebook wxBoxSizer* bSizer1; bSizer1 = new wxBoxSizer( wxVERTICAL ); m_notebook1 = new wxNotebook( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); //make a panel inside the notebook to hold the m_splitter m_panel1 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); // create list of volumes and cluster map (with splitter as parent) m_splitter = new wxSplitterWindow(m_panel1,wxID_ANY, wxDefaultPosition,wxDefaultSize, wxSP_3D | wxCLIP_CHILDREN); m_splitter->SetMinimumPaneSize(DPI(MIN_PANEL_HEIGHT)); m_vList = new DrivesList(m_splitter,wxLC_REPORT | wxLC_NO_SORT_HEADER | wxLC_HRULES | wxLC_VRULES | wxBORDER_NONE); m_cMap = new ClusterMap(m_splitter); m_splitter->SplitHorizontally(m_vList,m_cMap); int height = GetClientSize().GetHeight(); int maxPanelHeight = height - DPI(MIN_PANEL_HEIGHT) - m_splitter->GetSashSize(); if(m_separatorPosition < DPI(MIN_PANEL_HEIGHT)) m_separatorPosition = DPI(MIN_PANEL_HEIGHT); else if(m_separatorPosition > maxPanelHeight) m_separatorPosition = maxPanelHeight; m_splitter->SetSashPosition(m_separatorPosition); // update frame layout so we'll be able to initialize // list of volumes and cluster map properly wxSizeEvent evt(wxSize(m_width,m_height)); ProcessEvent(evt); m_splitter->UpdateSize(); InitVolList(); m_vList->SetFocus(); // populate list of volumes m_listThread = new ListThread(); //make sizer2 to Fit the splitter, and initialize it. wxBoxSizer* bSizer2; bSizer2 = new wxBoxSizer( wxVERTICAL ); bSizer2->Add( m_splitter, 1, wxEXPAND, 1 ); m_panel1->SetSizer( bSizer2 ); //Finish Tab1 - Add the Panel1(Splitter+sizer2) to the notebook. m_notebook1->AddPage( m_panel1, wxT("Drives"), false ); //make a 2nd panel inside the notebook to hold the 2nd page(a grid) m_panel2 = new wxPanel( m_notebook1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); m_filesList = new FilesList(m_panel2,wxLC_REPORT /* | wxLC_SINGLE_SEL | wxLC_NO_SORT_HEADER*/ \ | wxLC_VIRTUAL | wxLC_HRULES | wxLC_VRULES | wxBORDER_NONE); InitFilesList(); //make sizer3 to Fit the page2list, and initialize it. wxBoxSizer* bSizer3; bSizer3 = new wxBoxSizer( wxVERTICAL ); bSizer3->Add( m_filesList, 1, wxEXPAND, 1 ); m_panel2->SetSizer( bSizer3 ); bSizer3->Fit( m_panel2 ); //Finish Tab 2 - Add the Panel2(page2list+sizer3) to the notebook. m_notebook1->AddPage( m_panel2, wxT("Files"), false ); //Finish Notebook & initialize bSizer1->Add( m_notebook1, 1, wxEXPAND, 1 ); this->SetSizer( bSizer1 ); // check the boot time defragmenter presence wxFileName btdFile(wxT("%SystemRoot%\\system32\\defrag_native.exe")); btdFile.Normalize(); bool btd = btdFile.FileExists(); m_menuBar->FindItem(ID_BootEnable)->Enable(btd); m_menuBar->FindItem(ID_BootScript)->Enable(btd); m_toolBar->EnableTool(ID_BootEnable,btd); m_toolBar->EnableTool(ID_BootScript,btd); if(btd && ::winx_bootex_check(L"defrag_native") > 0){ m_menuBar->FindItem(ID_BootEnable)->Check(true); m_toolBar->ToggleTool(ID_BootEnable,true); m_btdEnabled = true; } else { m_btdEnabled = false; } // launch threads for time consuming operations m_btdThread = btd ? new BtdThread() : NULL; m_configThread = new ConfigThread(); m_crashInfoThread = new CrashInfoThread(); wxConfigBase *cfg = wxConfigBase::Get(); int ulevel = (int)cfg->Read(wxT("/Upgrade/Level"),1); wxMenuItem *item = m_menuBar->FindItem(ID_HelpUpgradeNone + ulevel); if(item) item->Check(); m_upgradeThread = new UpgradeThread(ulevel); // set system tray icon m_systemTrayIcon = new SystemTrayIcon(); if(!m_systemTrayIcon->IsOk()){ etrace("system tray icon initialization failed"); wxSetEnv(wxT("UD_MINIMIZE_TO_SYSTEM_TRAY"),wxT("0")); } SetSystemTrayIcon(wxT("tray"),wxT("UltraDefrag")); // set localized text ProcessCommandEvent(ID_LocaleChange + g_locale->GetLanguage()); // allow disk processing m_jobThread = new JobThread(); //create query thread to perform queries without blocking the GUI //(sort of like jobs) - may not be good to have both possibly running at once. //Create Query Tab, Tab #3. InitQueryMenu(); UD_DisableTool(ID_Stop); //change stop icon to be not always enabled. }