diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/pacman/callback.c | 13 | ||||
| -rw-r--r-- | src/pacman/util.c | 55 | ||||
| -rw-r--r-- | src/pacman/util.h | 2 | 
3 files changed, 70 insertions, 0 deletions
| diff --git a/src/pacman/callback.c b/src/pacman/callback.c index e3feea16..43c56d00 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -302,6 +302,19 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,  				alpm_list_free(namelist);  			}  			break; +		case PM_TRANS_CONV_SELECT_PROVIDER: +			{ +				alpm_list_t *providers = (alpm_list_t *)data1; +				int count = alpm_list_count(providers); +				char *depstring = alpm_dep_compute_string((pmdepend_t *)data2); +				printf(_(":: There are %d providers available for %s:\n"), count, +						depstring); +				free(depstring); +				select_display(providers); +				printf("\n"); +				*response = select_question(count); +			} +			break;  		case PM_TRANS_CONV_LOCAL_NEWER:  			if(!config->op_s_downloadonly) {  				*response = yesno(_(":: %s-%s: local version is newer. Upgrade anyway?"), diff --git a/src/pacman/util.c b/src/pacman/util.c index 0377bf79..133dccc2 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -677,6 +677,61 @@ void display_optdepends(pmpkg_t *pkg)  	}  } +void select_display(const alpm_list_t *pkglist) +{ +	const alpm_list_t *i; +	int nth = 1; +	alpm_list_t *list = NULL; +	char *string = NULL; + +	for (i = pkglist; i; i = i->next) { +		string = NULL; +		pm_asprintf(&string, "%d) %s", nth, alpm_pkg_get_name(i->data)); +		list = alpm_list_add(list, string); +		nth++; +	} +	list_display("  ", list); +	FREELIST(list); +} + +int select_question(int count) +{ +	char response[32]; +	FILE *stream; +	int preset = 1; + +	if(config->noconfirm) { +		stream = stdout; +	} else { +		/* Use stderr so questions are always displayed when redirecting output */ +		stream = stderr; +	} + +	fprintf(stream, _("Enter a number (default=%d)"), preset); +	fprintf(stream,	": "); + +	if(config->noconfirm) { +		fprintf(stream, "\n"); +		return(preset-1); +	} + +	if(fgets(response, sizeof(response), stdin)) { +		strtrim(response); +		if(strlen(response) > 0) { +			char *endptr = NULL; +			int n = strtol(response, &endptr, 10); +			if(*endptr == '\0' && n >= 1 && n <= count) { +				return(n-1); +			} else { +				fprintf(stream, _("Invalid number: %s\n"), response); +				return(-1); +			} +		} +	} +	return(preset-1); +} + +  /* presents a prompt and gets a Y/N answer */  static int question(short preset, char *fmt, va_list args)  { diff --git a/src/pacman/util.h b/src/pacman/util.h index 78fe5b59..399f9bc8 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -59,6 +59,8 @@ int str_cmp(const void *s1, const void *s2);  void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg);  void display_optdepends(pmpkg_t *pkg);  void print_packages(const alpm_list_t *packages); +void select_display(const alpm_list_t *pkglist); +int select_question(int count);  int yesno(char *fmt, ...);  int noyes(char *fmt, ...);  int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); | 
