aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2003-10-12 04:04:38 +0000
committerJason Woodward2003-10-12 04:04:38 +0000
commit652b3278d095e46bb41c62ef5bd56c136eaeee9b (patch)
treec78a043a65bc59a6bcbb3887f1d815e75b2fd0a2
parent2c2d5433983e79200392372b59bec8ffb517c088 (diff)
downloadslapt-get-652b3278d095e46bb41c62ef5bd56c136eaeee9b.tar.gz
options can now be passed in in any order, so --no-prompt at the end now works
-rw-r--r--ChangeLog1
-rw-r--r--src/action.c32
-rw-r--r--src/main.c104
-rw-r--r--src/main.h4
-rw-r--r--src/package.c2
5 files changed, 79 insertions, 64 deletions
diff --git a/ChangeLog b/ChangeLog
index 44df6ac..2bc51eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@
directories.
* Prompt to upgrade before downloading (thanks kyotou)
* updated FAQ with dropline question, and upgrade single package question
+ * options can now be passed in in any order, so --no-prompt at the end now works
0.9.5e Oct 10, 2003
* added a doinst.sh script (generated from the Makefile) to help
diff --git a/src/action.c b/src/action.c
index 9bc00c7..691acda 100644
--- a/src/action.c
+++ b/src/action.c
@@ -53,14 +53,10 @@ void pkg_action_install(const rc_config *global_config,const char *pkg_name){
/* check to see if the package exists in the update list */
/* this way we install the most up to date pkg */
if( (update_pkg = get_newest_pkg(updates->pkgs,pkg_name,updates->pkg_count)) != NULL ){
- if( (install_pkg(global_config,update_pkg)) == -1 ){
- fprintf(stderr,"Installation of %s failed.\n",update_pkg->name);
- }
+ install_pkg(global_config,update_pkg);
}else{
/* install from list */
- if( (install_pkg(global_config,pkg)) == -1 ){
- fprintf(stderr,"Installation of %s failed.\n",pkg->name);
- }
+ install_pkg(global_config,pkg);
}
}
@@ -113,9 +109,7 @@ void pkg_action_remove(const char *pkg_name){
installed = get_installed_pkgs();
if( (pkg = get_newest_pkg(installed->pkgs,pkg_name,installed->pkg_count)) != NULL ){
- if( (remove_pkg(pkg)) == -1 ){
- fprintf(stderr,"Failed to remove %s.\n",pkg_name);
- }
+ remove_pkg(pkg);
}else{
printf("%s is not installed.\n",pkg_name);
}
@@ -236,9 +230,7 @@ void pkg_action_upgrade(const rc_config *global_config,pkg_info_t *installed_pkg
cmp_result = cmp_pkg_versions(installed_pkg->version,update_pkg->version);
if( cmp_result < 0 ){ /* update_pkg is newer than installed_pkg */
- if( (upgrade_pkg(global_config,installed_pkg,update_pkg)) == -1 ){
- fprintf(stderr,"Failed to update %s.\n",installed_pkg->name);
- }
+ upgrade_pkg(global_config,installed_pkg,update_pkg);
}else{
if( cmp_result > 0 ){
printf("Newer version of %s already installed.\n",installed_pkg->name);
@@ -248,9 +240,7 @@ void pkg_action_upgrade(const rc_config *global_config,pkg_info_t *installed_pkg
}
}else{
if( cmp_pkg_versions(installed_pkg->version,available_pkg->version) < 0 ){
- if( (upgrade_pkg(global_config,installed_pkg,available_pkg)) == -1 ){
- fprintf(stderr,"Failed to update %s.\n",installed_pkg->name);
- }
+ upgrade_pkg(global_config,installed_pkg,available_pkg);
}else{
printf("%s is already the newest version.\n",installed_pkg->name);
}
@@ -291,9 +281,7 @@ void pkg_action_upgrade_all(const rc_config *global_config){
if( (cmp_pkg_versions(installed_pkgs->pkgs[iterator]->version,update_pkg->version)) < 0 ){
/* attempt to upgrade */
- if( (upgrade_pkg(global_config,installed_pkgs->pkgs[iterator],update_pkg)) == -1 ){
- fprintf(stderr,"Failed to update %s.\n",installed_pkgs->pkgs[iterator]->name);
- }/* end upgrade attempt */
+ upgrade_pkg(global_config,installed_pkgs->pkgs[iterator],update_pkg);
}else{
try_dist_upgrade = 1;
@@ -313,13 +301,7 @@ void pkg_action_upgrade_all(const rc_config *global_config){
/* the current version of the pkg is greater than the installed version */
if( (cmp_pkg_versions(installed_pkgs->pkgs[iterator]->version,current_pkg->version)) < 0 ){
/* attempt to upgrade */
- if( (upgrade_pkg(global_config,installed_pkgs->pkgs[iterator],current_pkg)) == -1 ){
- fprintf(
- stderr,
- "Failed to update %s.\n",
- installed_pkgs->pkgs[iterator]->name
- );
- }/* end upgrade attempt */
+ upgrade_pkg(global_config,installed_pkgs->pkgs[iterator],current_pkg);
}/* end if cmp_pkg_versions */
}/* end if current_pkg */
}
diff --git a/src/main.c b/src/main.c
index df62d69..6dfbcb2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,13 +24,14 @@ int main( int argc, char *argv[] ){
int c = 0;
extern char *optarg;
extern int optind, opterr, optopt;
+ enum action do_action = 0;
static struct option long_options[] = {
{"update", 0, 0, 'u'},
{"upgrade", 0, 0, 'g'},
- {"install", 1, 0, 'i'},
- {"remove", 1, 0, 'r'},
- {"show", 1, 0, 's'},
- {"search", 1, 0, 'e'},
+ {"install", 0, 0, 'i'},
+ {"remove", 0, 0, 'r'},
+ {"show", 0, 0, 's'},
+ {"search", 0, 0, 'e'},
{"list", 0, 0, 't'},
{"installed", 0, 0, 'd'},
{"clean", 0, 0, 'c'},
@@ -47,8 +48,7 @@ int main( int argc, char *argv[] ){
setvbuf(stdout, (char *)NULL, _IONBF, 0); /* unbuffer stdout */
- if( argc < 2 )
- usage();
+ if( argc < 2 ) usage(), exit(1);
/* load up the configuration file */
global_config = read_rc_config(RC_LOCATION);
@@ -59,53 +59,31 @@ int main( int argc, char *argv[] ){
while( ( c = getopt_long_only(argc,argv,"",long_options,&option_index ) ) != EOF ){
switch(c){
case 'u': /* update */
- pkg_action_update(global_config);
+ do_action = UPDATE;
break;
case 'i': /* install */
- if( optarg != NULL ){
- pkg_action_install( global_config, optarg );
- for(;optind < argc;optind++){
- pkg_action_install( global_config, argv[optind] );
- }
- }else{
- usage();
- }
+ do_action = INSTALL;
break;
case 'r': /* remove */
- if( optarg != NULL ){
- pkg_action_remove( optarg );
- for(;optind < argc;optind++){
- pkg_action_remove( argv[optind] );
- }
- }else{
- usage();
- }
+ do_action = REMOVE;
break;
case 's': /* show */
- if( optarg != NULL ){
- pkg_action_show( optarg );
- }else{
- usage();
- }
+ do_action = SHOW;
break;
case 'e': /* search */
- if( optarg != NULL ){
- pkg_action_search( optarg );
- }else{
- usage();
- }
+ do_action = SEARCH;
break;
case 't': /* list */
- pkg_action_list();
+ do_action = LIST;
break;
case 'd': /* installed */
- pkg_action_list_installed();
+ do_action = INSTALLED;
break;
case 'c': /* clean */
- pkg_action_clean(global_config);
+ do_action = CLEAN;
break;
case 'g': /* upgrade */
- pkg_action_upgrade_all(global_config);
+ do_action = UPGRADE;
break;
case 'o': /* download only flag */
global_config->download_only = 1;
@@ -114,7 +92,7 @@ int main( int argc, char *argv[] ){
global_config->simulate = 1;
break;
case 'v': /* version */
- version_info();
+ do_action = SHOWVERSION;
break;
case 'b': /* auto */
global_config->no_prompt = 1;
@@ -134,6 +112,56 @@ int main( int argc, char *argv[] ){
}
}
+ if( do_action == UPDATE ){
+ pkg_action_update(global_config);
+ }else if( do_action == INSTALL ){
+ if (optind < argc) {
+ while (optind < argc){
+ pkg_action_install( global_config, argv[optind++] );
+ }
+ }else{
+ usage();
+ }
+ }else if( do_action == REMOVE ){
+ if (optind < argc) {
+ while (optind < argc){
+ pkg_action_remove( argv[optind++] );
+ }
+ }else{
+ usage();
+ }
+ }else if( do_action == SHOW ){
+ if (optind < argc) {
+ while (optind < argc){
+ pkg_action_show( argv[optind++] );
+ }
+ }else{
+ usage();
+ }
+ }else if( do_action == SEARCH ){
+ if (optind < argc) {
+ while (optind < argc){
+ pkg_action_search( argv[optind++] );
+ }
+ }else{
+ usage();
+ }
+ }else if( do_action == UPGRADE ){
+ pkg_action_upgrade_all(global_config);
+ }else if( do_action == LIST ){
+ pkg_action_list();
+ }else if( do_action == INSTALLED ){
+ pkg_action_list_installed();
+ }else if( do_action == CLEAN ){
+ pkg_action_clean(global_config);
+ }else if( do_action == SHOWVERSION ){
+ version_info();
+ }else if( do_action == 0 ){
+ /* default initialized value */
+ }else{
+ usage();
+ }
+
free(global_config->exclude_list);
free(global_config);
curl_global_cleanup();
diff --git a/src/main.h b/src/main.h
index 5fa9f0b..18a763c 100644
--- a/src/main.h
+++ b/src/main.h
@@ -56,6 +56,10 @@ struct _sg_regex {
int reg_return;
};
typedef struct _sg_regex sg_regex;
+enum action {
+ UPDATE = 1, INSTALL, REMOVE, SHOW, SEARCH, UPGRADE,
+ LIST, INSTALLED, CLEAN, SHOWVERSION
+};
/* */
#define DEBUG 0
diff --git a/src/package.c b/src/package.c
index a8b4377..9ac5145 100644
--- a/src/package.c
+++ b/src/package.c
@@ -557,7 +557,7 @@ int upgrade_pkg(const rc_config *global_config,pkg_info_t *installed_pkg,pkg_inf
return 0;
}
- if( global_config->no_prompt == 0 ){
+ if( global_config->no_prompt == 0 && global_config->download_only == 0 ){
printf("Replace %s-%s with %s-%s? [y|n] ",pkg->name,installed_pkg->version,pkg->name,pkg->version);
fgets(prompt_answer,10,stdin);
if( tolower(prompt_answer[0]) != 'y' ){