1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-25 01:05:37 +00:00

Patch 3: Further fixes including strcasestr and convert_to_lowercase

This commit is contained in:
M. Vefa Bicakci 2008-11-01 18:13:24 +01:00 committed by Kalle Olavi Niemitalo
parent a3abd3b275
commit 5bd3425540
13 changed files with 39 additions and 16 deletions

View File

@ -530,7 +530,7 @@ test_search(struct listbox_item *item, void *data_, int *offset)
assert(ctx->title && ctx->url);
ctx->found = (*ctx->title && strcasestr(bm->title, ctx->title))
|| (*ctx->url && strcasestr(bm->url, ctx->url));
|| (*ctx->url && c_strcasestr(bm->url, ctx->url));
if (ctx->found) *offset = 0;
}

4
src/cache/dialogs.c vendored
View File

@ -175,8 +175,8 @@ match_cache_entry(struct listbox_item *item, struct terminal *term,
{
struct cache_entry *cached = item->udata;
if (strcasestr(struri(cached->uri), text)
|| (cached->head && strcasestr(cached->head, text)))
if (c_strcasestr(struri(cached->uri), text)
|| (cached->head && c_strcasestr(cached->head, text)))
return LISTBOX_MATCH_OK;
return LISTBOX_MATCH_NO;

View File

@ -17,6 +17,7 @@
#include "intl/gettext/libintl.h"
#include "main/event.h"
#include "terminal/kbd.h"
#include "util/conv.h"
#include "util/memory.h"
#include "util/string.h"

View File

@ -753,21 +753,21 @@ html_link_parse(struct html_context *html_context, unsigned char *a,
return 1;
}
if (strcasestr(link->name, "icon") ||
(link->content_type && strcasestr(link->content_type, "icon"))) {
if (c_strcasestr(link->name, "icon") ||
(link->content_type && c_strcasestr(link->content_type, "icon"))) {
link->type = LT_ICON;
} else if (strcasestr(link->name, "alternate")) {
} else if (c_strcasestr(link->name, "alternate")) {
link->type = LT_ALTERNATE;
if (link->lang)
link->type = LT_ALTERNATE_LANG;
else if (strcasestr(link->name, "stylesheet") ||
(link->content_type && strcasestr(link->content_type, "css")))
else if (c_strcasestr(link->name, "stylesheet") ||
(link->content_type && c_strcasestr(link->content_type, "css")))
link->type = LT_ALTERNATE_STYLESHEET;
else if (link->media)
link->type = LT_ALTERNATE_MEDIA;
} else if (link->content_type && strcasestr(link->content_type, "css")) {
} else if (link->content_type && c_strcasestr(link->content_type, "css")) {
link->type = LT_STYLESHEET;
}

View File

@ -299,7 +299,7 @@ globhist_simple_search(unsigned char *search_url, unsigned char *search_title)
if ((*search_title
&& strcasestr(history_item->title, search_title))
|| (*search_url
&& strcasestr(history_item->url, search_url))) {
&& c_strcasestr(history_item->url, search_url))) {
history_item->box_item->visible = 1;
} else {
history_item->box_item->visible = 0;

View File

@ -248,7 +248,7 @@ get_fragment_content_type(struct cache_entry *cached)
if (!sample)
return NULL;
if (strcasestr(sample, "<html>"))
if (c_strcasestr(sample, "<html>"))
ctype = stracpy("text/html");
mem_free(sample);

View File

@ -41,7 +41,7 @@ get_system_env(void)
int env = get_common_env();
unsigned char *term = getenv("TERM");
if (!term || (toupper(term[0]) == 'B' && toupper(term[1]) == 'E'))
if (!term || (c_toupper(term[0]) == 'B' && c_toupper(term[1]) == 'E'))
env |= ENV_BE;
return env;

View File

@ -37,7 +37,7 @@ proxy_probe_no_proxy(unsigned char *url, unsigned char *no_proxy)
skip_space(no_proxy);
if (jumper) *jumper = '\0';
if (strcasestr(url, no_proxy)) {
if (c_strcasestr(url, no_proxy)) {
if (jumper) *jumper = ',';
if (slash) *slash = '/';
return 1;

View File

@ -682,7 +682,7 @@ normalize_uri(struct uri *uri, unsigned char *uristring)
* get_translated_uri() through translate_url() calls this
* function and then it already works on and modifies an
* allocated copy. */
convert_to_lowercase(uri->string, uri->protocollen);
convert_to_lowercase_locale_indep(uri->string, uri->protocollen);
if (uri->hostlen) convert_to_lowercase(uri->host, uri->hostlen);
parse = 1;

View File

@ -104,7 +104,7 @@ get_user_program(struct terminal *term, unsigned char *progid, int progidlen)
/* Now add lowercased progid part. Delicious. */
add_bytes_to_string(&name, progid, progidlen);
convert_to_lowercase(&name.source[sizeof("protocol.user.") - 1], progidlen);
convert_to_lowercase_locale_indep(&name.source[sizeof("protocol.user.") - 1], progidlen);
add_char_to_string(&name, '.');
add_to_string(&name, get_system_str(xwin));

View File

@ -361,7 +361,7 @@ strtolx(unsigned char *str, unsigned char **end)
if (errno) return 0;
if (!*end) return num;
postfix = toupper(**end);
postfix = c_toupper(**end);
if (postfix == 'K') {
(*end)++;
if (num < -INT_MAX / 1024) return -INT_MAX;

View File

@ -318,6 +318,25 @@ int c_strncasecmp (const char *s1, const char *s2, size_t n)
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
}
/* c_strcasestr - adapted from src/osdep/stub.c */
char * c_strcasestr(const char *haystack, const char *needle)
{
size_t haystack_length = strlen(haystack);
size_t needle_length = strlen(needle);
int i;
if (haystack_length < needle_length)
return NULL;
for (i = haystack_length - needle_length + 1; i; i--) {
if (!c_strncasecmp(haystack, needle, needle_length))
return (char *) haystack;
haystack++;
}
return NULL;
}
/* The new string utilities: */
/* TODO Currently most of the functions use add_bytes_to_string() as a backend

View File

@ -102,6 +102,9 @@ int elinks_strlcasecmp(const unsigned char *s1, size_t n1,
int c_strcasecmp(const char *s1, const char *s2);
int c_strncasecmp(const char *s1, const char *s2, size_t n);
/* strcasestr function which works as if it is in the C locale. */
char * c_strcasestr(const char *haystack, const char *needle);
#define skip_space(S) \
do { while (isspace(*(S))) (S)++; } while (0)