From de98f7004e712ae422af4a567c7df26c4579b0d6 Mon Sep 17 00:00:00 2001 From: Judd Vinet Date: Sun, 11 Sep 2005 23:18:42 +0000 Subject: Imported from pacman-2.9.7-TEST3.tar.gz --- src/db.c | 6 +++--- src/list.c | 20 ++++++++++++++++++++ src/list.h | 1 + src/pacman.c | 39 +++++++++++++++++++++++++++++++-------- src/util.c | 11 +++++++++++ src/util.h | 1 + 6 files changed, 67 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/db.c b/src/db.c index 4d5c4e22..6bcd0530 100644 --- a/src/db.c +++ b/src/db.c @@ -659,7 +659,7 @@ void db_search(pacdb_t *db, PMList *cache, const char *treename, PMList *needles /* check name */ haystack = strdup(pkg->name); strtoupper(haystack); - if(strstr(haystack, targ)) { + if(reg_match(haystack, targ)) { match = 1; } FREE(haystack); @@ -668,7 +668,7 @@ void db_search(pacdb_t *db, PMList *cache, const char *treename, PMList *needles if(!match) { haystack = strdup(pkg->desc); strtoupper(haystack); - if(strstr(haystack, targ)) { + if(reg_match(haystack, targ)) { match = 1; } FREE(haystack); @@ -682,7 +682,7 @@ void db_search(pacdb_t *db, PMList *cache, const char *treename, PMList *needles for(m = info->provides; m; m = m->next) { haystack = strdup(m->data); strtoupper(haystack); - if(strstr(haystack, targ)) { + if(reg_match(haystack, targ)) { match = 1; } FREE(haystack); diff --git a/src/list.c b/src/list.c index 49c07f51..1394f321 100644 --- a/src/list.c +++ b/src/list.c @@ -238,6 +238,8 @@ int list_strcmp(const void *s1, const void *s2) return(strcmp(*str1, *str2)); } +/* Sort a list of strings. + */ PMList *list_sort(PMList *list) { char **arr = NULL; @@ -270,6 +272,24 @@ PMList *list_sort(PMList *list) return(lp); } +/* Filter out any duplicate strings in a list. + * + * Not the most efficient way, but simple to implement -- we assemble + * a new list, using is_in() to check for dupes at each iteration. + * + */ +PMList* list_remove_dupes(PMList *list) +{ + PMList *i, *newlist = NULL; + + for(i = list; i; i = i->next) { + if(!is_in(i->data, newlist)) { + newlist = list_add(newlist, strdup(i->data)); + } + } + return newlist; +} + /* Reverse the order of a list * * The caller is responsible for freeing the old list diff --git a/src/list.h b/src/list.h index 28ef2a6c..fec2fcde 100644 --- a/src/list.h +++ b/src/list.h @@ -47,6 +47,7 @@ PMList* list_merge(PMList *one, PMList *two); PMList* list_last(PMList* list); int list_strcmp(const void *s1, const void *s2); PMList *list_sort(PMList *list); +PMList* list_remove_dupes(PMList *list); PMList *list_reverse(PMList *list); void list_display(const char *title, PMList *list); diff --git a/src/pacman.c b/src/pacman.c index 6ab8d3cf..acd70566 100644 --- a/src/pacman.c +++ b/src/pacman.c @@ -160,8 +160,9 @@ int main(int argc, char *argv[]) /* check for permission */ pm_access = READ_ONLY; if(pmo_op != PM_MAIN && pmo_op != PM_QUERY && pmo_op != PM_DEPTEST) { - if(pmo_op == PM_SYNC && !pmo_s_sync && - (pmo_s_search || pmo_s_printuris || pmo_group || pmo_q_list || pmo_q_info)) { + if((pmo_op == PM_SYNC && !pmo_s_sync && + (pmo_s_search || pmo_s_printuris || pmo_group || pmo_q_list || + pmo_q_info)) || (pmo_op == PM_DEPTEST && !pmo_d_resolve)) { /* special case: PM_SYNC can be used w/ pmo_s_search by any user */ } else { if(myuid) { @@ -238,6 +239,10 @@ int main(int argc, char *argv[]) /* load pm_packages cache */ pm_packages = db_loadpkgs(db_local); + /* the operation requires at least one target */ + if (list_count(pm_targets) == 0 && !(pmo_op == PM_QUERY || (pmo_op == PM_SYNC && (pmo_s_sync || pmo_s_upgrade || pmo_s_clean || pmo_group || pmo_q_list)))) + usage(pmo_op, (char*)basename(argv[0])); + /* start the requested operation */ switch(pmo_op) { case PM_ADD: ret = pacman_add(db_local, pm_targets, NULL); break; @@ -509,7 +514,7 @@ int pacman_sync(pacdb_t *db, PMList *targets) if(targets) { groups = NULL; for(j = targets; j; j = j->next) { - if(is_in((char *)j->data, allgroups)) { + if(is_in(j->data, allgroups)) { groups = list_add(groups, strdup((char *)j->data)); } } @@ -533,6 +538,12 @@ int pacman_sync(pacdb_t *db, PMList *targets) } pkg = list_sort(i); FREELIST(i); + i = pkg; + /* need to remove dupes in the list -- dupes can appear if a package + * belonging to this group exists in more than one repo at the same + * time. */ + pkg = list_remove_dupes(i); + FREELIST(i); list_display(" ", pkg); FREELIST(pkg); } @@ -693,8 +704,8 @@ int pacman_sync(pacdb_t *db, PMList *targets) cmp = rpmvercmp(local->version, sync->pkg->version); if(cmp > 0 && !sync->pkg->force) { /* local version is newer */ - fprintf(stderr, ":: %s: local version (%s) appears to be newer than repo version (%s)\n", - local->name, local->version, sync->pkg->version); + fprintf(stderr, ":: %s: local (%s) appears to be newer than repo (%s/%s)\n", + local->name, local->version, sync->dbs->sync->treename, sync->pkg->version); newer = 1; FREE(sync); continue; @@ -811,6 +822,12 @@ int pacman_sync(pacdb_t *db, PMList *targets) FREELIST(l); } if(k != NULL) { + /* remove dupe entries in case a package exists in + * multiple repos */ + PMList *tmp = list_remove_dupes(k); + FREELIST(k); + k = tmp; + printf(":: group %s:\n", targ); list_display(" ", k); if(yesno(" Install whole content? [Y/n] ")) { @@ -3488,7 +3505,7 @@ int parseargs(int op, int argc, char **argv) case 'v': pmo_verbose = 1; break; case 'w': pmo_s_downloadonly = 1; break; case 'y': pmo_s_sync = 1; break; - case '?': return(1); + case '?': pmo_help = 1; break; default: return(1); } } @@ -3507,6 +3524,12 @@ int parseargs(int op, int argc, char **argv) return(2); } + if (optind == 1) { + fprintf(stderr, "error: you should specify at least one operation\n"); + usage(pmo_op, (char*)basename(argv[0])); + return(2); + } + while(optind < argc) { /* add the target to our target array */ char *s = strdup(argv[optind]); @@ -3813,7 +3836,7 @@ void usage(int op, char *myname) printf(" -o, --owns query the package that owns \n"); printf(" -p, --file pacman will query the package file [package] instead of\n"); printf(" looking in the database\n"); - printf(" -s, --search search locally-installed packages for matching strings\n"); + printf(" -s, --search search locally-installed packages for matching regexps\n"); } else if(op == PM_SYNC) { printf("usage: %s {-S --sync} [options] [package]\n", myname); printf("options:\n"); @@ -3824,7 +3847,7 @@ void usage(int op, char *myname) printf(" -i, --info view package information\n"); printf(" -l, --list list all packages belonging to the specified repository\n"); printf(" -p, --print-uris print out download URIs for each package to be installed\n"); - printf(" -s, --search search remote repositories for matching strings\n"); + printf(" -s, --search search remote repositories for matching regexps\n"); printf(" -u, --sysupgrade upgrade all packages that are out of date\n"); printf(" -w, --downloadonly download packages but do not install/upgrade anything\n"); printf(" -y, --refresh download fresh package databases from the server\n"); diff --git a/src/util.c b/src/util.c index b68b71f2..528cc91f 100644 --- a/src/util.c +++ b/src/util.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "util.h" extern unsigned short pmo_verbose; @@ -427,5 +428,15 @@ int grep(const char *fn, const char *needle) return(0); } +int reg_match(char *string, char *pattern) +{ + int result; + regex_t reg; + + regcomp(®, pattern, REG_EXTENDED | REG_NOSUB); + result = regexec(®, string, 0, 0, 0); + regfree(®); + return(!(result)); +} /* vim: set ts=2 sw=2 noet: */ diff --git a/src/util.h b/src/util.h index a536c2e1..2098277d 100644 --- a/src/util.h +++ b/src/util.h @@ -39,6 +39,7 @@ void indentprint(char *str, int indent); char* trim(char *str); char* strtoupper(char *str); int grep(const char *fn, const char *needle); +int reg_match(char *string, char *pattern); #endif /* vim: set ts=2 sw=2 noet: */ -- cgit v1.2.3-24-g4f1b