comparison src/c/lacweb.c @ 137:4ffdbf429e8d

Replaced allocation stubs
author Adam Chlipala <adamc@hcoop.net>
date Thu, 17 Jul 2008 14:32:49 -0400
parents 133fa2d51bb4
children d6d78055f001
comparison
equal deleted inserted replaced
136:133fa2d51bb4 137:4ffdbf429e8d
118 char *result; 118 char *result;
119 int len; 119 int len;
120 lw_check_heap(ctx, INTS_MAX); 120 lw_check_heap(ctx, INTS_MAX);
121 result = ctx->heap_front; 121 result = ctx->heap_front;
122 sprintf(result, "%d%n", n, &len); 122 sprintf(result, "%d%n", n, &len);
123 ctx->heap_front += len; 123 ctx->heap_front += len+1;
124 return result; 124 return result;
125 } 125 }
126 126
127 char *lw_Basis_attrifyFloat(lw_context ctx, lw_Basis_float n) { 127 char *lw_Basis_attrifyFloat(lw_context ctx, lw_Basis_float n) {
128 char *result; 128 char *result;
129 int len; 129 int len;
130 lw_check_heap(ctx, INTS_MAX); 130 lw_check_heap(ctx, FLOATS_MAX);
131 result = ctx->heap_front; 131 result = ctx->heap_front;
132 sprintf(result, "%g%n", n, &len); 132 sprintf(result, "%g%n", n, &len);
133 ctx->heap_front += len; 133 ctx->heap_front += len+1;
134 return result; 134 return result;
135 } 135 }
136 136
137 char *lw_Basis_attrifyString(lw_context ctx, lw_Basis_string s) { 137 char *lw_Basis_attrifyString(lw_context ctx, lw_Basis_string s) {
138 int len = strlen(s); 138 int len = strlen(s);
139 char *result, *p; 139 char *result, *p;
140 lw_check_heap(ctx, len * 6); 140 lw_check_heap(ctx, len * 6 + 1);
141 141
142 result = p = ctx->heap_front; 142 result = p = ctx->heap_front;
143 143
144 for (; *s; s++) { 144 for (; *s; s++) {
145 char c = *s; 145 char c = *s;
158 sprintf(p, "&#%d;%n", c, &len2); 158 sprintf(p, "&#%d;%n", c, &len2);
159 p += len2; 159 p += len2;
160 } 160 }
161 } 161 }
162 162
163 *p++ = 0;
163 ctx->heap_front = p; 164 ctx->heap_front = p;
164 return result; 165 return result;
165 } 166 }
166 167
167 static void lw_Basis_attrifyInt_w_unsafe(lw_context ctx, lw_Basis_int n) { 168 static void lw_Basis_attrifyInt_w_unsafe(lw_context ctx, lw_Basis_int n) {
203 } 204 }
204 } 205 }
205 } 206 }
206 207
207 208
208 char *lw_Basis_urlifyInt(lw_Basis_int n) { 209 char *lw_Basis_urlifyInt(lw_context ctx, lw_Basis_int n) {
209 return "0"; 210 int len;
210 } 211 char *r;
211 212
212 char *lw_Basis_urlifyFloat(lw_Basis_float n) { 213 lw_check_heap(ctx, INTS_MAX);
213 return "0.0"; 214 r = ctx->heap_front;
214 } 215 sprintf(r, "%d%n", n, &len);
215 216 ctx->heap_front += len+1;
216 char *lw_Basis_urlifyString(lw_Basis_string s) { 217 return r;
217 return ""; 218 }
219
220 char *lw_Basis_urlifyFloat(lw_context ctx, lw_Basis_float n) {
221 int len;
222 char *r;
223
224 lw_check_heap(ctx, FLOATS_MAX);
225 r = ctx->heap_front;
226 sprintf(r, "%g%n", n, &len);
227 ctx->heap_front += len+1;
228 return r;
229 }
230
231 char *lw_Basis_urlifyString(lw_context ctx, lw_Basis_string s) {
232 char *r, *p;
233
234 lw_check_heap(ctx, strlen(s) * 3 + 1);
235
236 for (r = p = ctx->heap_front; *s; s++) {
237 char c = *s;
238
239 if (c == ' ')
240 *p++ = '+';
241 else if (isalnum(c))
242 *p++ = c;
243 else {
244 sprintf(p, "%%%02X", c);
245 p += 3;
246 }
247 }
248
249 *p++ = 0;
250 ctx->heap_front = p;
251 return r;
218 } 252 }
219 253
220 static void lw_Basis_urlifyInt_w_unsafe(lw_context ctx, lw_Basis_int n) { 254 static void lw_Basis_urlifyInt_w_unsafe(lw_context ctx, lw_Basis_int n) {
221 int len; 255 int len;
222 256
320 return r; 354 return r;
321 } 355 }
322 356
323 357
324 char *lw_Basis_htmlifyString(lw_context ctx, lw_Basis_string s) { 358 char *lw_Basis_htmlifyString(lw_context ctx, lw_Basis_string s) {
325 return ""; 359 char *r, *s2;
360
361 lw_check_heap(ctx, strlen(s) * 5 + 1);
362
363 for (r = s2 = ctx->heap_front; *s; s++) {
364 char c = *s;
365
366 switch (c) {
367 case '<':
368 strcpy(s2, "&lt;");
369 s2 += 4;
370 break;
371 case '&':
372 strcpy(s2, "&amp;");
373 s2 += 5;
374 break;
375 default:
376 if (isprint(c))
377 *s2++ = c;
378 else {
379 int len2;
380 sprintf(s2, "&#%d;%n", c, &len2);
381 s2 += len2;
382 }
383 }
384 }
385
386 *s2++ = 0;
387 ctx->heap_front = s2;
388 return r;
326 } 389 }
327 390
328 void lw_Basis_htmlifyString_w(lw_context ctx, lw_Basis_string s) { 391 void lw_Basis_htmlifyString_w(lw_context ctx, lw_Basis_string s) {
329 lw_check(ctx, strlen(s) * 5); 392 lw_check(ctx, strlen(s) * 5);
330 393