Revert "Introduce bsearch() and use it in tagtree.c."

It was committed by accident (it's on FS still).

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30157 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2011-07-18 18:57:50 +00:00
parent 76b6db375a
commit 1b7ff725c6
4 changed files with 65 additions and 147 deletions

View file

@ -29,7 +29,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "string-extra.h" #include "string-extra.h"
#include "bsearch.h"
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "kernel.h" #include "kernel.h"
@ -161,13 +160,6 @@ struct match
int symbol; int symbol;
}; };
static int compare_match(const void* _key, const void* _elem)
{
const char* key = _key;
const struct match *elem = _elem;
return strcasecmp(key, elem->str);
}
/* Statusbar text of the current view. */ /* Statusbar text of the current view. */
static char current_title[MAX_TAGS][128]; static char current_title[MAX_TAGS][128];
@ -229,42 +221,42 @@ static int get_token_str(char *buf, int size)
static int get_tag(int *tag) static int get_tag(int *tag)
{ {
static const struct match get_tag_match[] = static const struct match get_tag_match[] =
{ /* sorted by ascii (case insensitive) for bsearch */ {
{ "%format", var_format }, {"album", tag_album},
{ "%include", var_include }, {"artist", tag_artist},
{ "%limit", var_limit }, {"bitrate", tag_bitrate},
{"%menu_start",var_menu_start}, {"composer", tag_composer},
{"%root_menu",var_rootmenu}, {"comment", tag_comment},
{ "%sort", var_sorttype }, {"albumartist", tag_albumartist},
{ "%strip", var_strip }, {"ensemble", tag_albumartist},
{"->",menu_next}, {"grouping", tag_grouping},
{ "==>", menu_load }, {"genre", tag_genre},
{ "album", tag_album }, {"length", tag_length},
{ "albumartist", tag_albumartist }, {"Lm", tag_virt_length_min},
{ "artist", tag_artist }, {"Ls", tag_virt_length_sec},
{ "autoscore", tag_virt_autoscore }, {"Pm", tag_virt_playtime_min},
{ "bitrate", tag_bitrate }, {"Ps", tag_virt_playtime_sec},
{ "comment", tag_comment }, {"title", tag_title},
{ "commitid", tag_commitid }, {"filename", tag_filename},
{ "composer", tag_composer }, {"tracknum", tag_tracknumber},
{ "discnum", tag_discnumber }, {"discnum", tag_discnumber},
{ "ensemble", tag_albumartist }, {"year", tag_year},
{ "entryage", tag_virt_entryage }, {"playcount", tag_playcount},
{ "filename", tag_filename }, {"rating", tag_rating},
{ "genre", tag_genre }, {"lastplayed", tag_lastplayed},
{ "grouping", tag_grouping }, {"lastoffset", tag_lastoffset},
{ "lastoffset", tag_lastoffset }, {"commitid", tag_commitid},
{ "lastplayed", tag_lastplayed }, {"entryage", tag_virt_entryage},
{ "length", tag_length }, {"autoscore", tag_virt_autoscore},
{ "Lm", tag_virt_length_min }, {"%sort", var_sorttype},
{ "Ls", tag_virt_length_sec }, {"%limit", var_limit},
{ "playcount", tag_playcount }, {"%strip", var_strip},
{ "Pm", tag_virt_playtime_min }, {"%menu_start", var_menu_start},
{ "Ps", tag_virt_playtime_sec }, {"%include", var_include},
{ "rating", tag_rating }, {"%root_menu", var_rootmenu},
{ "title", tag_title }, {"%format", var_format},
{ "tracknum", tag_tracknumber }, {"->", menu_next},
{ "year", tag_year }, {"==>", menu_load}
}; };
char buf[128]; char buf[128];
unsigned int i; unsigned int i;
@ -285,13 +277,15 @@ static int get_tag(int *tag)
} }
buf[i] = '\0'; buf[i] = '\0';
struct match *elem = bsearch(buf, get_tag_match, ARRAYLEN(get_tag_match), for (i = 0; i < ARRAYLEN(get_tag_match); i++)
sizeof(struct match), compare_match);
if (elem)
{ {
*tag = elem->symbol; if (!strcasecmp(buf, get_tag_match[i].str))
{
*tag = get_tag_match[i].symbol;
return 1; return 1;
} }
}
logf("NO MATCH: %s\n", buf); logf("NO MATCH: %s\n", buf);
if (buf[0] == '?') if (buf[0] == '?')
return 0; return 0;
@ -302,21 +296,21 @@ static int get_tag(int *tag)
static int get_clause(int *condition) static int get_clause(int *condition)
{ {
static const struct match get_clause_match[] = static const struct match get_clause_match[] =
{ /* sorted by ascii (case insensitive) for bsearch */ {
{ "!$", clause_not_ends_with }, {"=", clause_is},
{ "!=", clause_is_not }, {"==", clause_is},
{ "!^", clause_not_begins_with }, {"!=", clause_is_not},
{ "!~", clause_not_contains }, {">", clause_gt},
{ "$", clause_ends_with }, {">=", clause_gteq},
{ "<", clause_lt }, {"<", clause_lt},
{ "<=", clause_lteq }, {"<=", clause_lteq},
{ "=", clause_is }, {"~", clause_contains},
{ "==", clause_is }, {"!~", clause_not_contains},
{ ">", clause_gt }, {"^", clause_begins_with},
{ ">=", clause_gteq }, {"!^", clause_not_begins_with},
{ "@", clause_oneof }, {"$", clause_ends_with},
{ "^", clause_begins_with }, {"!$", clause_not_ends_with},
{ "~", clause_contains }, {"@", clause_oneof}
}; };
char buf[4]; char buf[4];
@ -338,13 +332,15 @@ static int get_clause(int *condition)
} }
buf[i] = '\0'; buf[i] = '\0';
struct match *elem = bsearch(buf, get_clause_match, ARRAYLEN(get_clause_match), for (i = 0; i < ARRAYLEN(get_clause_match); i++)
sizeof(struct match), compare_match);
if (elem)
{ {
*condition = elem->symbol; if (!strcasecmp(buf, get_clause_match[i].str))
{
*condition = get_clause_match[i].symbol;
return 1; return 1;
} }
}
return 0; return 0;
} }

View file

@ -105,7 +105,6 @@ libc/mktime.c
/* Common */ /* Common */
common/version.c common/version.c
common/bsearch.c
common/config.c common/config.c
common/crc32.c common/crc32.c
#ifdef MI4_FORMAT #ifdef MI4_FORMAT

View file

@ -1,49 +0,0 @@
/* Copyright (C) 1991,92,97,2000,02 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#include <stdlib.h>
/* Perform a binary search for KEY in BASE which has NMEMB elements
of SIZE bytes each. The comparisons are done by (*COMPAR)(). */
void *
bsearch (const void *key, const void *base, size_t nmemb, size_t size,
int (*compar) (const void *, const void *))
{
size_t l, u, idx;
const void *p;
int comparison;
l = 0;
u = nmemb;
while (l < u)
{
idx = (l + u) / 2;
p = (void *) (((const char *) base) + (idx * size));
comparison = (*compar) (key, p);
if (comparison < 0)
u = idx;
else if (comparison > 0)
l = idx + 1;
else
return (void *) p;
}
return NULL;
}
/* libc_hidden_def (bsearch) */

View file

@ -1,28 +0,0 @@
/* Copyright (C) 1991,92,97,2000,02 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#ifndef __BSEARCH_H__
#define __BSEARCH_H__
/* Perform a binary search for KEY in BASE which has NMEMB elements
of SIZE bytes each. The comparisons are done by (*COMPAR)(). */
void *
bsearch (const void *key, const void *base, size_t nmemb, size_t size,
int (*compar) (const void *, const void *));
#endif