[pacman-dev] [PATCH] Make it easier to ignore multiple packages.
This makes --ignore and --ignoregroup able to accept multiple packages/groups by separating each with a comma. For instance: pacman -Su --ignore kernel26,udev,glibc This was requested in the comments of FS#8054. Signed-off-by: Nathan Jones <nathanj@insightbb.com> --- src/pacman/pacman.c | 18 ++++++++++++++++-- src/pacman/util.c | 24 ++++++++++++++++++++++++ src/pacman/util.h | 1 + 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index af61ab9..52d5fff 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -314,6 +314,8 @@ static int parseargs(int argc, char *argv[]) }; while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepituwygz", opts, &option_index))) { + alpm_list_t *list = NULL, *item = NULL; /* lists for splitting strings */ + if(opt < 0) { break; } @@ -326,7 +328,13 @@ static int parseargs(int argc, char *argv[]) } config->configfile = strndup(optarg, PATH_MAX); break; - case 1002: alpm_option_add_ignorepkg(strdup(optarg)); break; + case 1002: + list = strsplit(optarg, ','); + for(item = list; item; item = alpm_list_next(item)) { + alpm_option_add_ignorepkg((char *)alpm_list_getdata(item)); + } + FREELIST(list); + break; case 1003: /* debug levels are made more 'human readable' than using a raw logmask * here, error and warning are set in config_new, though perhaps a @@ -370,7 +378,13 @@ static int parseargs(int argc, char *argv[]) } config->have_logfile = 1; break; - case 1010: alpm_option_add_ignoregrp(strdup(optarg)); break; + case 1010: + list = strsplit(optarg, ','); + for(item = list; item; item = alpm_list_next(item)) { + alpm_option_add_ignoregrp((char *)alpm_list_getdata(item)); + } + FREELIST(list); + break; case 'A': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_ADD); break; case 'F': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); diff --git a/src/pacman/util.c b/src/pacman/util.c index bc51427..c710f41 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -293,6 +293,30 @@ char *strreplace(const char *str, const char *needle, const char *replace) return newstr; } +/** Splits a string into a list of strings using the chosen character as + * a delimiter. + * + * @param str the string to split + * @param splitchar the character to split at + * + * @return a list containing the duplicated strings + */ +alpm_list_t *strsplit(const char *str, const char splitchar) +{ + alpm_list_t *list = NULL; + const char *prev = str; + + while((str = strchr(str, splitchar))) { + list = alpm_list_add(list, strndup(prev, str - prev)); + str++; + prev = str; + } + + list = alpm_list_add(list, strdup(prev)); + + return(list); +} + void list_display(const char *title, const alpm_list_t *list) { const alpm_list_t *i; diff --git a/src/pacman/util.h b/src/pacman/util.h index 4d17b17..931b456 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -46,6 +46,7 @@ void indentprint(const char *str, int indent); char *strtoupper(char *str); char *strtrim(char *str); char *strreplace(const char *str, const char *needle, const char *replace); +alpm_list_t *strsplit(const char *str, const char splitchar); void list_display(const char *title, const alpm_list_t *list); void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local); int yesno(char *fmt, ...); -- 1.5.3.5
On Nov 13, 2007 5:38 PM, Nathan Jones <nathanj@insightbb.com> wrote:
This makes --ignore and --ignoregroup able to accept multiple packages/groups by separating each with a comma.
For instance: pacman -Su --ignore kernel26,udev,glibc
This was requested in the comments of FS#8054.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
Wow man, you're like a machine. Thanks so much for doing this. One comment on the strsplit function though - could you please check the strndup return for non-null, it'd make me feel better 8)
This makes --ignore and --ignoregroup able to accept multiple packages/groups by separating each with a comma. For instance: pacman -Su --ignore kernel26,udev,glibc This was requested in the comments of FS#8054. Signed-off-by: Nathan Jones <nathanj@insightbb.com> --- doc/pacman.8.txt | 6 ++++-- src/pacman/pacman.c | 18 ++++++++++++++++-- src/pacman/util.c | 34 ++++++++++++++++++++++++++++++++++ src/pacman/util.h | 1 + 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt index db7f9c3..7b10bc0 100644 --- a/doc/pacman.8.txt +++ b/doc/pacman.8.txt @@ -267,11 +267,13 @@ Sync Options[[SO]] *\--ignore* <'package'>:: Directs pacman to ignore upgrades of package even if there is one - available. + available. Multiple packages can be specified by separating them + with a comma. *\--ignoregroup* <'group'>:: Directs pacman to ignore upgrades of all packages in 'group' even if - there is one available. + there is one available. Multiple groups can be specified by + separating them with a comma. Handling Config Files[[HCF]] diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index af61ab9..52d5fff 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -314,6 +314,8 @@ static int parseargs(int argc, char *argv[]) }; while((opt = getopt_long(argc, argv, "ARUFQSTr:b:vkhscVfmnoldepituwygz", opts, &option_index))) { + alpm_list_t *list = NULL, *item = NULL; /* lists for splitting strings */ + if(opt < 0) { break; } @@ -326,7 +328,13 @@ static int parseargs(int argc, char *argv[]) } config->configfile = strndup(optarg, PATH_MAX); break; - case 1002: alpm_option_add_ignorepkg(strdup(optarg)); break; + case 1002: + list = strsplit(optarg, ','); + for(item = list; item; item = alpm_list_next(item)) { + alpm_option_add_ignorepkg((char *)alpm_list_getdata(item)); + } + FREELIST(list); + break; case 1003: /* debug levels are made more 'human readable' than using a raw logmask * here, error and warning are set in config_new, though perhaps a @@ -370,7 +378,13 @@ static int parseargs(int argc, char *argv[]) } config->have_logfile = 1; break; - case 1010: alpm_option_add_ignoregrp(strdup(optarg)); break; + case 1010: + list = strsplit(optarg, ','); + for(item = list; item; item = alpm_list_next(item)) { + alpm_option_add_ignoregrp((char *)alpm_list_getdata(item)); + } + FREELIST(list); + break; case 'A': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_ADD); break; case 'F': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); diff --git a/src/pacman/util.c b/src/pacman/util.c index bc51427..3a06e78 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -293,6 +293,40 @@ char *strreplace(const char *str, const char *needle, const char *replace) return newstr; } +/** Splits a string into a list of strings using the chosen character as + * a delimiter. + * + * @param str the string to split + * @param splitchar the character to split at + * + * @return a list containing the duplicated strings + */ +alpm_list_t *strsplit(const char *str, const char splitchar) +{ + alpm_list_t *list = NULL; + const char *prev = str; + char *dup = NULL; + + while((str = strchr(str, splitchar))) { + dup = strndup(prev, str - prev); + if(dup == NULL) { + return(NULL); + } + list = alpm_list_add(list, dup); + + str++; + prev = str; + } + + dup = strdup(prev); + if(dup == NULL) { + return(NULL); + } + list = alpm_list_add(list, strdup(prev)); + + return(list); +} + void list_display(const char *title, const alpm_list_t *list) { const alpm_list_t *i; diff --git a/src/pacman/util.h b/src/pacman/util.h index 4d17b17..931b456 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -46,6 +46,7 @@ void indentprint(const char *str, int indent); char *strtoupper(char *str); char *strtrim(char *str); char *strreplace(const char *str, const char *needle, const char *replace); +alpm_list_t *strsplit(const char *str, const char splitchar); void list_display(const char *title, const alpm_list_t *list); void display_targets(const alpm_list_t *syncpkgs, pmdb_t *db_local); int yesno(char *fmt, ...); -- 1.5.3.5
On Nov 13, 2007 5:38 PM, Nathan Jones <nathanj@insightbb.com> wrote:
This makes --ignore and --ignoregroup able to accept multiple packages/groups by separating each with a comma.
For instance: pacman -Su --ignore kernel26,udev,glibc
This was requested in the comments of FS#8054.
Signed-off-by: Nathan Jones <nathanj@insightbb.com>
Wow man, you're like a machine. Thanks so much for doing this. One comment on the strsplit function though - could you please check the strndup return for non-null, it'd make me feel better 8) +1 Thanks for this, I like it, too. Bye PS: We are hard-working nowadays; I enjoy this... keep it up! ;-)
---------------------------------------------------- SZTE Egyetemi Könyvtár - http://www.bibl.u-szeged.hu This mail sent through IMP: http://horde.org/imp/
participants (3)
-
Aaron Griffin
-
Nagy Gabor
-
Nathan Jones