comparison src/c/lacweb.c @ 186:88d46972de53

bool in Basis
author Adam Chlipala <adamc@hcoop.net>
date Sun, 03 Aug 2008 18:53:20 -0400
parents c0ea24dcb86f
children 20bf7487c370
comparison
equal deleted inserted replaced
185:19ee24bffbc0 186:88d46972de53
336 *p++ = 0; 336 *p++ = 0;
337 ctx->heap_front = p; 337 ctx->heap_front = p;
338 return r; 338 return r;
339 } 339 }
340 340
341 char *lw_Basis_urlifyBool(lw_context ctx, lw_Basis_bool b) {
342 if (b->tag == lw_Basis_False)
343 return "0";
344 else
345 return "1";
346 }
347
341 static void lw_Basis_urlifyInt_w_unsafe(lw_context ctx, lw_Basis_int n) { 348 static void lw_Basis_urlifyInt_w_unsafe(lw_context ctx, lw_Basis_int n) {
342 int len; 349 int len;
343 350
344 sprintf(ctx->page_front, "%d%n", n, &len); 351 sprintf(ctx->page_front, "%d%n", n, &len);
345 ctx->page_front += len; 352 ctx->page_front += len;
373 ctx->page_front += 3; 380 ctx->page_front += 3;
374 } 381 }
375 } 382 }
376 } 383 }
377 384
385 void lw_Basis_urlifyBool_w(lw_context ctx, lw_Basis_bool b) {
386 if (b->tag == lw_Basis_False)
387 lw_writec(ctx, '0');
388 else
389 lw_writec(ctx, '1');
390 }
391
378 392
379 static char *lw_unurlify_advance(char *s) { 393 static char *lw_unurlify_advance(char *s) {
380 char *new_s = strchr(s, '/'); 394 char *new_s = strchr(s, '/');
381 395
382 if (new_s) 396 if (new_s)
385 new_s = strchr(s, 0); 399 new_s = strchr(s, 0);
386 400
387 return new_s; 401 return new_s;
388 } 402 }
389 403
390 lw_Basis_int lw_unurlifyInt(char **s) { 404 lw_Basis_int lw_Basis_unurlifyInt(lw_context ctx, char **s) {
391 char *new_s = lw_unurlify_advance(*s); 405 char *new_s = lw_unurlify_advance(*s);
392 int r; 406 int r;
393 407
394 r = atoi(*s); 408 r = atoi(*s);
395 *s = new_s; 409 *s = new_s;
396 return r; 410 return r;
397 } 411 }
398 412
399 lw_Basis_float lw_unurlifyFloat(char **s) { 413 lw_Basis_float lw_Basis_unurlifyFloat(lw_context ctx, char **s) {
400 char *new_s = lw_unurlify_advance(*s); 414 char *new_s = lw_unurlify_advance(*s);
401 int r; 415 int r;
402 416
403 r = atof(*s); 417 r = atof(*s);
404 *s = new_s; 418 *s = new_s;
432 } 446 }
433 *s1++ = 0; 447 *s1++ = 0;
434 return s1; 448 return s1;
435 } 449 }
436 450
437 lw_Basis_string lw_unurlifyString(lw_context ctx, char **s) { 451 static struct lw_Basis_bool lw_False = { lw_Basis_False },
452 lw_True = { lw_Basis_True };
453
454 lw_Basis_bool lw_Basis_unurlifyBool(lw_context ctx, char **s) {
455 char *new_s = lw_unurlify_advance(*s);
456 lw_Basis_bool r;
457
458 if (*s[0] == 0 || !strcmp(*s, "0") || !strcmp(*s, "off"))
459 r = &lw_False;
460 else
461 r = &lw_True;
462
463 *s = new_s;
464 return r;
465 }
466
467 lw_Basis_string lw_Basis_unurlifyString(lw_context ctx, char **s) {
438 char *new_s = lw_unurlify_advance(*s); 468 char *new_s = lw_unurlify_advance(*s);
439 char *r, *s1, *s2; 469 char *r, *s1, *s2;
440 int len, n; 470 int len, n;
441 471
442 len = strlen(*s); 472 len = strlen(*s);