/* Write System Files */ void Write_System_Files(void) { char * syspath = NULL; char sysarg0[3] = { 'x', ':', 0 }; int retval; #if defined(__TURBOC__) /* Check for the sys command. */ syspath = searchpath("sys.com"); if (syspath == NULL) syspath = searchpath("sys.exe"); if (syspath == NULL) { printf("\nWARNING: No SYS in PATH - could not install system files!\n"); return; } sysarg0[0] = param.drive_letter[0]; printf("\nRunning SYS: %s %s\n", syspath, sysarg0); retval = spawnl(P_WAIT, syspath, syspath, sysarg0, NULL); #else /* use less efficient / less safe style with a new shell: */ /* Issue the command to write system files. */ char sys[7] = {'s','y','s',' ','x',':',0}; sys[4] = param.drive_letter[0]; printf("\nRunning SYS in a shell: %s\n", sys); retval = system(sys); #endif if (retval > 0) printf("\nSYS returned errorlevel %d.\n", retval); if (retval < 0) printf("\nWARNING: Running SYS failed.\n"); } /* Write_System_Files */
// // Get the name of the Gvim executable to use, with the path. // When "runtime" is non-zero, we were called to find the runtime directory. // Returns the path in name[BUFSIZE]. It's empty when it fails. // static void getGvimName(char *name, int runtime) { HKEY keyhandle; DWORD hlen; // Get the location of gvim from the registry. name[0] = 0; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Vim\\Gvim", 0, KEY_READ, &keyhandle) == ERROR_SUCCESS) { hlen = BUFSIZE; if (RegQueryValueEx(keyhandle, "path", 0, NULL, (BYTE *)name, &hlen) != ERROR_SUCCESS) name[0] = 0; else name[hlen] = 0; RegCloseKey(keyhandle); } // Registry didn't work, use the search path. if (name[0] == 0) strcpy(name, searchpath((char *)"gvim.exe")); if (!runtime) { // Only when looking for the executable, not the runtime dir, we can // search for the batch file or a name without a path. if (name[0] == 0) strcpy(name, searchpath((char *)"gvim.bat")); if (name[0] == 0) strcpy(name, "gvim"); // finds gvim.bat or gvim.exe } }
void read_ini(void) {char name[60],*path; printf("Reading the INI file . . . "); GetPath(name,CMD); strcat(name,INI_NAME); if ((ini_file=fopen(name,"r"))!=NULL) {ini_find=1,ini_open=1; strcpy(INI_PATH,name); } else {path=searchpath(INI_NAME); if (path==NULL) ini_find=0,ini_open=0; else {ini_file=fopen(path,"r"); ini_find=1,ini_open=1; strcpy(INI_PATH,path); } } if (ini_open) ReadINI(); else {strcpy(HZK,"C:\\HREADER\\HZK16"); strcpy(LABEL_PATH,"C:\\HREADER\\LABEL\\"); strcpy(TEMP_PATH,"C:\\HREADER\\TEMP\\"); History=0; } fclose(ini_file); }
int _RTL_FUNC system(const char *string) { FILE *f; char buf[1024],*a; a = getenv("COMSPEC"); if (!a) a = searchpath("cmd.exe"); if (!string) { if (!a) return 0; else if (f = fopen(a,"r")) { fclose(f); return 1; } else return 0; } if (!a) { errno = ENOENT; return -1; } buf[0] = ' '; buf[1] = '/'; buf[2] = 'C'; buf[3] = ' '; strcpy(buf+4,string); return spawnlp(P_WAIT,a,a,buf,0); }
static int spawnbase(const char *path, const char *args[], const char *env[], int toexit, int tosearch) { FILE *fil; int rv; char name[260],*vv; char parms[1024]; parms[0] = ' '; parms[1] = 0; if (*args) { while (*++args) { strcat(parms," ") ; strcat(parms,*args); } } strcpy(name,path); if (tosearch) { if (!(vv = searchpath(name))) { strcat(name,".EXE"); if (!(vv = searchpath(name))) { strcpy(name,path); strcat(name,".COM"); if (!(vv = searchpath(name))) { errno = ENOENT; return -1 ; } } } } else { int h = open(name, O_RDONLY); if (h == -1) { errno = ENOENT; return -1; } close(h); vv = name; } fflush(0) ; rv = __ll_spawn(vv,parms,env,toexit); if (toexit == P_OVERLAY) exit(rv); return rv; }
media_auditor::summary media_auditor::audit_samples() { // start fresh m_record_list.reset(); int required = 0; int found = 0; // iterate over sample entries samples_device_iterator iterator(m_enumerator.config().root_device()); for (samples_device *device = iterator.first(); device != nullptr; device = iterator.next()) { // by default we just search using the driver name std::string searchpath(m_enumerator.driver().name); // add the alternate path if present samples_iterator iter(*device); if (iter.altbasename() != nullptr) searchpath.append(";").append(iter.altbasename()); // iterate over samples in this entry for (const char *samplename = iter.first(); samplename != nullptr; samplename = iter.next()) { required++; // create a new record audit_record &record = m_record_list.append(*global_alloc(audit_record(samplename, audit_record::MEDIA_SAMPLE))); // look for the files emu_file file(m_enumerator.options().sample_path(), OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD); path_iterator path(searchpath.c_str()); std::string curpath; while (path.next(curpath, samplename)) { // attempt to access the file (.flac) or (.wav) osd_file::error filerr = file.open(curpath.c_str(), ".flac"); if (filerr != osd_file::error::NONE) filerr = file.open(curpath.c_str(), ".wav"); if (filerr == osd_file::error::NONE) { record.set_status(audit_record::STATUS_GOOD, audit_record::SUBSTATUS_GOOD); found++; } else record.set_status(audit_record::STATUS_NOT_FOUND, audit_record::SUBSTATUS_NOT_FOUND); } } } if (found == 0 && required > 0) { m_record_list.reset(); return NOTFOUND; } // return a summary return summarize(m_enumerator.driver().name); }
static const char *findfile(lua_State *L, const char *name, const char *pname, bool is_local) { const char *path; lua_getfield(L, lua_upvalueindex(1), pname); path = lua_tostring(L, -1); if (path == NULL) luaL_error(L, "`package.%s` must be a string", pname); return searchpath(L, name, path, ".", LUA_DIRSEP, is_local); }
static const char *findfile(lua_State *L, const char *name, const char *pname, const char *dirsep, bool is_local) { const char *path; lua_getfield(L, lua_upvalueindex(1), pname); path = lua_tostring(L, -1); if (path == NULL) luaL_error(L, LUA_QL("package.%s") " must be a string", pname); return searchpath(L, name, path, "\0", dirsep, is_local); }
/* Taken from imapdial, replaces tlsclient call with stunnel */ static int smtpdial(char *server) { int p[2]; int fd[3]; char *tmp; char *fpath; if(pipe(p) < 0) return -1; fd[0] = dup(p[0], -1); fd[1] = dup(p[0], -1); fd[2] = dup(2, -1); #ifdef PLAN9PORT tmp = smprint("%s:587", server); fpath = searchpath("stunnel3"); if (!fpath) { werrstr("stunnel not found. it is required for tls support."); return -1; } if(threadspawnl(fd, fpath, "stunnel", "-n", "smtp" , "-c", "-r", tmp, nil) < 0) { #else tmp = smprint("tcp!%s!587", server); if(threadspawnl(fd, "/bin/tlsclient", "tlsclient", tmp, nil) < 0){ #endif free(tmp); close(p[0]); close(p[1]); close(fd[0]); close(fd[1]); close(fd[2]); return -1; } free(tmp); close(p[0]); return p[1]; } int mxdial(char *addr, char *ddomain, char *gdomain) { int fd; DS ds; char err[Errlen]; addr = netmkaddr(addr, 0, "smtp"); dial_string_parse(addr, &ds); /* try connecting to destination or any of it's mail routers */ fd = callmx(&ds, addr, ddomain); /* try our mail gateway */ rerrstr(err, sizeof(err)); if(fd < 0 && gdomain && strstr(err, "can't translate") != 0) fd = dial(netmkaddr(gdomain, 0, "smtp"), 0, 0, 0); return fd; }
void main (int argc, char *argv[]) { char *caminho; if (caminho = searchpath("relatorio.txt")) printf ("Caminho do arquivo: %s\n", caminho); else printf ("Arquivo nao encontrado\n"); }
static int ll_searchpath (lua_State *L) { const char *f = searchpath(L, luaL_checkstring(L, 1), luaL_checkstring(L, 2)); if (f != NULL) return 1; else { /* error message is on top of the stack */ lua_pushnil(L); lua_insert(L, -2); return 2; /* return nil + error message */ } }
static const char *findfile(lua_State *L, const char *name, const char *pname) { const char *path; lua_getfield(L, LUA_ENVIRONINDEX, pname); path = lua_tostring(L, -1); if (path == NULL) luaL_error(L, LUA_QL("package.%s") " must be a string", pname); return searchpath(L, name, path, ".", LUA_DIRSEP); }
static const char *findfile (lua_State *L, const char *name, const char *pname, const char *dirsep) { const char *path; lua_getfield(L, lua_upvalueindex(1), pname); path = lua_tostring(L, -1); if (path == NULL) luaL_error(L, "'package.%s' must be a string", pname); return searchpath(L, name, path, ".", dirsep); }
void applyBinding(lua_State * L) { // Connect LuaBind to this state try { luabind::open(L); luabind::bind_class_info(L); } catch (const std::exception & e) { std::cerr << "Caught exception connecting luabind and class_info: " << e.what() << std::endl; throw; } /// Apply our bindings to this state // Extend the lua script search path for "require" LuaPath& lp = LuaPath::instance(); { LuaSearchPathUpdater searchpath(L); searchpath.extend(SearchDirectory(lp.getLuaDir())); searchpath.extend(RootDirectory(lp.getRootDir())); } { /// @todo c search path //LuaCSearchPathUpdater csearchpath(L); } // osgLua bindOsgToLua(L); // vrjugglua bindKernelToLua(L); bindSonixToLua(L); bindGadgetInterfacesToLua(L); bindRunBufferToLua(L); BindvrjLuaToLua(L); OsgAppProxy::bindToLua(L); // Set up traceback... luabind::set_pcall_callback(&add_file_and_line); // Load the vrjlua init script luabind::globals(L)["require"]("vrjlua-init"); // set up global for debug mode /// @todo make this work /* luabind::module(L.get(), "vrjlua")[ luabind::def_readwrite(boost::ref(LuaScript::exitOnError)) ]; */ }
static int ll_searchpath (lua_State *L) { const wchar_t *f = searchpath(L, luaL_checkstring(L, 1), check_utf8_string(L, 2, NULL), opt_utf8_string(L, 3, L"."), opt_utf8_string(L, 4, LUA_DIRSEP)); if (f != NULL) return 1; else { /* error message is on top of the stack */ lua_pushnil(L); lua_insert(L, -2); return 2; /* return nil + error message */ } }
static const wchar_t *findfile (lua_State *L, const char *name, const char *pname, const wchar_t *dirsep) { const wchar_t *path; lua_getfield(L, lua_upvalueindex(1), pname); if (lua_tostring(L, -1) == NULL) luaL_error(L, LUA_QL("package.%s") " must be a string", pname); path = utf8_to_utf16(L, -1, NULL); if (path == NULL) luaL_error(L, LUA_QL("package.%s") " contains invalid UTF-8", pname); return searchpath(L, name, path, L".", dirsep); }
/* Write System Files */ static void Write_System_Files(void) { int sys_found = FALSE; char sys[9] = {'s','y','s',' ','x',':',13,0,0}; /* Check for the sys command. */ if (NULL!=searchpath("sys.com") ) sys_found = TRUE; if (NULL!=searchpath("sys.exe") ) sys_found = TRUE; if (sys_found==TRUE) { /* Issue the command to write system files. */ sys[4]=param.drive_letter[0]; printf("\nRunning SYS command: %s\n",sys); system(sys); } else { printf("\n Error: The SYS command has not been located.\n"); printf( " System files have not be written to the disk.\n"); } }
static int lj_cf_package_searchpath(lua_State *L) { const char *f = searchpath(L, luaL_checkstring(L, 1), luaL_checkstring(L, 2), luaL_optstring(L, 3, "."), luaL_optstring(L, 4, LUA_DIRSEP)); if (f != NULL) { return 1; } else { /* error message is on top of the stack */ lua_pushnil(L); lua_insert(L, -2); return 2; /* return nil + error message */ } }
/************************************************* Function: main Description: 主函数 Calls: scanf printf Called By: 编译器 Input: 无 Output: 无 Return: 0 *************************************************/ int main(void) { char *ptr = NULL; char filename[20]; printf("input the file name:\n"); scanf("%s", filename); if ((ptr = searchpath(filename)) != NULL) { printf("%s", ptr); } else { printf("no the file!\n"); } }
void main() { char *p,*a,q[100]; strcpy (q,"link.exe"); p = searchpath (q); /* El valor de q no cambia */ if (p == NULL) { a = _strerror ("Error en searchpath ()"); PRS(a); getch(); exit (1); } PRS(p); SALTO; getch(); }
media_auditor::summary media_auditor::audit_samples() { // start fresh m_record_list.reset(); // iterate over sample entries for (const device_t *device = m_enumerator.config().first_device(); device != NULL; device = device->next()) if (device->type() == SAMPLES) { const samples_interface *intf = reinterpret_cast<const samples_interface *>(device->static_config()); if (intf->samplenames != NULL) { // by default we just search using the driver name astring searchpath(m_enumerator.driver().name); // iterate over samples in this entry for (int sampnum = 0; intf->samplenames[sampnum] != NULL; sampnum++) { // starred entries indicate an additional searchpath if (intf->samplenames[sampnum][0] == '*') { searchpath.cat(";").cat(&intf->samplenames[sampnum][1]); continue; } // create a new record audit_record &record = m_record_list.append(*global_alloc(audit_record(intf->samplenames[sampnum], audit_record::MEDIA_SAMPLE))); // look for the files emu_file file(m_enumerator.options().sample_path(), OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD); path_iterator path(searchpath); astring curpath; while (path.next(curpath, intf->samplenames[sampnum])) { // attempt to access the file file_error filerr = file.open(curpath); if (filerr == FILERR_NONE) record.set_status(audit_record::STATUS_GOOD, audit_record::SUBSTATUS_GOOD); else record.set_status(audit_record::STATUS_NOT_FOUND, audit_record::SUBSTATUS_NOT_FOUND); } } } } // return a summary return summarize(); }
/* Commands look like this: cmd [arg]* [| cmd [arg]* ]* [< filein] [> filein] [&] parsecmd -> parseargs */ struct CmdGroup *parsecmd(struct CmdGroup *cmdgroup){ struct CmdNode *cmdnode; char *fullpath; if((fullpath = searchpath(tokentext))){ cmdnode = pushcmd(cmdgroup, tokentext, fullpath); free(fullpath); if(cmdnode){ return parseargs(cmdgroup, cmdnode); } else{ return cmderror(NONE, cmdgroup, "Could not allocate memory for command '%s'\n", tokentext); } } else{ return cmderror(NONE, cmdgroup, "Could not find '%s'\n", tokentext); } }
int main(int argc, char ** argv) { char * truename, * runtime_path; int fd; truename = searchpath(argv[0]); fd = open(truename, O_RDONLY | O_BINARY); if (fd == -1 || (runtime_path = read_runtime_path(fd)) == NULL) { errwrite(truename); errwrite(" not found or is not a bytecode executable file\n"); return 2; } argv[0] = truename; execv(runtime_path, argv); errwrite("Cannot exec "); errwrite(runtime_path); errwrite("\n"); return 2; }
// Search NAME along PATHP with the elements of PATHEXT in turn added. char *searchpathext(const char *name, const char *pathext, const char *pathp) { char *found = 0; char *tmpathext = strsave(pathext); // strtok modifies this string, // so make a copy char *ext = strtok(tmpathext, PATH_SEP); while (ext) { char *namex = new char[strlen(name) + strlen(ext) + 1]; strcpy(namex, name); strcat(namex, ext); found = searchpath(namex, pathp); a_delete namex; if (found) break; ext = strtok(0, PATH_SEP); } a_delete tmpathext; return found; }
/* Create Alternate Master Boot Code */ void Create_Alternate_MBR(void) { char home_path[255]; int index=0; FILE *file_pointer; //Qprintf("Create_Alternate_MBR()\n"); Read_Physical_Sectors(flags.drive_number,0,0,1,1); /* Clear old MBR, if any */ memset(sector_buffer,0x00,0x1be); strcpy(home_path,path); strcat(home_path,"boot.mbr"); /* Search the directory Free FDISK resides in before searching the PATH */ /* in the environment for the boot.mbr file. */ file_pointer=fopen(home_path,"rb"); if(!file_pointer) file_pointer=fopen(searchpath("boot.mbr"),"rb"); if(!file_pointer) { printf("\nThe \"boot.mbr\" file has not been found...Program Terminated.\n"); exit(8); } index=0; do { sector_buffer[index]=fgetc(file_pointer); index++; }while(index<0x1be); fclose(file_pointer); sector_buffer[0x1fe]=0x55; sector_buffer[0x1ff]=0xaa; Write_Physical_Sectors(flags.drive_number,0,0,1,1); }
int attempt_open(char ** name, struct exec_trailer * trail, int do_open_script) { char * truename; int fd; int err; char buf [2]; truename = searchpath(*name); if (truename == 0) truename = *name; else *name = truename; fd = open(truename, O_RDONLY); if (fd == -1) return FILE_NOT_FOUND; if (!do_open_script){ err = read (fd, buf, 2); if (err < 2) return TRUNCATED_FILE; if (buf [0] == '#' && buf [1] == '!') return BAD_MAGIC_NUM; } err = read_trailer(fd, trail); if (err != 0) { close(fd); return err; } return fd; }
// // Get the Vim runtime directory into buf[BUFSIZE]. // The result is empty when it failed. // When it works, the path ends in a slash or backslash. // static void getRuntimeDir(char *buf) { int idx; getGvimName(buf, 1); if (buf[0] != 0) { // When no path found, use the search path to expand it. if (strchr(buf, '/') == NULL && strchr(buf, '\\') == NULL) strcpy(buf, searchpath(buf)); // remove "gvim.exe" from the end for (idx = (int)strlen(buf) - 1; idx >= 0; idx--) if (buf[idx] == '\\' || buf[idx] == '/') { buf[idx + 1] = 0; break; } } }
// Compute the current prefix. void set_current_prefix() { char *pathextstr; curr_prefix = new char[path_name_max()]; // Obtain the full path of the current binary; // using GetModuleFileName on MS-Windows, // and searching along PATH on other systems. #ifdef _WIN32 int len = GetModuleFileName(0, curr_prefix, path_name_max()); if (len) len = GetShortPathName(curr_prefix, curr_prefix, path_name_max()); # if DEBUG fprintf(stderr, "curr_prefix: %s\n", curr_prefix); # endif /* DEBUG */ #else /* !_WIN32 */ curr_prefix = searchpath(program_name, getenv("PATH")); if (!curr_prefix && !strchr(program_name, '.')) { // try with extensions pathextstr = strsave(getenv("PATHEXT")); if (!pathextstr) pathextstr = strsave(PATH_EXT); curr_prefix = searchpathext(program_name, pathextstr, getenv("PATH")); a_delete pathextstr; } if (!curr_prefix) return; #endif /* !_WIN32 */ msw2posixpath(curr_prefix); #if DEBUG fprintf(stderr, "curr_prefix: %s\n", curr_prefix); #endif curr_prefix = xdirname(curr_prefix); // directory of executable curr_prefix = xdirname(curr_prefix); // parent directory of executable curr_prefix_len = strlen(curr_prefix); #if DEBUG fprintf(stderr, "curr_prefix: %s\n", curr_prefix); fprintf(stderr, "curr_prefix_len: %d\n", curr_prefix_len); #endif }
void execexec(void) { word *a, *p; char *s; int n; popword(); /* "exec" */ if(runq->argv->words==0){ Xerror1("empty argument list"); return; } doredir(runq->redir); if(flag['j']){ a = runq->argv->words; n = 0; for(p = a;p;p = p->next) n+=strlen(p->word); s = emalloc(n+2); if(a){ strcat(s, a->word); for(p = a->next;p;p = p->next){ popword(); strcat(s, " "); strcat(s, p->word); } } print("%s\n", s); pushword(s); pushword("1"); pushword("-n"); pushword("/Users/npe/src/hare/usr/inferno/appl/cmd/scripts/anl/linux/deploy/py9p/"); pushword("-9"); pushword("runJob.py"); } Execute(runq->argv->words, searchpath(runq->argv->words->word)); poplist(); }
void help() { int c; int eof; int i; long filepos[26]; /* seek position for each screen */ int screennr; /* screen number; 'c' == 1 */ char fnamebuf[MAXPATHL]; #ifdef MSDOS char *fnamep; #endif /* * try to open the file specified by the "helpfile" option */ expand_env(p_hf, fnamebuf, MAXPATHL); if ((helpfd = fopen(fnamebuf, READBIN)) == NULL) { #ifdef MSDOS /* * for MSdos: try the DOS search path */ strcpy(fnamebuf, "vim.hlp"); fnamep = searchpath(fnamebuf); if (fnamep == NULL || (helpfd = fopen(fnamep, READBIN)) == NULL) { #endif smsg("Sorry, help file %s not found", fnamebuf); return; #ifdef MSDOS } #endif } helpfilepos = 0; screennr = 0; for (i = 0; i < 26; ++i) filepos[i] = 0; State = HELP; for (;;) { eof = redrawhelp(); if (!eof) filepos[screennr + 1] = ftell(helpfd); if ((c = vgetc()) == '\n' || c == '\r') break; if (c == ' ') /* one screen forwards */ { if (screennr < 25 && !eof) ++screennr; } else if (c == 'a') /* go to first screen */ screennr = 0; else if (c == 'b') /* go one screen backwards */ { if (screennr > 0) --screennr; } else if (c >= 'c' && c <= 'z') /* go to specified screen */ { if (c - 'b' < screennr) /* backwards */ screennr = c - 'b'; else /* forwards */ { while (screennr < c - 'b' && filepos[screennr + 1]) ++screennr; fseek(helpfd, filepos[screennr], 0); while (screennr < c - 'b') { while ((i = getc(helpfd)) != '\f' && i != -1) ; if (i == -1) break; filepos[++screennr] = ftell(helpfd); } } } helpfilepos = filepos[screennr]; } State = NORMAL; script_winsize_pp(); fclose(helpfd); updateScreen(CLEAR); }