[pacman-dev] alpm_list regex matching

Dan McGee dpmcgee at gmail.com
Sat Apr 11 15:55:35 EDT 2009


Holy cow, this is the oldest pacman-dev email still in my inbox.
Anyone think this would still be useful?

-Dan

On Sat, Apr 14, 2007 at 3:20 PM,  <leslie.polzer at gmx.net> wrote:
>
> Hello,
>
>  inlined diff (p0, hope that's not a problem) adds regex matching to
> alpm_list; useful for regular expressions in IgnorePkg etc.
>
> I'll leave the actual usage up to you and hope it helps somehow :)
>
>  Leslie
>
> --
> NEW homepage: https://viridian.dnsalias.net/~sky/homepage/ gpg
> --keyserver pgp.mit.edu --recv-keys DD4EBF83
>
>
>
> Index: lib/libalpm/alpm_list.c
> ===================================================================
> RCS file: /home/cvs-pacman/pacman-lib/lib/libalpm/alpm_list.c,v
> retrieving revision 1.11
> diff -a -p -u -r1.11 alpm_list.c
> --- lib/libalpm/alpm_list.c     11 Mar 2007 21:10:03 -0000      1.11
> +++ lib/libalpm/alpm_list.c     14 Apr 2007 19:18:15 -0000
> @@ -24,9 +24,11 @@
>  #include <stdlib.h>
>  #include <string.h>
>  #include <stdio.h>
> +#include <regex.h>
>
>  /* libalpm */
>  #include "alpm_list.h"
> +#include "error.h"
>  #include "util.h"
>
>  /** \defgroup alpm_list functions */
> @@ -458,6 +460,39 @@ int SYMEXPORT alpm_list_find_str(alpm_li
>        return(0);
>  }
>
> +/* Test for existence of a string in an alpm_list_t, treating the list
> + * elements as regular expressions
> +*/
> +/** Is a _string_ in the list (optimization of alpm_list_find for strings)
> + *  @param needle the string to compare
> + *  @param haystack the list to search
> + *  @return 1 if `needle` is found, 0 otherwise
> + */
> +
> +int SYMEXPORT alpm_list_find_str_regex(alpm_list_t *haystack, const char *needle)
> +{
> +       alpm_list_t *lp = haystack;
> +
> +       while(lp) {
> +               if(lp->data) {
> +                       char* targ = lp->data;
> +                       regex_t reg;
> +
> +                       _alpm_log(PM_LOG_DEBUG, "matching needle '%s' against haystack item '%s'",
> +                                       needle, lp->data);
> +
> +                       if(regcomp(&reg, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
> +                               RET_ERR(PM_ERR_INVALID_REGEX, NULL);
> +                       }
> +
> +                       if (regexec(&reg, needle, 0, 0, 0) == 0) {
> +                               return(1);
> +                       }
> +               }
> +               lp = lp->next;
> +       }
> +       return(0);
> +}
>  /**
>  * Calculate the items in list `lhs` that are not present in list `rhs`
>  * @note Entries are not duplicated
>
>
> _______________________________________________
> pacman-dev mailing list
> pacman-dev at archlinux.org
> http://archlinux.org/mailman/listinfo/pacman-dev
>


More information about the pacman-dev mailing list