8 static inline unsigned char nib2hex(int c
)
10 return (c
>=10 ? c
+'a'-10 : c
+ '0');
13 static inline unsigned int hex2nib(unsigned char c
)
17 if (c
>= 'a' && c
<= 'f')
19 if (c
>= 'A' && c
<= 'F')
25 void path_encode(struct grow
*g
, const char *path
)
32 while ((c
= *path
++)) {
33 if (isalnum(c
) || c
== '_' || c
== '/' || c
== '.') {
36 buf
[1] = nib2hex(c
>>4);
37 buf
[2] = nib2hex(c
&15);
38 grow_append(g
, buf
, 3);
43 void path_decode(struct grow
*g
, const char *path
)
47 while ((c
= *path
++)) {
49 d
= hex2nib(*path
++) << 4;
50 d
+= hex2nib(*path
++);
52 } else if (c
== '&' && !strncasecmp(path
, "amp;", 4)) {
55 /* } else if (c == '+') { */
56 /* grow_put(g, ' '); */
65 struct grow g
= GROW_INIT
, h
= GROW_INIT
;
67 int main(int argc
, char *argv
[])
69 path_encode(&g
, argv
[1]);
70 path_decode(&h
, argv
[2]);
74 printf("'%s' '%s'\n", g
.arr
, h
.arr
);
80 struct grow g
= GROW_INIT
, h
= GROW_INIT
;
82 int main(int argc
, char *argv
[])
84 char *p
=argv
[1], *r
=argv
[2];
87 printf("usage: %s <http_root> <path> <prefix>\n", argv
[0]);
98 if (pfx
[strlen(pfx
)-1] != '/')
102 printf("%s\n", grow_cstr(&g
));