diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | indep.c | 39 | ||||
-rw-r--r-- | myctype.c | 43 | ||||
-rw-r--r-- | myctype.h | 4 |
4 files changed, 66 insertions, 31 deletions
@@ -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] @@ -1124,4 +1133,4 @@ * release-0-2-1 * import w3m-0.2.1 -$Id: ChangeLog,v 1.119 2001/12/10 15:04:09 ukai Exp $ +$Id: ChangeLog,v 1.120 2001/12/10 15:23:08 ukai Exp $ @@ -1,4 +1,4 @@ -/* $Id: indep.c,v 1.14 2001/12/02 16:26:08 ukai Exp $ */ +/* $Id: indep.c,v 1.15 2001/12/10 15:23:08 ukai Exp $ */ #include "fm.h" #include <stdio.h> #include <pwd.h> @@ -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) @@ -1,4 +1,4 @@ -/* $Id: myctype.c,v 1.4 2001/11/24 02:01:26 ukai Exp $ */ +/* $Id: myctype.c,v 1.5 2001/12/10 15:23:08 ukai Exp $ */ unsigned char MYCTYPE_MAP[0x100] = { /* NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1, @@ -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] = { @@ -1,4 +1,4 @@ -/* $Id: myctype.h,v 1.3 2001/11/20 17:49:23 ukai Exp $ */ +/* $Id: myctype.h,v 1.4 2001/12/10 15:23:08 ukai Exp $ */ #ifndef _MYCTYPE_H #define _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 |