diff options
author | Tatsuya Kinoshita <tats@debian.org> | 2021-01-02 00:20:37 +0000 |
---|---|---|
committer | Tatsuya Kinoshita <tats@debian.org> | 2021-01-02 00:20:37 +0000 |
commit | 1d0ba25a660483da1272a31dd077ed94441e3d9f (patch) | |
tree | 1d8dee52cd1e3d340fe178a8193dc96c4496db84 /indep.c | |
parent | Merge branch 'cvstrunk' into upstream (diff) | |
download | w3m-1d0ba25a660483da1272a31dd077ed94441e3d9f.tar.gz w3m-1d0ba25a660483da1272a31dd077ed94441e3d9f.zip |
New upstream version 0.5.3+git20210102upstream/0.5.3+git20210102upstream
Diffstat (limited to 'indep.c')
-rw-r--r-- | indep.c | 125 |
1 files changed, 122 insertions, 3 deletions
@@ -19,7 +19,7 @@ unsigned char QUOTE_MAP[0x100] = { /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US */ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, /* SPC ! " # $ % & ' ( ) * + , - . / */ - 24, 72, 76, 40, 8, 40, 41, 72, 72, 72, 72, 40, 72, 8, 0, 64, + 24, 72, 76, 40, 8, 40, 41, 77, 72, 72, 72, 40, 72, 8, 0, 64, /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 72, 74, 72, 75, 40, /* @ A B C D E F G H I J K L M N O */ @@ -47,7 +47,7 @@ char *HTML_QUOTE_MAP[] = { "<", ">", """, - NULL, + "'", NULL, NULL, }; @@ -357,6 +357,20 @@ strcasemstr(char *str, char *srch[], char **ret_ptr) return -1; } +int +strmatchlen(const char *s1, const char *s2, int maxlen) +{ + int i; + + /* To allow the maxlen to be negatie (infinity), + * compare by "!=" instead of "<=". */ + for (i = 0; i != maxlen; ++i) { + if (!s1[i] || !s2[i] || s1[i] != s2[i]) + break; + } + return i; +} + char * remove_space(char *str) { @@ -448,7 +462,7 @@ getescapechar(char **str) q = p; for (p++; IS_ALNUM(*p); p++) ; q = allocStr(q, p - q); - if (strcasestr("lt gt amp quot nbsp", q) && *p != '=') { + if (strcasestr("lt gt amp quot apos nbsp", q) && *p != '=') { /* a character entity MUST be terminated with ";". However, * there's MANY web pages which uses < , > or something * like them as <, >, etc. Therefore, we treat the most @@ -707,6 +721,111 @@ shell_quote(char *str) return str; } +void * +xrealloc(void *ptr, size_t size) +{ + void *newptr = realloc(ptr, size); + if (newptr == NULL) { + fprintf(stderr, "Out of memory\n"); + exit(-1); + } + return newptr; +} + +/* Define this as a separate function in case the free() has + * an incompatible prototype. */ +void +xfree(void *ptr) +{ + free(ptr); +} + +void * +w3m_GC_realloc_atomic(void *ptr, size_t size) +{ + return ptr ? GC_REALLOC(ptr, size) : GC_MALLOC_ATOMIC(size); +} + +void +w3m_GC_free(void *ptr) +{ + GC_FREE(ptr); +} + +void +growbuf_init(struct growbuf *gb) +{ + gb->ptr = NULL; + gb->length = 0; + gb->area_size = 0; + gb->realloc_proc = &w3m_GC_realloc_atomic; + gb->free_proc = &w3m_GC_free; +} + +void +growbuf_init_without_GC(struct growbuf *gb) +{ + gb->ptr = NULL; + gb->length = 0; + gb->area_size = 0; + gb->realloc_proc = &xrealloc; + gb->free_proc = &xfree; +} + +void +growbuf_clear(struct growbuf *gb) +{ + (*gb->free_proc) (gb->ptr); + gb->ptr = NULL; + gb->length = 0; + gb->area_size = 0; +} + +Str +growbuf_to_Str(struct growbuf *gb) +{ + Str s; + + if (gb->free_proc == &w3m_GC_free) { + growbuf_reserve(gb, gb->length + 1); + gb->ptr[gb->length] = '\0'; + s = New(struct _Str); + s->ptr = gb->ptr; + s->length = gb->length; + s->area_size = gb->area_size; + } else { + s = Strnew_charp_n(gb->ptr, gb->length); + (*gb->free_proc) (gb->ptr); + } + gb->ptr = NULL; + gb->length = 0; + gb->area_size = 0; + return s; +} + +void +growbuf_reserve(struct growbuf *gb, int leastarea) +{ + int newarea; + + if (gb->area_size < leastarea) { + newarea = gb->area_size * 3 / 2; + if (newarea < leastarea) + newarea = leastarea; + newarea += 16; + gb->ptr = (*gb->realloc_proc) (gb->ptr, newarea); + gb->area_size = newarea; + } +} + +void +growbuf_append(struct growbuf *gb, const char *src, int len) +{ + growbuf_reserve(gb, gb->length + len); + memcpy(&gb->ptr[gb->length], src, len); + gb->length += len; +} + static char * w3m_dir(const char *name, char *dft) { |