int command_line_get_part_flag (const char* prompt, const PedPartition* part, PedPartitionFlag* flag) { StrList* opts = NULL; PedPartitionFlag walk = 0; char* flag_name; while ( (walk = ped_partition_flag_next (walk)) ) { if (ped_partition_is_flag_available (part, walk)) { const char* walk_name; walk_name = ped_partition_flag_get_name (walk); opts = str_list_append (opts, walk_name); opts = str_list_append_unique (opts, _(walk_name)); } } if (opts == NULL) { ped_exception_throw (PED_EXCEPTION_ERROR, PED_EXCEPTION_OK, _("No flags supported")); return 0; } flag_name = command_line_get_word (prompt, NULL, opts, 1); str_list_destroy (opts); if (flag_name) { *flag = ped_partition_flag_get_by_name (flag_name); free (flag_name); return 1; } else return 0; }
size_t strListMerge(str_list_t* list, str_list_t add_list) { size_t i; size_t count; count=strListCount(*list); for(i=0; add_list[i]!=NULL; i++) str_list_append(list,add_list[i],count++); return(i); }
char* strListAppend(str_list_t* list, const char* str, size_t index) { char* buf; if(str==NULL) return(NULL); if((buf=strdup(str))==NULL) return(NULL); if(index==STR_LIST_LAST_INDEX) index=strListCount(*list); return(str_list_append(list,buf,index)); }
int command_line_get_unit (const char* prompt, PedUnit* unit) { StrList* opts = NULL; PedUnit walk; char* unit_name; const char* default_unit_name; for (walk = PED_UNIT_FIRST; walk <= PED_UNIT_LAST; walk++) opts = str_list_append (opts, ped_unit_get_name (walk)); default_unit_name = ped_unit_get_name (ped_unit_get_default ()); unit_name = command_line_get_word (prompt, default_unit_name, opts, 1); str_list_destroy (opts); if (unit_name) { *unit = ped_unit_get_by_name (unit_name); free (unit_name); return 1; } else return 0; }
static int args_parse(int argc, char *argv[]) { int c; int option_index = 0; int parse_err = 0; char *tuple, *targ; while (1) { c = getopt_long_only(argc, argv, "Ad:f:no:p:t:vV::", long_options, &option_index); if (c == -1) break; switch (c) { case 'A': opkg_config->query_all = 1; break; case 'd': opkg_config->dest_str = xstrdup(optarg); break; case 'f': opkg_config->conf_file = xstrdup(optarg); break; case 'o': opkg_config->offline_root = xstrdup(optarg); break; case 't': opkg_config->tmp_dir = xstrdup(optarg); break; case 'v': printf("opkg version %s\n", VERSION); exit(0); case 'V': opkg_config->verbosity = INFO; if (optarg != NULL) opkg_config->verbosity = atoi(optarg); break; case ARGS_OPT_AUTOREMOVE: opkg_config->autoremove = 1; break; case ARGS_OPT_FORCE_MAINTAINER: opkg_config->force_maintainer = 1; break; case ARGS_OPT_IGNORE_MAINTAINER: opkg_config->ignore_maintainer = 1; break; case ARGS_OPT_FORCE_DEPENDS: opkg_config->force_depends = 1; break; case ARGS_OPT_FORCE_OVERWRITE: opkg_config->force_overwrite = 1; break; case ARGS_OPT_FORCE_DOWNGRADE: opkg_config->force_downgrade = 1; break; case ARGS_OPT_FORCE_REINSTALL: opkg_config->force_reinstall = 1; break; case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES: opkg_config->force_removal_of_essential_packages = 1; break; case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES: opkg_config->force_removal_of_dependent_packages = 1; break; case ARGS_OPT_FORCE_SPACE: opkg_config->force_space = 1; break; case ARGS_OPT_FORCE_POSTINSTALL: opkg_config->force_postinstall = 1; break; case ARGS_OPT_FORCE_REMOVE: opkg_config->force_remove = 1; break; case ARGS_OPT_PREFER_ARCH_TO_VERSION: opkg_config->prefer_arch_to_version = 1; break; case ARGS_OPT_NODEPS: opkg_config->nodeps = 1; break; case ARGS_OPT_ADD_ARCH: case ARGS_OPT_ADD_DEST: tuple = xstrdup(optarg); if ((targ = strchr(tuple, ':')) != NULL) { *targ++ = 0; if ((strlen(tuple) > 0) && (strlen(targ) > 0)) { nv_pair_list_append((c == ARGS_OPT_ADD_ARCH) ? &opkg_config->arch_list : &opkg_config->tmp_dest_list, tuple, targ); } } free(tuple); break; case ARGS_OPT_ADD_EXCLUDE: str_list_append(&opkg_config->exclude_list, optarg); break; case ARGS_OPT_NOACTION: opkg_config->noaction = 1; break; case ARGS_OPT_DOWNLOAD_ONLY: opkg_config->download_only = 1; break; case ARGS_OPT_CACHE_DIR: opkg_config->cache_dir = xstrdup(optarg); break; case ARGS_OPT_HOST_CACHE_DIR: opkg_config->host_cache_dir = 1; break; case ARGS_OPT_VOLATILE_CACHE: opkg_config->volatile_cache = 1; break; case ARGS_OPT_NO_INSTALL_RECOMMENDS: opkg_config->no_install_recommends = 1; break; case ARGS_OPT_COMBINE: opkg_config->combine = 1; break; case ':': parse_err = -1; break; case '?': parse_err = -1; break; default: printf("Confusion: getopt_long returned %d\n", c); } } if (parse_err) return parse_err; else return optind; }
void remove_data_files_and_list(pkg_t * pkg) { str_list_t installed_dirs; str_list_t *installed_files; str_list_elt_t *iter; char *file_name; conffile_t *conffile; int removed_a_dir; pkg_t *owner; int rootdirlen = 0; int r; installed_files = pkg_get_installed_files(pkg); if (installed_files == NULL) { opkg_msg(ERROR, "Failed to determine installed " "files for %s. None removed.\n", pkg->name); return; } str_list_init(&installed_dirs); /* don't include trailing slash */ if (opkg_config->offline_root) rootdirlen = strlen(opkg_config->offline_root); for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) { file_name = (char *)iter->data; owner = file_hash_get_file_owner(file_name); if (owner != pkg) /* File may have been claimed by another package. */ continue; if (!file_is_symlink(file_name) && file_is_dir(file_name)) { str_list_append(&installed_dirs, file_name); continue; } conffile = pkg_get_conffile(pkg, file_name + rootdirlen); if (conffile) { if (conffile_has_been_modified(conffile)) { opkg_msg(NOTICE, "Not deleting modified conffile %s.\n", file_name); continue; } } if (!opkg_config->noaction) { opkg_msg(INFO, "Deleting %s.\n", file_name); unlink(file_name); } else opkg_msg(INFO, "Not deleting %s. (noaction)\n", file_name); file_hash_remove(file_name); } /* Remove empty directories */ if (!opkg_config->noaction) { do { removed_a_dir = 0; for (iter = str_list_first(&installed_dirs); iter; iter = str_list_next(&installed_dirs, iter)) { file_name = (char *)iter->data; r = rmdir(file_name); if (r == 0) { opkg_msg(INFO, "Deleting %s.\n", file_name); removed_a_dir = 1; str_list_remove(&installed_dirs, &iter); } } } while (removed_a_dir); } pkg_free_installed_files(pkg); pkg_remove_installed_files_list(pkg); /* Don't print warning for dirs that are provided by other packages */ for (iter = str_list_first(&installed_dirs); iter; iter = str_list_next(&installed_dirs, iter)) { file_name = (char *)iter->data; owner = file_hash_get_file_owner(file_name); if (owner) { free(iter->data); iter->data = NULL; str_list_remove(&installed_dirs, &iter); } } /* cleanup */ while (!void_list_empty(&installed_dirs)) { iter = str_list_pop(&installed_dirs); free(iter->data); free(iter); } str_list_deinit(&installed_dirs); }
void command_line_push_word (const char* word) { command_line = str_list_append (command_line, word); }