aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Woodward2004-10-03 20:32:45 +0000
committerJason Woodward2004-10-03 20:32:45 +0000
commit93e0e321880ab89823399a13819405014076a550 (patch)
tree9516618734e38f3ede2ec9f13d28f84d91a180e9 /src
parent393f3d8f048a46a3810a8a327719f878cdb53126 (diff)
downloadslapt-get-93e0e321880ab89823399a13819405014076a550.tar.gz
merged Michel Hermier's ask_yes_no() patch to common.[ch] and transation.c
Diffstat (limited to 'src')
-rw-r--r--src/common.c21
-rw-r--r--src/common.h4
-rw-r--r--src/transaction.c7
3 files changed, 25 insertions, 7 deletions
diff --git a/src/common.c b/src/common.c
index 73e6e71..2966f56 100644
--- a/src/common.c
+++ b/src/common.c
@@ -75,7 +75,7 @@ void gen_md5_sum_of_file(FILE *f,char *result_sum){
char *getline_buffer = NULL;
md = EVP_md5();
-
+
EVP_MD_CTX_init(&mdctx);
EVP_DigestInit_ex(&mdctx, md, NULL);
@@ -90,7 +90,7 @@ void gen_md5_sum_of_file(FILE *f,char *result_sum){
EVP_MD_CTX_cleanup(&mdctx);
result_sum[0] = '\0';
-
+
for(i = 0; i < md_len; i++){
char *p = malloc( sizeof *p * 3 );
@@ -196,3 +196,20 @@ void create_dir_structure(const char *dir_name){
free(cwd);
}
+int ask_yes_no(const char *format, ...)
+{
+ char prompt_answer[10];
+ va_list arg_list;
+
+ va_start(arg_list, format);
+ vprintf(format, arg_list);
+ va_end(arg_list);
+
+ /* FIXME: Use rpmatch instead ? */
+ fgets(prompt_answer,10,stdin);
+ if( tolower(prompt_answer[0]) == 'y' )
+ return 1;
+ if( tolower(prompt_answer[0]) == 'n' )
+ return 0;
+ return -1;
+}
diff --git a/src/common.h b/src/common.h
index bf22594..2af6b52 100644
--- a/src/common.h
+++ b/src/common.h
@@ -38,3 +38,7 @@ void create_dir_structure(const char *dir_name);
/* generate an md5sum of filehandle */
void gen_md5_sum_of_file(FILE *f,char *result_sum);
+/* Ask the user to answer yes or no.
+ * return 1 on yes, 0 on no, else -1.
+ */
+int ask_yes_no(const char *format, ...);
diff --git a/src/transaction.c b/src/transaction.c
index c2bbb47..ad39581 100644
--- a/src/transaction.c
+++ b/src/transaction.c
@@ -152,10 +152,7 @@ int handle_transaction(const rc_config *global_config, transaction *tran){
(global_config->no_prompt == 0 && global_config->download_only == 0 &&
global_config->simulate == 0 && global_config->print_uris == 0 )
) {
- char prompt_answer[10];
- printf(_("Do you want to continue? [y/N] "));
- fgets(prompt_answer,10,stdin);
- if( tolower(prompt_answer[0]) != 'y' ){
+ if( ask_yes_no(_("Do you want to continue? [y/N] ")) != 1 ){
printf(_("Abort.\n"));
return 0;
}
@@ -339,7 +336,7 @@ void add_upgrade_to_transaction(
tmp_list = realloc(
tran->upgrade_pkgs->pkgs,
- sizeof *tran->upgrade_pkgs->pkgs * ( tran->upgrade_pkgs->pkg_count + 1 )
+ sizeof *tran->upgrade_pkgs->pkgs * ( tran->upgrade_pkgs->pkg_count + 1 )
);
if( tmp_list != NULL ){
tran->upgrade_pkgs->pkgs = tmp_list;