diff options
author | Mike Frysinger <vapier@gentoo.org> | 2013-04-29 04:38:16 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2013-04-29 04:38:16 +0000 |
commit | 9ba7e8a90a1735ae016988c4983af8b78a3df203 (patch) | |
tree | d86391157bf220e09af37c358e4712e491afc612 /libq/atom_explode.c | |
parent | qatom: check # of args before running main code (diff) | |
download | portage-utils-9ba7e8a90a1735ae016988c4983af8b78a3df203.tar.gz portage-utils-9ba7e8a90a1735ae016988c4983af8b78a3df203.tar.bz2 portage-utils-9ba7e8a90a1735ae016988c4983af8b78a3df203.zip |
initial support for prefix/suffix operators #369225 by Christian Ruppert
Diffstat (limited to 'libq/atom_explode.c')
-rw-r--r-- | libq/atom_explode.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/libq/atom_explode.c b/libq/atom_explode.c index 79d854c..8795706 100644 --- a/libq/atom_explode.c +++ b/libq/atom_explode.c @@ -1,7 +1,7 @@ /* * Copyright 2005-2008 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 - * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/atom_explode.c,v 1.26 2011/01/18 03:12:19 vapier Exp $ + * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/atom_explode.c,v 1.27 2013/04/29 04:38:16 vapier Exp $ * * Copyright 2005-2008 Ned Ludd - <solar@gentoo.org> * Copyright 2005-2008 Mike Frysinger - <vapier@gentoo.org> @@ -15,8 +15,23 @@ typedef struct { uint64_t sint; } atom_suffix; +const char * const atom_op_str[] = { "", ">", ">=", "=", "<=", "<", "~", "!", "!!", "*" }; +typedef enum { + /* */ ATOM_OP_NONE = 0, + /* > */ ATOM_OP_NEWER, + /* >= */ ATOM_OP_NEWER_EQUAL, + /* = */ ATOM_OP_EQUAL, + /* <= */ ATOM_OP_OLDER_EQUAL, + /* < */ ATOM_OP_OLDER, + /* ~ */ ATOM_OP_PV_EQUAL, + /* ! */ ATOM_OP_BLOCK, + /* !! */ ATOM_OP_BLOCK_HARD, + /* * */ ATOM_OP_STAR, +} atom_operator; + typedef struct { /* XXX: we don't provide PF ... */ + atom_operator pfx_op, sfx_op; char *CATEGORY; char *PN; unsigned int PR_int; @@ -59,6 +74,42 @@ depend_atom *atom_explode(const char *atom) ret->P = ptr + sizeof(*ret); ret->PVR = ret->P + slen + 1; ret->CATEGORY = ret->PVR + slen + 1 + 3; + + /* eat any prefix operators */ + switch (atom[0]) { + case '>': + ++atom; + if (atom[0] == '=') { + ++atom; + ret->pfx_op = ATOM_OP_NEWER_EQUAL; + } else + ret->pfx_op = ATOM_OP_NEWER; + break; + case '=': + ++atom; + ret->pfx_op = ATOM_OP_EQUAL; + break; + case '<': + ++atom; + if (atom[0] == '=') { + ++atom; + ret->pfx_op = ATOM_OP_OLDER_EQUAL; + } else + ret->pfx_op = ATOM_OP_OLDER; + break; + case '~': + ++atom; + ret->pfx_op = ATOM_OP_PV_EQUAL; + break; + case '!': + ++atom; + if (atom[0] == '!') { + ++atom; + ret->pfx_op = ATOM_OP_BLOCK_HARD; + } else + ret->pfx_op = ATOM_OP_BLOCK; + break; + } strcpy(ret->CATEGORY, atom); /* eat file name crap */ @@ -71,6 +122,15 @@ depend_atom *atom_explode(const char *atom) *ptr = '\0'; } + /* see if we have any suffix operators */ + if ((ptr = strrchr(ret->CATEGORY, '*')) != NULL) { + /* make sure it's the last byte */ + if (ptr[1] == '\0') { + ret->sfx_op = ATOM_OP_STAR; + *ptr = '\0'; + } + } + /* break up the CATEOGRY and PVR */ if ((ptr = strrchr(ret->CATEGORY, '/')) != NULL) { ret->PN = ptr + 1; |