/* Open the source file for reading, closing any previously open file. If dir_list is not NULL, calls path_search() to search the file in dir_list */ bool SrcFile_open( SrcFile *self, const char *filename, UT_array *dir_list ) { /* close last file */ if (self->file != NULL) { xfclose(self->file); self->file = NULL; } /* search path, add to strpool */ const char *filename_path = path_search(filename, dir_list); /* check for recursive includes, return if found */ if (!check_recursive_include(self, filename_path)) return false; self->filename = filename_path; self->line_filename = filename_path; /* open new file in binary mode, for cross-platform newline processing */ self->file = fopen( self->filename, "rb" ); if (!self->file) error_read_file(self->filename); /* init current line */ Str_clear( self->line ); self->line_nr = 0; self->line_inc = 1; self->is_c_source = false; if (self->file) return true; else return false; /* error opening file */ }
std::vector<Location> Enemy1::getPath() { std::unordered_map<Location, Location, LocationHash, Equal> came_from; std::unordered_map<Location, int, LocationHash, Equal> cost_so_far; path_search(*levelGrid, currentSquare[FIRST_SQUARE_ID], currentGoal, came_from, cost_so_far); auto path = reconstruct_path(currentSquare[FIRST_SQUARE_ID], currentGoal, came_from); return path; }
/* * init_mbox_checking: Look for the user's mbox * * Look for an mbox-style mailbox. If the user sets the MAIL environment * variable, we use that. Otherwise, we look for a file by the user's name * in the usual directories (/var/spool/mail, /usr/spool/mail, /var/mail, * and /usr/mail). If we cannot find an mbox anywhere, we forcibly turn off * mail checking. This will defeat the mail timer and save the user trouble. * * Return value: * 1 if an mbox was found. * 0 if an mbox was not found. */ static int init_mbox_checking (void) { const char *mbox_path_list = "/var/spool/mail:/usr/spool/mail:" "/var/mail:/usr/mail"; Filename tmp_mbox_path; if (getenv("MAIL") && file_exists(getenv("MAIL"))) mbox_path = malloc_strdup(getenv("MAIL")); else if (!path_search(username, mbox_path_list, tmp_mbox_path)) mbox_path = malloc_strdup(tmp_mbox_path); else { say("I can't find your mailbox."); set_int_var(MAIL_VAR, 0); return 0; } return 1; }
int rc_sourcefile(char *filename) { FILE *f; char *name; char line[256], *p; name = path_search(filename, "r", rcpath); f = fopen(name, "r"); if (!f) return -1; for (;;) { if (feof(f)) break; fgets(line, sizeof line, f); if ((p = strpbrk(line, "#\r\n"))) *p = 0; rc_command(line); } fclose(f); return 0; }
int symex_parseoptionst::doit() { if(cmdline.isset("version")) { std::cout << CBMC_VERSION << std::endl; return 0; } register_language(new_ansi_c_language); register_language(new_cpp_language); // // command line options // optionst options; get_command_line_options(options); eval_verbosity(); goto_functionst goto_functions; if(get_goto_program(options, goto_functions)) return 6; label_properties(goto_functions); if(cmdline.isset("show-properties")) { const namespacet ns(symbol_table); show_properties(ns, get_ui(), goto_functions); return 0; } if(set_properties(goto_functions)) return 7; if(cmdline.isset("show-locs")) { const namespacet ns(symbol_table); locst locs(ns); locs.build(goto_functions); locs.output(std::cout); return 0; } // do actual Symex try { const namespacet ns(symbol_table); path_searcht path_search(ns); path_search.set_message_handler(get_message_handler()); path_search.set_verbosity(get_verbosity()); if(cmdline.isset("depth")) path_search.depth_limit=unsafe_string2unsigned(cmdline.getval("depth")); if(cmdline.isset("context-bound")) path_search.context_bound=unsafe_string2unsigned(cmdline.getval("context-bound")); if(cmdline.isset("unwind")) path_search.unwind_limit=unsafe_string2unsigned(cmdline.getval("unwind")); if(cmdline.isset("show-vcc")) { path_search.show_vcc=true; path_search(goto_functions); return 0; } // do actual symex switch(path_search(goto_functions)) { case safety_checkert::SAFE: report_properties(path_search.property_map); report_success(); return 0; case safety_checkert::UNSAFE: report_properties(path_search.property_map); report_failure(); return 10; default: return 8; } } catch(const std::string error_msg) { error() << error_msg << messaget::eom; return 8; } catch(const char *error_msg) { error() << error_msg << messaget::eom; return 8; } #if 0 // let's log some more statistics debug() << "Memory consumption:" << messaget::endl; memory_info(debug()); debug() << eom; #endif }
int symex_parse_optionst::doit() { if(cmdline.isset("version")) { std::cout << CBMC_VERSION << std::endl; return 0; } register_language(new_ansi_c_language); register_language(new_cpp_language); register_language(new_java_bytecode_language); // // command line options // optionst options; get_command_line_options(options); eval_verbosity(); goto_model.set_message_handler(get_message_handler()); if(goto_model(cmdline.args)) return 6; if(process_goto_program(options)) return 6; label_properties(goto_model); if(cmdline.isset("show-properties")) { show_properties(goto_model, get_ui()); return 0; } if(set_properties()) return 7; if(cmdline.isset("show-locs")) { const namespacet ns(goto_model.symbol_table); locst locs(ns); locs.build(goto_model.goto_functions); locs.output(std::cout); return 0; } // do actual Symex try { const namespacet ns(goto_model.symbol_table); path_searcht path_search(ns); path_search.set_message_handler(get_message_handler()); if(cmdline.isset("depth")) path_search.set_depth_limit(unsafe_string2unsigned(cmdline.get_value("depth"))); if(cmdline.isset("context-bound")) path_search.set_context_bound(unsafe_string2unsigned(cmdline.get_value("context-bound"))); if(cmdline.isset("branch-bound")) path_search.set_branch_bound(unsafe_string2unsigned(cmdline.get_value("branch-bound"))); if(cmdline.isset("unwind")) path_search.set_unwind_limit(unsafe_string2unsigned(cmdline.get_value("unwind"))); if(cmdline.isset("dfs")) path_search.set_dfs(); if(cmdline.isset("bfs")) path_search.set_bfs(); if(cmdline.isset("locs")) path_search.set_locs(); if(cmdline.isset("show-vcc")) { path_search.show_vcc=true; path_search(goto_model.goto_functions); return 0; } path_search.eager_infeasibility= cmdline.isset("eager-infeasibility"); if(cmdline.isset("cover")) { // test-suite generation path_search(goto_model.goto_functions); report_cover(path_search.property_map); return 0; } else { // do actual symex, for assertion checking switch(path_search(goto_model.goto_functions)) { case safety_checkert::SAFE: report_properties(path_search.property_map); report_success(); return 0; case safety_checkert::UNSAFE: report_properties(path_search.property_map); report_failure(); return 10; default: return 8; } } } catch(const std::string error_msg) { error() << error_msg << messaget::eom; return 8; } catch(const char *error_msg) { error() << error_msg << messaget::eom; return 8; } #if 0 // let's log some more statistics debug() << "Memory consumption:" << messaget::endl; memory_info(debug()); debug() << eom; #endif }
static int whence(Shell_t *shp,char **argv, register int flags) { register const char *name; register Namval_t *np; register const char *cp; register int aflag,r=0; register const char *msg; int tofree; Dt_t *root; Namval_t *nq; char *notused; Pathcomp_t *pp=0; int notrack = 1; if(flags&Q_FLAG) flags &= ~A_FLAG; while(name= *argv++) { tofree=0; aflag = ((flags&A_FLAG)!=0); cp = 0; np = 0; if(flags&P_FLAG) goto search; if(flags&Q_FLAG) goto bltins; /* reserved words first */ if(sh_lookup(name,shtab_reserved)) { sfprintf(sfstdout,"%s%s\n",name,(flags&V_FLAG)?sh_translate(is_reserved):""); if(!aflag) continue; aflag++; } /* non-tracked aliases */ if((np=nv_search(name,shp->alias_tree,0)) && !nv_isnull(np) && !(notrack=nv_isattr(np,NV_TAGGED)) && (cp=nv_getval(np))) { if(flags&V_FLAG) { if(nv_isattr(np,NV_EXPORT)) msg = sh_translate(is_xalias); else msg = sh_translate(is_alias); sfprintf(sfstdout,msg,name); } sfputr(sfstdout,sh_fmtq(cp),'\n'); if(!aflag) continue; cp = 0; aflag++; } /* built-ins and functions next */ bltins: root = (flags&F_FLAG)?shp->bltin_tree:shp->fun_tree; if(np= nv_bfsearch(name, root, &nq, ¬used)) { if(is_abuiltin(np) && nv_isnull(np)) goto search; cp = ""; if(flags&V_FLAG) { if(nv_isnull(np)) cp = sh_translate(is_ufunction); else if(is_abuiltin(np)) { if(nv_isattr(np,BLT_SPC)) cp = sh_translate(is_spcbuiltin); else cp = sh_translate(is_builtin); } else cp = sh_translate(is_function); } if(flags&Q_FLAG) continue; sfprintf(sfstdout,"%s%s\n",name,cp); if(!aflag) continue; cp = 0; aflag++; } search: if(sh_isstate(SH_DEFPATH)) { cp=0; notrack=1; } do { if(path_search(shp,name,&pp,2+(aflag>1))) { cp = name; if((flags&P_FLAG) && *cp!='/') cp = 0; } else { cp = stakptr(PATH_OFFSET); if(*cp==0) cp = 0; else if(*cp!='/') { cp = path_fullname(shp,cp); tofree=1; } } if(flags&Q_FLAG) { pp = 0; r |= !cp; } else if(cp) { if(flags&V_FLAG) { if(*cp!= '/') { if(!np && (np=nv_search(name,shp->track_tree,0))) sfprintf(sfstdout,"%s %s %s/%s\n",name,sh_translate(is_talias),path_pwd(shp,0),cp); else if(!np || nv_isnull(np)) sfprintf(sfstdout,"%s%s\n",name,sh_translate(is_ufunction)); continue; } sfputr(sfstdout,sh_fmtq(name),' '); /* built-in version of program */ if(*cp=='/' && (np=nv_search(cp,shp->bltin_tree,0))) msg = sh_translate(is_builtver); /* tracked aliases next */ else if(aflag>1 || !notrack || strchr(name,'/')) msg = sh_translate("is"); else msg = sh_translate(is_talias); sfputr(sfstdout,msg,' '); } sfputr(sfstdout,sh_fmtq(cp),'\n'); if(aflag) { if(aflag<=1) aflag++; if (pp) pp = pp->next; } else pp = 0; if(tofree) { free((char*)cp); tofree = 0; } } else if(aflag<=1) { r |= 1; if(flags&V_FLAG) errormsg(SH_DICT,ERROR_exit(0),e_found,sh_fmtq(name)); } } while(pp); } return(r); }
FILE * tmpfile (void) { char dir[PATH_MAX]; DWORD retval; /* Find Windows temporary file directory. We provide this as the directory argument to path_search because Windows defines P_tmpdir to "\\" and will therefore try to put all temporary files in the root directory (unless $TMPDIR is set). */ retval = GetTempPath (PATH_MAX, dir); if (retval > 0 && retval < PATH_MAX) { char xtemplate[PATH_MAX]; if (path_search (xtemplate, PATH_MAX, dir, NULL, true) >= 0) { size_t len = strlen (xtemplate); int o_temporary = (supports_delete_on_close () ? _O_TEMPORARY : 0); int fd; do { memcpy (&xtemplate[len - 6], "XXXXXX", 6); if (gen_tempname (xtemplate, 0, 0, GT_NOCREATE) < 0) { fd = -1; break; } fd = _open (xtemplate, _O_CREAT | _O_EXCL | o_temporary | _O_RDWR | _O_BINARY, _S_IREAD | _S_IWRITE); } while (fd < 0 && errno == EEXIST); if (fd >= 0) { FILE *fp = _fdopen (fd, "w+b"); if (fp != NULL) return fp; else { int saved_errno = errno; _close (fd); errno = saved_errno; } } } } else { if (retval > 0) errno = ENAMETOOLONG; else /* Ideally this should translate GetLastError () to an errno value. */ errno = ENOENT; } return NULL; }
/*========================================== * 経路探索ルーチン単体テスト用main関数 *------------------------------------------ */ void main(int argc,char *argv[]) { struct walkpath_data wpd; map[0].gat=gat; map[0].xs=64; map[0].ys=64; path_search(&wpd,0,3,4,5,4); path_search(&wpd,0,5,4,3,4); path_search(&wpd,0,6,4,3,4); path_search(&wpd,0,7,4,3,4); path_search(&wpd,0,4,3,4,5); path_search(&wpd,0,4,2,4,5); path_search(&wpd,0,4,1,4,5); path_search(&wpd,0,4,5,4,3); path_search(&wpd,0,4,6,4,3); path_search(&wpd,0,4,7,4,3); path_search(&wpd,0,7,4,3,4); path_search(&wpd,0,8,4,3,4); path_search(&wpd,0,9,4,3,4); path_search(&wpd,0,10,4,3,4); path_search(&wpd,0,11,4,3,4); path_search(&wpd,0,12,4,3,4); path_search(&wpd,0,13,4,3,4); path_search(&wpd,0,14,4,3,4); path_search(&wpd,0,15,4,3,4); path_search(&wpd,0,16,4,3,4); path_search(&wpd,0,17,4,3,4); path_search(&wpd,0,18,4,3,4); }
search P4C(const_string, path, const_string, original_name, boolean, must_exist, boolean, all) { str_list_type ret_list; string name; boolean absolute_p; #ifdef __DJGPP__ /* We will use `stat' heavily, so let's request for the fastest possible version of `stat', by telling it what members of struct stat do we really need. We need to set this on each call because this is a library function; the caller might need other options from `stat'. Thus save the flags and restore them before exit. This call tells `stat' that we do NOT need to recognize executable files (neither by an extension nor by a magic signature); that we do NOT need time stamp of root directories; and that we do NOT need the write access bit in st_mode. Note that `kpse_set_progname' needs the EXEC bits, but it was already called by the time we get here. */ unsigned short save_djgpp_flags = _djstat_flags; _djstat_flags = _STAT_EXEC_MAGIC | _STAT_EXEC_EXT | _STAT_ROOT_TIME | _STAT_WRITEBIT; #endif /* Make a leading ~ count as an absolute filename, and expand $FOO's. */ name = kpse_expand (original_name); /* If the first name is absolute or explicitly relative, no need to consider PATH at all. */ absolute_p = kpse_absolute_p (name, true); if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) DEBUGF4 ("start search(file=%s, must_exist=%d, find_all=%d, path=%s).\n", name, must_exist, all, path); /* Find the file(s). */ ret_list = absolute_p ? absolute_search (name) : path_search (path, name, must_exist, all); /* Append NULL terminator if we didn't find anything at all, or we're supposed to find ALL and the list doesn't end in NULL now. */ if (STR_LIST_LENGTH (ret_list) == 0 || (all && STR_LIST_LAST_ELT (ret_list) != NULL)) str_list_add (&ret_list, NULL); /* The very first search is for texmf.cnf. We can't log that, since we want to allow setting TEXMFLOG in texmf.cnf. */ if (first_search) { first_search = false; } else { /* Record the filenames we found, if desired. And wrap them in a debugging line if we're doing that. */ if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) DEBUGF1 ("search(%s) =>", original_name); log_search (ret_list); if (KPSE_DEBUG_P (KPSE_DEBUG_SEARCH)) putc ('\n', stderr); } #ifdef __DJGPP__ /* Undo any side effects. */ _djstat_flags = save_djgpp_flags; #endif return STR_LIST (ret_list); }
/* * init_variables: initializes the string variables that can't really be * initialized properly above */ void init_variables() { #if defined(WINNT) || defined(__EMX__) char *shell; #endif int old_display = window_display; int i; char *s; for (i = 1; i < NUMBER_OF_VARIABLES - 1; i++) if (strcmp(irc_variable[i-1].name, irc_variable[i].name) >= 0) nappanic("Variable [%d] (%s) is out of order.", i, irc_variable[i].name); window_display = 0; set_string_var(DEFAULT_EMAIL_VAR, "blah@opennap"); set_string_var(DEFAULT_SERVER_VAR, "bitchx.dimension6.com"); if (*password) set_string_var(DEFAULT_PASSWORD_VAR, password); else set_string_var(DEFAULT_PASSWORD_VAR, "blah"); if (*nickname) set_string_var(DEFAULT_NICKNAME_VAR, nickname); else set_string_var(DEFAULT_NICKNAME_VAR, "blah"); set_string_var(DEFAULT_SPEED_VAR, "?"); set_string_var(PTEST_CHANGE_PORT_VAR, "8899 0"); s = m_strdup(irc_lib); malloc_strcat(&s, "/help"); set_string_var(HELP_PATH_VAR, s); new_free(&s); set_string_var(LOGFILE_VAR, DEFAULT_LOGFILE); set_string_var(FORMAT_DIRECTORY_VAR, "%d"); set_string_var(FORMAT_FILENAME_VAR, "%g4.1L %b %t %f"); set_string_var(SEARCH_FORMAT_VAR, "%-40f %b %3.1H %t %g4.1L %N %1.3p"); set_string_var(NAMES_NICKCOLOR_VAR, FORMAT_NICKCOLOR); set_string_var(DOWNLOAD_DIRECTORY_VAR, DEFAULT_DOWNLOAD_DIRECTORY); set_string_var(SHOW_NUMERICS_STR_VAR, DEFAULT_SHOW_NUMERICS_STR); set_numeric_string(current_window, DEFAULT_SHOW_NUMERICS_STR, 0); set_string_var(CMDCHARS_VAR, DEFAULT_CMDCHARS); set_string_var(LOGFILE_VAR, DEFAULT_LOGFILE); set_string_var(WORD_BREAK_VAR, DEFAULT_WORD_BREAK); #if defined(__EMX__) if ((shell = getenv("SHELL"))) { set_string_var(SHELL_VAR, path_search(shell, getenv("PATH"))); if (getenv("SHELL_FLAGS")) set_string_var(SHELL_FLAGS_VAR, getenv("SHELL_FLAGS")); } else { shell = "cmd.exe"; set_string_var(SHELL_FLAGS_VAR, "/c"); set_string_var(SHELL_VAR, convert_dos(path_search(shell, getenv("PATH")))); } #elif WINNT if ((shell = getenv("SHELL"))) { set_string_var(SHELL_VAR, path_search(shell, getenv("PATH"))); if (getenv("SHELL_FLAGS")) set_string_var(SHELL_FLAGS_VAR, getenv("SHELL_FLAGS")); } else if (gdwPlatform == VER_PLATFORM_WIN32_WINDOWS) { shell = "command.com"; set_string_var(SHELL_FLAGS_VAR, "/c"); set_string_var(SHELL_VAR, convert_dos(path_search(shell, getenv("PATH")))); } else { shell = "cmd.exe"; set_string_var(SHELL_FLAGS_VAR, "/c"); set_string_var(SHELL_VAR, convert_dos(path_search(shell, getenv("PATH")))); } #else set_string_var(SHELL_VAR, DEFAULT_SHELL); set_string_var(SHELL_FLAGS_VAR, DEFAULT_SHELL_FLAGS); #endif set_string_var(CONTINUED_LINE_VAR, DEFAULT_CONTINUED_LINE); set_string_var(INPUT_PROMPT_VAR, DEFAULT_INPUT_PROMPT); set_string_var(HIGHLIGHT_CHAR_VAR, DEFAULT_HIGHLIGHT_CHAR); set_string_var(LASTLOG_LEVEL_VAR, DEFAULT_LASTLOG_LEVEL); set_string_var(STATUS_FORMAT1_VAR, DEFAULT_STATUS_FORMAT1); set_string_var(STATUS_FORMAT2_VAR, DEFAULT_STATUS_FORMAT2); set_string_var(STATUS_CHANNEL_VAR, DEFAULT_STATUS_CHANNEL); set_string_var(STATUS_CLOCK_VAR, DEFAULT_STATUS_CLOCK); set_string_var(STATUS_CPU_SAVER_VAR, DEFAULT_STATUS_CPU_SAVER); set_string_var(STATUS_HOLD_VAR, DEFAULT_STATUS_HOLD); set_string_var(STATUS_HOLD_LINES_VAR, DEFAULT_STATUS_HOLD_LINES); set_string_var(STATUS_INSERT_VAR, DEFAULT_STATUS_INSERT); set_string_var(STATUS_NICK_VAR, DEFAULT_STATUS_NICK); set_string_var(STATUS_NOTIFY_VAR, DEFAULT_STATUS_NOTIFY); set_string_var(STATUS_OVERWRITE_VAR, DEFAULT_STATUS_OVERWRITE); set_string_var(STATUS_QUERY_VAR, DEFAULT_STATUS_QUERY); set_string_var(STATUS_SERVER_VAR, DEFAULT_STATUS_SERVER); set_string_var(STATUS_STATS_VAR, DEFAULT_STATUS_STATS); set_string_var(STATUS_USER0_VAR, DEFAULT_STATUS_USER); set_string_var(STATUS_USER1_VAR, DEFAULT_STATUS_USER1); set_string_var(STATUS_USER2_VAR, DEFAULT_STATUS_USER2); set_string_var(STATUS_USER3_VAR, DEFAULT_STATUS_USER3); set_string_var(STATUS_USER4_VAR, DEFAULT_STATUS_USER4); set_string_var(STATUS_USER5_VAR, DEFAULT_STATUS_USER5); set_string_var(STATUS_USER6_VAR, DEFAULT_STATUS_USER6); set_string_var(STATUS_USER7_VAR, DEFAULT_STATUS_USER7); set_string_var(STATUS_USER8_VAR, DEFAULT_STATUS_USER8); set_string_var(STATUS_USER9_VAR, DEFAULT_STATUS_USER9); set_string_var(STATUS_USER10_VAR, DEFAULT_STATUS_USER10); set_string_var(STATUS_USER11_VAR, DEFAULT_STATUS_USER11); set_string_var(STATUS_USER12_VAR, DEFAULT_STATUS_USER12); set_string_var(STATUS_USER13_VAR, DEFAULT_STATUS_USER13); set_string_var(STATUS_USER14_VAR, DEFAULT_STATUS_USER14); set_string_var(STATUS_USER15_VAR, DEFAULT_STATUS_USER15); set_string_var(STATUS_USER16_VAR, DEFAULT_STATUS_USER16); set_string_var(STATUS_USER17_VAR, DEFAULT_STATUS_USER17); set_string_var(STATUS_USER18_VAR, DEFAULT_STATUS_USER18); set_string_var(STATUS_USER19_VAR, DEFAULT_STATUS_USER19); set_string_var(STATUS_USER20_VAR, DEFAULT_STATUS_USER20); set_string_var(STATUS_USER21_VAR, DEFAULT_STATUS_USER21); set_string_var(STATUS_USER22_VAR, DEFAULT_STATUS_USER22); set_string_var(STATUS_USER23_VAR, DEFAULT_STATUS_USER23); set_string_var(STATUS_USER24_VAR, DEFAULT_STATUS_USER24); set_string_var(STATUS_USER25_VAR, DEFAULT_STATUS_USER25); set_string_var(STATUS_USER26_VAR, DEFAULT_STATUS_USER26); set_string_var(STATUS_USER27_VAR, DEFAULT_STATUS_USER27); set_string_var(STATUS_USER28_VAR, DEFAULT_STATUS_USER28); set_string_var(STATUS_USER29_VAR, DEFAULT_STATUS_USER29); set_string_var(STATUS_USER30_VAR, DEFAULT_STATUS_USER30); set_string_var(STATUS_USER31_VAR, DEFAULT_STATUS_USER31); set_string_var(STATUS_USER32_VAR, DEFAULT_STATUS_USER32); set_string_var(STATUS_USER33_VAR, DEFAULT_STATUS_USER33); set_string_var(STATUS_USER34_VAR, DEFAULT_STATUS_USER34); set_string_var(STATUS_USER35_VAR, DEFAULT_STATUS_USER35); set_string_var(STATUS_USER36_VAR, DEFAULT_STATUS_USER36); set_string_var(STATUS_USER37_VAR, DEFAULT_STATUS_USER37); set_string_var(STATUS_USER38_VAR, DEFAULT_STATUS_USER38); set_string_var(STATUS_USER39_VAR, DEFAULT_STATUS_USER39); set_string_var(STATUS_WINDOW_VAR, DEFAULT_STATUS_WINDOW); set_string_var(STATUS_SCROLLBACK_VAR, DEFAULT_STATUS_SCROLLBACK); set_string_var(ILLEGAL_CHARS_VAR, DEFAULT_ILLEGAL_CHARS); set_beep_on_msg(current_window, DEFAULT_BEEP_ON_MSG, 0); set_cd_device(current_window, "/dev/cdrom", 0); set_lastlog_size(current_window, NULL, irc_variable[LASTLOG_VAR].integer); set_history_size(current_window, NULL, irc_variable[HISTORY_VAR].integer); set_lastlog_level(current_window, irc_variable[LASTLOG_LEVEL_VAR].string, 0); set_input_prompt(current_window, DEFAULT_INPUT_PROMPT, 0); build_status(current_window, NULL, 0); window_display = old_display; }
int b_dot_cmd(int n, char *argv[], Shbltin_t *context) { char *script; Namval_t *np; int jmpval; Shell_t *shp = context->shp; struct sh_scoped savst, *prevscope = shp->st.self; int fd; char *filename = NULL; char *buffer = NULL; struct dolnod *saveargfor = NULL; volatile struct dolnod *argsave = NULL; checkpt_t buff; Sfio_t *iop = NULL; short level; Optdisc_t disc; memset(&disc, 0, sizeof(disc)); disc.version = OPT_VERSION; opt_info.disc = &disc; while ((n = optget(argv, sh_optdot))) { switch (n) { case ':': { errormsg(SH_DICT, 2, "%s", opt_info.arg); break; } case '?': { errormsg(SH_DICT, ERROR_usage(0), "%s", opt_info.arg); return 2; } default: { break; } } } argv += opt_info.index; script = *argv; if (error_info.errors || !script) { errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL)); __builtin_unreachable(); } if (shp->dot_depth + 1 > DOTMAX) { errormsg(SH_DICT, ERROR_exit(1), e_toodeep, script); __builtin_unreachable(); } np = shp->posix_fun; if (!np) { // Check for KornShell style function first. np = nv_search(script, shp->fun_tree, 0); if (np && is_afunction(np) && !nv_isattr(np, NV_FPOSIX)) { if (!FETCH_VT(np->nvalue, ip)) { // TODO: Replace this with a comment explaining why the return value of this // path_search() call is ignored. At the time I wrote this (2019-03-16) no unit test // exercises this statement. I added the void cast to silence Coverity Scan 253792. (void)path_search(shp, script, NULL, 0); if (FETCH_VT(np->nvalue, ip)) { if (nv_isattr(np, NV_FPOSIX)) np = NULL; } else { errormsg(SH_DICT, ERROR_exit(1), e_found, script); __builtin_unreachable(); } } } else { np = NULL; } if (!np) { fd = path_open(shp, script, path_get(shp, script)); if (fd < 0) { errormsg(SH_DICT, ERROR_system(1), e_open, script); __builtin_unreachable(); } filename = path_fullname(shp, stkptr(shp->stk, PATH_OFFSET)); } } *prevscope = shp->st; shp->st.lineno = np ? ((struct functnod *)nv_funtree(np))->functline : 1; shp->st.var_local = shp->st.save_tree = shp->var_tree; if (filename) { shp->st.filename = filename; shp->st.lineno = 1; } level = shp->fn_depth + shp->dot_depth + 1; nv_putval(SH_LEVELNOD, (char *)&level, NV_INT16); shp->st.prevst = prevscope; shp->st.self = &savst; shp->topscope = (Shscope_t *)shp->st.self; prevscope->save_tree = shp->var_tree; if (np) { struct Ufunction *rp = FETCH_VT(np->nvalue, rp); shp->st.filename = strdup(rp->fname ? rp->fname : ""); } nv_putval(SH_PATHNAMENOD, shp->st.filename, NV_NOFREE); shp->posix_fun = NULL; if (np || argv[1]) argsave = sh_argnew(shp, argv, &saveargfor); sh_pushcontext(shp, &buff, SH_JMPDOT); jmpval = sigsetjmp(buff.buff, 0); if (jmpval == 0) { shp->dot_depth++; if (np) { sh_exec(shp, (Shnode_t *)(nv_funtree(np)), sh_isstate(shp, SH_ERREXIT)); } else { buffer = malloc(IOBSIZE + 1); iop = sfnew(NULL, buffer, IOBSIZE, fd, SF_READ); sh_offstate(shp, SH_NOFORK); sh_eval(shp, iop, sh_isstate(shp, SH_PROFILE) ? SH_FUNEVAL : 0); } } sh_popcontext(shp, &buff); if (buffer) free(buffer); if (!np) { free(shp->st.filename); shp->st.filename = NULL; } shp->dot_depth--; if ((np || argv[1]) && jmpval != SH_JMPSCRIPT) { sh_argreset(shp, (struct dolnod *)argsave, saveargfor); } else { prevscope->dolc = shp->st.dolc; prevscope->dolv = shp->st.dolv; } if (shp->st.self != &savst) *shp->st.self = shp->st; // Only restore the top Shscope_t portion for posix functions. memcpy(&shp->st, prevscope, sizeof(Shscope_t)); shp->topscope = (Shscope_t *)prevscope; nv_putval(SH_PATHNAMENOD, shp->st.filename, NV_NOFREE); if (jmpval && jmpval != SH_JMPFUN) siglongjmp(shp->jmplist->buff, jmpval); return shp->exitval; }
void control_room() { setbkcolor(game.bgcolor); game.centrex=getmaxx()/2; game.centrey=getmaxy()/2; game.left_boundry=10; game.right_boundry=game.centrex*2-10; game.top_boundry=20; game.bottom_boundry=game.centrey*2-5; cout<<"head: "<<snake.head.x<<", "<<snake.head.y; rectangle(game.left_boundry, game.top_boundry, game.right_boundry, game.bottom_boundry); game.key_pressed=RIGHT; /* to start game for the first time */ /* to record path moved */ ofstream opfile; opfile.open("path.txt", ios::binary); if(!opfile) { cout<<"file not opened"; } /* draw initial path and mark target in a circle */ // int lastcolor=getcolor(); setcolor(YELLOW); circle(target.x, target.y, 5); snake.move_xy(snake.head); point neu_position; do { neu_position = path_search(snake.head); opfile<<neu_position.x<<neu_position.y; //cout<<" "<<neu_position.x<<","<<neu_position.y; erase_path(); snake.move_xy(neu_position); target.move(); }while( !(neu_position.x==-1 && neu_position.y==-1) ); opfile.close(); cout<<"\final position: "<<neu_position.x<<", "<<neu_position.y; outtextxy(game.centrex-20, game.centrey, "target down dude!!!:-)"); /*reuse neu to redraw whole path*/ ifstream ipfile; ipfile. open("path.txt", ios::nocreate|ios::noreplace|ios::binary); if(!ipfile) { cout<<"ofile not opened"; } point dummy; while(ipfile) { ipfile>>dummy.x>>dummy.y; cout<<dummy.x<<dummy.y; putpixel(dummy.x, dummy.y, WHITE); } getch(); getch(); } //end of control_room()