w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit dfe51e46ef34c64cf1372e34a51fb4e8529ba930
parent 2a4d1d83f8171e17da61b3dfd1fedb8cdcdb419e
Author: ukai <ukai>
Date:   Mon, 10 Dec 2001 15:23:08 +0000

[w3m-dev 02441] A patch against functions *_(un)?quote()
From: Kiyokazu SUTO <suto@ks-and-ks.ne.jp>

Diffstat:
MChangeLog | 9+++++++++
Mindep.c | 37++++++++++---------------------------
Mmyctype.c | 41+++++++++++++++++++++++++++++++++++++++++
Mmyctype.h | 2++
4 files changed, 62 insertions(+), 27 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,12 @@ +2001-12-11 Kiyokazu SUTO <suto@ks-and-ks.ne.jp> + + * [w3m-dev 02441] A patch against functions *_(un)?quote() + * indep.c (url_unquote_char): use GET_MYCDIGIT, instead of sscanf + * indep.c (url_quote): use xdigit[] instead of sprintf() + * myctype.c (MYCTYPE_DIGITMAP): added + * myctype.h (MYCTYPE_DIGITMAP): ditto + * myctype.h (GET_MYCDIGIT): added + 2001-12-11 Fumitoshi UKAI <ukai@debian.or.jp> * [w3m-dev 02647] diff --git a/indep.c b/indep.c @@ -427,45 +427,28 @@ html_unquote(char *str) return str; } -static int -url_unquote_char(char **str) -{ - char *p = *str; - char buf[3]; - int n; +static char xdigit[0x10] = "0123456789ABCDEF"; - if (*p != '%') - return -1; - p++; - if (IS_XDIGIT(*p)) { - buf[0] = *(p++); - if (IS_XDIGIT(*p)) { - buf[1] = *(p++); - buf[2] = '\0'; - } - else - buf[1] = '\0'; - if (sscanf(buf, "%x", &n)) { - *str = p; - return n; - } - } - return -1; -} +#define url_unquote_char(pstr) \ + (IS_XDIGIT((*(pstr))[1]) ? \ + (IS_XDIGIT((*(pstr))[2]) ? \ + (*(pstr) += 3, (GET_MYCDIGIT((*(pstr))[-2]) << 4) | GET_MYCDIGIT((*(pstr))[-1])) : \ + (*(pstr) += 2, GET_MYCDIGIT((*(pstr))[-1]))) : \ + -1) char * url_quote(char *str) { Str tmp = NULL; char *p; - char buf[4]; for (p = str; *p; p++) { if (IS_CNTRL(*p) || *p == ' ' || !IS_ASCII(*p)) { if (tmp == NULL) tmp = Strnew_charp_n(str, (int)(p - str)); - sprintf(buf, "%%%02X", (unsigned char)*p); - Strcat_charp(tmp, buf); + Strcat_char(tmp, '%'); + Strcat_char(tmp, xdigit[((unsigned char)*p >> 4) & 0xF]); + Strcat_char(tmp, xdigit[(unsigned char)*p & 0xF]); } else { if (tmp) diff --git a/myctype.c b/myctype.c @@ -27,6 +27,47 @@ unsigned char MYCTYPE_MAP[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; +unsigned char MYCTYPE_DIGITMAP[0x100] = { + /* NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI */ + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US */ + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + /* SPC ! " # $ % & ' ( ) * + , - . / */ + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, 255, 255, 255, 255, 255, + /* @ A B C D E F G H I J K L M N O */ + 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, + /* P Q R S T U V W X Y Z [ \ ] ^ _ */ + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + /* ` a b c d e f g h i j k l m n o */ + 255, 10, 11, 12, 13, 14, 15, 255, 255, 255, 255, 255, 255, 255, 255, 255, + /* p q r s t u v w x y z { | } ~ DEL */ + + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, +}; + unsigned char INTCTYPE_MAP[0x100] = { diff --git a/myctype.h b/myctype.h @@ -12,6 +12,7 @@ #define MYCTYPE_XDIGIT (MYCTYPE_HEX|MYCTYPE_DIGIT) #define GET_MYCTYPE(x) (MYCTYPE_MAP[(int)(unsigned char)(x)]) +#define GET_MYCDIGIT(x) (MYCTYPE_DIGITMAP[(int)(unsigned char)(x)]) #define IS_CNTRL(x) (GET_MYCTYPE(x) & MYCTYPE_CNTRL) #define IS_SPACE(x) (GET_MYCTYPE(x) & MYCTYPE_SPACE) @@ -22,6 +23,7 @@ #define IS_XDIGIT(x) (GET_MYCTYPE(x) & MYCTYPE_XDIGIT) extern unsigned char MYCTYPE_MAP[]; +extern unsigned char MYCTYPE_DIGITMAP[]; #define INTCTYPE_ASCII 1