int version_detect_from_executable(sci_version_t *result) { sci_dir_t dir; char *filename; int mac = 0; /* For Mac versions we need to search the resource fork */ mac = !chdir(".rsrc"); sci_init_dir(&dir); filename = sci_find_first(&dir, "*"); while (filename) { if (mac ? is_mac_exe(filename) : is_exe(filename)) if (!scan_file(filename, result)) { sci_finish_find(&dir); if (mac) chdir(".."); return 0; } filename = sci_find_next(&dir); } if (mac) chdir(".."); return 1; }
gboolean if_link_is_exe (const vfs_path_t * full_name_vpath, const file_entry_t * file) { struct stat b; if (S_ISLNK (file->st.st_mode) && mc_stat (full_name_vpath, &b) == 0) return is_exe (b.st_mode); return TRUE; }
/* Calculates the truth value of the next condition starting from p. Returns the point after condition. */ static char *test_condition (WEdit *edit_widget, char *p, int *condition) { WPanel *panel; char arg [256]; /* Handle one condition */ for (;*p != '\n' && *p != '&' && *p != '|'; p++){ /* support quote space .mnu */ if ((*p == ' ' && *(p-1) != '\\') || *p == '\t') continue; if (*p >= 'a') panel = current_panel; else { if (get_other_type () == view_listing) panel = other_panel; else panel = NULL; } *p |= 0x20; switch (*p++){ case '!': p = test_condition (edit_widget, p, condition); *condition = ! *condition; p--; break; case 'f': /* file name pattern */ p = extract_arg (p, arg, sizeof (arg)); *condition = panel && regexp_match (arg, panel->dir.list [panel->selected].fname, match_file, 0); break; case 'y': /* syntax pattern */ if (edit_widget && edit_widget->syntax_type) { p = extract_arg (p, arg, sizeof (arg)); *condition = panel && regexp_match (arg, edit_widget->syntax_type, match_normal, 0); } break; case 'd': p = extract_arg (p, arg, sizeof (arg)); *condition = panel && regexp_match (arg, panel->cwd, match_file, 0); break; case 't': p = extract_arg (p, arg, sizeof (arg)); *condition = panel && test_type (panel, arg); break; case 'x': /* executable */ { struct stat status; p = extract_arg (p, arg, sizeof (arg)); if (stat (arg, &status) == 0) *condition = is_exe (status.st_mode); else *condition = 0; break; } default: debug_error = 1; break; } /* switch */ } /* while */ return p; }
inline static gboolean mc_fhl_is_file_exec (file_entry_t * fe) { return is_exe (fe->st.st_mode); }
static char * test_condition (WEdit * edit_widget, char *p, int *condition) { char arg[256]; const mc_search_type_t search_type = easy_patterns ? MC_SEARCH_T_GLOB : MC_SEARCH_T_REGEX; /* Handle one condition */ for (; *p != '\n' && *p != '&' && *p != '|'; p++) { WPanel *panel = NULL; /* support quote space .mnu */ if ((*p == ' ' && *(p - 1) != '\\') || *p == '\t') continue; if (*p >= 'a') panel = current_panel; else if (get_other_type () == view_listing) panel = other_panel; *p |= 0x20; switch (*p++) { case '!': p = test_condition (edit_widget, p, condition); *condition = !*condition; str_prev_char (&p); break; case 'f': /* file name pattern */ p = extract_arg (p, arg, sizeof (arg)); #ifdef USE_INTERNAL_EDIT if (edit_widget != NULL) { char *edit_filename; edit_filename = edit_get_file_name (edit_widget); *condition = mc_search (arg, DEFAULT_CHARSET, edit_filename, search_type) ? 1 : 0; g_free (edit_filename); } else #endif *condition = panel != NULL && mc_search (arg, DEFAULT_CHARSET, panel->dir.list[panel->selected].fname, search_type) ? 1 : 0; break; case 'y': /* syntax pattern */ #ifdef USE_INTERNAL_EDIT if (edit_widget != NULL) { const char *syntax_type = edit_get_syntax_type (edit_widget); if (syntax_type != NULL) { p = extract_arg (p, arg, sizeof (arg)); *condition = mc_search (arg, DEFAULT_CHARSET, syntax_type, MC_SEARCH_T_NORMAL) ? 1 : 0; } } #endif break; case 'd': p = extract_arg (p, arg, sizeof (arg)); *condition = panel != NULL && mc_search (arg, DEFAULT_CHARSET, vfs_path_as_str (panel->cwd_vpath), search_type) ? 1 : 0; break; case 't': p = extract_arg (p, arg, sizeof (arg)); *condition = panel != NULL && test_type (panel, arg) ? 1 : 0; break; case 'x': /* executable */ { struct stat status; p = extract_arg (p, arg, sizeof (arg)); if (stat (arg, &status) == 0) *condition = is_exe (status.st_mode) ? 1 : 0; else *condition = 0; break; } default: debug_error = 1; break; } /* switch */ } /* while */ return p; }