5102 |
pushn((RWSTYPE) temp_space_fix(base)); |
pushn((RWSTYPE) temp_space_fix(base)); |
5103 |
} |
} |
5104 |
|
|
5105 |
|
#define ISPRINT(c) (((unsigned char)c) < 128 && (isalnum(c) || c == '-')) |
5106 |
|
|
5107 |
|
static void |
5108 |
|
bi_qprn() |
5109 |
|
{ |
5110 |
|
char *s = (char*)getarg(1); |
5111 |
|
char *p; |
5112 |
|
size_t count; |
5113 |
|
|
5114 |
|
for (count = 0, p = s; *p; p++) |
5115 |
|
if (!ISPRINT(*p)) |
5116 |
|
count++; |
5117 |
|
|
5118 |
|
/* Each encoded character takes 3 bytes. */ |
5119 |
|
p = heap_reserve(strlen(s) + 2*count + 1); |
5120 |
|
|
5121 |
|
pushn((RWSTYPE) p); |
5122 |
|
for (; *s; s++) { |
5123 |
|
if (ISPRINT(*s)) |
5124 |
|
*p++ = *s; |
5125 |
|
else { |
5126 |
|
char buf[3]; |
5127 |
|
snprintf(buf, sizeof buf, "%2X", *s); |
5128 |
|
*p++ = '%'; |
5129 |
|
*p++ = buf[0]; |
5130 |
|
*p++ = buf[1]; |
5131 |
|
} |
5132 |
|
} |
5133 |
|
*p = 0; |
5134 |
|
} |
5135 |
|
|
5136 |
static builtin_t builtin[] = { |
static builtin_t builtin[] = { |
5137 |
{ bi_length, "length", Integer, "s" }, |
{ bi_length, "length", Integer, "s" }, |
5138 |
{ bi_index, "index", Integer, "si" }, |
{ bi_index, "index", Integer, "si" }, |
5148 |
{ bi_inet_aton, "inet_aton", Integer, "s" }, |
{ bi_inet_aton, "inet_aton", Integer, "s" }, |
5149 |
{ bi_sub, "sub", String, "sss" }, |
{ bi_sub, "sub", String, "sss" }, |
5150 |
{ bi_gsub, "gsub", String, "sss" }, |
{ bi_gsub, "gsub", String, "sss" }, |
5151 |
|
{ bi_qprn, "qprn", String, "s" }, |
5152 |
{ NULL } |
{ NULL } |
5153 |
}; |
}; |
5154 |
|
|