int os_can_exe(const char_u *name) { // If it's an absolute or relative path don't need to use $PATH. if (os_is_absolute_path(name) || (name[0] == '.' && (name[1] == '/' || (name[1] == '.' && name[2] == '/')))) { return is_executable(name); } return is_executable_in_path(name); }
/// Checks if the given path represents an executable file. /// /// @param[in] name The name of the executable. /// @param[out] abspath Path of the executable, if found and not `NULL`. /// /// @return `true` if `name` is executable and /// - can be found in $PATH, /// - is relative to current dir or /// - is absolute. /// /// @return `false` otherwise. bool os_can_exe(const char_u *name, char_u **abspath) { // If it's an absolute or relative path don't need to use $PATH. if (path_is_absolute_path(name) || (name[0] == '.' && (name[1] == '/' || (name[1] == '.' && name[2] == '/')))) { if (is_executable(name)) { if (abspath != NULL) { *abspath = save_absolute_path(name); } return true; } return false; } return is_executable_in_path(name, abspath); }
void FreeMyAppResources() { cleanup_default_balloons(); destroy_asdatabase(); mystyle_destroy_all(); mylook_init( &(ASDefaultScr->Look), True, ASFLAGS_EVERYTHING ); destroy_image_manager( ASDefaultScr->image_manager, False ); destroy_font_manager( ASDefaultScr->font_manager, False ); clientprops_cleanup (); destroy_wmprops (ASDefaultScr->wmprops, False); wmprops_cleanup (); free_func_hash(); flush_keyword_ids(); purge_asimage_registry(); asxml_var_cleanup(); custom_color_cleanup(); build_xpm_colormap( NULL ); destroy_screen_gcs(ASDefaultScr); if( ASDefaultScr->RootImage ) { safe_asimage_destroy( ASDefaultScr->RootImage ); ASDefaultScr->RootImage = NULL ; } destroy_asvisual( ASDefaultScr->asv, False ); free_as_app_args(); destroy_assession( Session ); Session = NULL ; destroy_asenvironment( &Environment ); is_executable_in_path ( NULL ); #ifdef XSHMIMAGE flush_shm_cache(); #endif free( ASDefaultScr ); flush_default_asstorage(); flush_asbidirlist_memory_pool(); flush_ashash_memory_pool(); }
/* sort entries based on their mtimes; old entries before new entries */ int dirtree_compar_mtime (const dirtree_t ** d1, const dirtree_t ** d2) { return (**d1).mtime - (**d2).mtime; } void dirtree_sort (dirtree_t * tree) { int i, n; dirtree_t *t; dirtree_t **list; ASSERT_TREE(tree); if (tree->child == NULL) return; for (n = 0, t = tree->child; t != NULL; t = t->next, n++); list = (dirtree_t **) safemalloc (n * sizeof (dirtree_t *)); for (n = 0, t = tree->child; t != NULL; t = t->next, n++) list[n] = t; qsort (list, n, sizeof (dirtree_t *), (int (*)())dirtree_compar); tree->child = list[0]; for (i = 1; i < n; i++) list[i - 1]->next = list[i]; list[n - 1]->next = NULL; free (list); for (t = tree->child; t != NULL; t = t->next) dirtree_sort (t); } int dirtree_set_id (dirtree_t * tree, int id) { dirtree_t *t; tree->flags = (tree->flags & ~DIRTREE_ID) | id; id++; for (t = tree->child; t != NULL; t = t->next) id = dirtree_set_id (t, id); return id; } #if 0 /* no longer used */ void dirtree_output_tree (FILE * fp, dirtree_t * tree, int recurse) { extern struct config func_config[]; dirtree_t *t; char *buf; /* first pass: print children */ if (recurse) for (t = tree->child; t != NULL; t = t->next) if (t->flags & DIRTREE_DIR) dirtree_output_tree (fp, t, recurse); /* second pass: print self */ buf = safemalloc (8192); if (tree->flags & DIRTREE_KEEPNAME) fprintf (fp, "PopUp \"%s\"\n", tree->name); else fprintf (fp, "PopUp \"%d\"\n", tree->flags & DIRTREE_ID); fprintf (fp, " Title \"%s\"\n", tree->name); fprintf (fp, " MiniPixmap \"%s\"\n", tree->icon != NULL ? tree->icon : "mini-menu.xpm"); for (t = tree->child; t != NULL; t = t->next) { if (t->flags & DIRTREE_DIR) { if (t->flags & DIRTREE_KEEPNAME) fprintf (fp, " PopUp \"%s\" %s\n", t->name, t->name); else fprintf (fp, " PopUp \"%s\" %d\n", t->name, t->flags & DIRTREE_ID); if (t->icon != NULL) fprintf (fp, " MiniPixmap \"%s\"\n", t->icon); else if (t->flags & DIRTREE_DIR) fprintf (fp, " MiniPixmap \"mini-folder.xpm\"\n"); } else if (t->command && t->command->keyword) { fprintf (fp, " %s \"%s\" %s\n", t->command->keyword, t->name, t->path); if (t->icon != NULL) fprintf (fp, " MiniPixmap \"%s\"\n", t->icon); } else { FILE *fp2 = fopen (t->path, "r"); /* try to load a command */ if (fp2 != NULL && fgets (buf, 8192, fp2) != NULL) { struct config *config = find_config (func_config, buf); char *ptr = strip_whitespace (buf); if (config != NULL && !isspace (buf[strlen (config->keyword)])) config = NULL; if (config == NULL && 13 + strlen (t->name) + strlen (ptr) < 8192) { memmove (ptr + 13 + strlen (t->name), ptr, strlen (ptr) + 1); sprintf (ptr, "Exec \"%s\" exec", t->name); ptr[strlen (ptr)] = ' '; } if (config == NULL || !mystrcasecmp (config->keyword, "Exec")) { #ifndef NO_AVAILABILITYCHECK char *tmp; for (tmp = ptr + 4; isspace (*tmp); tmp++); if (*tmp == '"') { for (tmp++; *tmp != '\0' && *tmp != '"'; tmp++); if (*tmp == '"') { for (tmp++; isspace (*tmp); tmp++); if (!is_executable_in_path (tmp)) { if (config != NULL) memcpy (ptr, "Nop ", 4); else sprintf (ptr = buf, "Nop \"%s\"", t->name); } } } #endif /* NO_AVAILABILITYCHECK */ } fprintf (fp, " %s\n", ptr); } else fprintf (fp, " Exec \"%s\" exec %s\n", t->name, t->name); /* check for a MiniPixmap */ if (fp2 != NULL && fgets (buf, 8192, fp2) != NULL) { char *ptr = strip_whitespace (buf); if (!mystrncasecmp (ptr, "MiniPixmap", 10)) fprintf (fp, " %s\n", ptr); } if (t->icon != NULL) fprintf (fp, " MiniPixmap \"%s\"\n", t->icon); fclose (fp2); } } fprintf (fp, "EndPopUp\n\n"); free (buf); }
void Done (Bool restart, char *command ) { int restart_screen = get_flags( AfterStepState, ASS_SingleScreen)?Scr.screen:-1; Bool restart_self = False ; char *local_command = NULL ; { static int already_dead = False ; if( already_dead ) return;/* non-reentrant function ! */ already_dead = True ; } /* lets duplicate the string so we don't accidental;y delete it while closing self down */ if( restart ) { int my_name_len = strlen(MyName); if( command ) { if( strncmp(command, MyName, my_name_len )==0 ) restart_self = (command[my_name_len] == ' '|| command[my_name_len] == '\0'); local_command = mystrdup(command); }else { local_command = mystrdup(MyName); restart_self = True ; } if (!is_executable_in_path(local_command)) { if (!restart_self || MyArgs.saved_argv[0] == NULL) { show_error("Cannot restart with command \"%s\" - application is not in PATH!", local_command); return; } free(local_command); if (command) { local_command = safemalloc(strlen(command) + 1+ strlen(MyArgs.saved_argv[0])+1); sprintf( local_command, "%s %s", MyArgs.saved_argv[0], command + my_name_len); }else local_command = mystrdup(MyArgs.saved_argv[0]); } } #ifdef XSHMIMAGE /* may not need to do that as server may still have some of the shared * memory and work in it */ flush_shm_cache(); #endif LOCAL_DEBUG_CALLER_OUT( "%s restart, cmd=\"%s\"", restart?"Do":"Don't", command?command:""); XSelectInput( dpy, Scr.Root, 0 ); SendPacket (-1, M_SHUTDOWN, 0); FlushAllQueues(); sleep_a_millisec(1000); LOCAL_DEBUG_OUT( "local_command = \"%s\", restart_self = %s", local_command, restart_self?"Yes":"No"); set_flags( AfterStepState, ASS_Shutdown ); if( restart ) set_flags( AfterStepState, ASS_Restarting ); clear_flags( AfterStepState, ASS_NormalOperation ); #ifndef NO_VIRTUAL MoveViewport (0, 0, False); #endif #ifndef NO_SAVEWINDOWS if (!restart) { char *fname = make_session_file( Session, AFTER_SAVE, False ); save_aswindow_list( Scr.Windows, NULL ); free( fname ); } #endif /* Close all my pipes */ ShutdownModules(False); desktop_cover_cleanup(); /* remove window frames */ CleanupScreen(); /* Really make sure that the connection is closed and cleared! */ XSync (dpy, 0); if (ASDBus_fd>=0) asdbus_shutdown(); #ifdef XSHMIMAGE flush_shm_cache(); #endif if (restart) { set_flags( MyArgs.flags, ASS_Restarting ); spawn_child( local_command, -1, restart_screen, original_DISPLAY_string, None, C_NO_CONTEXT, False, restart_self, NULL ); } else { XCloseDisplay (dpy); dpy = NULL ; /* freeing up memory */ DestroyPendingFunctionsQueue(); DestroyCategories(); cleanup_default_balloons(); destroy_asdatabase(); destroy_assession( Session ); destroy_asenvironment( &Environment ); /* pixmap references */ build_xpm_colormap (NULL); free_scratch_ids_vector(); free_scratch_layers_vector(); clientprops_cleanup (); wmprops_cleanup (); free_func_hash(); flush_keyword_ids(); purge_asimage_registry(); asxml_var_cleanup(); custom_color_cleanup(); free_as_app_args(); free( ASDefaultScr ); flush_default_asstorage(); flush_asbidirlist_memory_pool(); flush_ashash_memory_pool(); #ifdef DEBUG_ALLOCS print_unfreed_mem (); #endif /*DEBUG_ALLOCS */ #ifdef XSHMIMAGE flush_shm_cache(); #endif } exit(0); }