static UI_MENU_CALLBACK(license_callback) { menu_draw_t *menu_draw; #ifdef WINMIPS char *new_text = NULL; #endif if (activated) { menu_draw = sdl_ui_get_menu_param(); if (menu_draw->max_text_x > 60) { #ifdef WINMIPS new_text = concat_all(info_license_text); show_text(new_text); lib_free(new_text); #else show_text(info_license_text); #endif } else { #ifdef WINMIPS new_text = concat_all(info_license_text40); show_text(new_text); lib_free(new_text); #else show_text(info_license_text40); #endif } } return NULL; }
static UI_MENU_CALLBACK(contributors_callback) { menu_draw_t *menu_draw; char *info_contrib_text_n; #ifdef WINMIPS char *new_text = NULL; #endif if (activated) { menu_draw = sdl_ui_get_menu_param(); #ifdef WINMIPS new_text = concat_all(info_contrib_text); info_contrib_text_n = contrib_convert(new_text, menu_draw->max_text_x); lib_free(new_text); #else info_contrib_text_n = contrib_convert((char *)info_contrib_text, menu_draw->max_text_x); #endif show_text((const char *)info_contrib_text_n); lib_free(info_contrib_text_n); } return NULL; }
static Status pc_complete_path(const Session *sess, List *suggestions, const char *str, size_t str_len) { (void)sess; /* When only ~ is provided expand it to users home directory */ if (strcmp("~", str) == 0) { str = getenv("HOME"); str_len = strlen(str); } /* Create copies that we can modify */ char *path1 = strdup(str); char *path2 = strdup(str); if (path1 == NULL || path2 == NULL) { free(path1); free(path2); return OUT_OF_MEMORY("Unable to allocate memory for path"); } Status status = STATUS_SUCCESS; /* Split into containing directory and file name */ const char *dir_path; const char *file_name; size_t file_name_len; /* Need to take special care with root directory */ int is_root_only = (strcmp("/", path1) == 0); if (!is_root_only && path1[str_len - 1] == '/') { /* Path is a directory only so set file name * part to NULL to match all files in directory */ path1[str_len - 1] = '\0'; dir_path = path1; free(path2); path2 = NULL; file_name = NULL; file_name_len = 0; } else { dir_path = dirname(path1); if (is_root_only) { file_name = NULL; file_name_len = 0; } else { file_name = basename(path2); file_name_len = strlen(file_name); } } int home_dir_path = (dir_path[0] == '~'); const char *canon_dir_path; DIR *dir = NULL; if (home_dir_path) { /* Expand ~ to users home directory so we can read the * directory entries. Any suggestions provided to user * will still start with ~ */ const char *home_path = getenv("HOME"); canon_dir_path = concat(home_path, dir_path + 1); if (canon_dir_path == NULL) { status = OUT_OF_MEMORY("Unable to allocated path"); goto cleanup; } } else { canon_dir_path = dir_path; } dir = opendir(canon_dir_path); if (home_dir_path) { free((char *)canon_dir_path); } if (dir == NULL) { goto cleanup; } if (strcmp(dir_path, "/") == 0) { dir_path = ""; } struct dirent *dir_ent; PromptSuggestion *suggestion; SuggestionRank rank; size_t dir_ent_num = 0; errno = 0; while (dir_ent_num++ < MAX_DIR_ENT_NUM && (dir_ent = readdir(dir)) != NULL) { if (errno) { status = st_get_error(ERR_UNABLE_TO_READ_DIRECTORY, "Unable to read from directory - %s", strerror(errno)); goto cleanup; } if (strcmp(".", dir_ent->d_name) == 0 || strcmp("..", dir_ent->d_name) == 0) { continue; } rank = SR_NO_MATCH; if (file_name == NULL) { rank = SR_DEFAULT_MATCH; } else if (strcmp(file_name, dir_ent->d_name) == 0) { rank = SR_EXACT_MATCH; } else if (strncmp(file_name, dir_ent->d_name, file_name_len) == 0) { rank = SR_STARTS_WITH; } else if (strstr(file_name, dir_ent->d_name) != NULL) { rank = SR_CONTAINS; } if (rank != SR_NO_MATCH) { char *suggestion_path; if (dir_ent->d_type == DT_DIR) { suggestion_path = concat_all(4, dir_path, "/", dir_ent->d_name,"/"); } else { suggestion_path = concat_all(3, dir_path, "/", dir_ent->d_name); } if (suggestion_path == NULL) { status = OUT_OF_MEMORY("Unable to allocated suggested path"); goto cleanup; } suggestion = pc_new_suggestion(suggestion_path, rank, NULL); free(suggestion_path); if (suggestion == NULL || !list_add(suggestions, suggestion)) { free(suggestion); status = OUT_OF_MEMORY("Unable to allocated suggested buffer"); goto cleanup; } } } cleanup: if (dir != NULL) { closedir(dir); } free(path1); free(path2); return status; }