comparison src/c/urweb.c @ 678:5ff1ff38e2db

Preliminary work supporting channels in databases
author Adam Chlipala <adamc@hcoop.net>
date Thu, 26 Mar 2009 16:22:34 -0400
parents a8effb6159c2
children 44f23712020d
comparison
equal deleted inserted replaced
677:81573f62d6c3 678:5ff1ff38e2db
997 sprintf(result, "%lld%n", n, &len); 997 sprintf(result, "%lld%n", n, &len);
998 ctx->heap.front += len+1; 998 ctx->heap.front += len+1;
999 return result; 999 return result;
1000 } 1000 }
1001 1001
1002 char *uw_Basis_attrifyChannel(uw_context ctx, uw_Basis_channel n) {
1003 char *result;
1004 int len;
1005 uw_check_heap(ctx, INTS_MAX);
1006 result = ctx->heap.front;
1007 sprintf(result, "%lld%n", (long long)n, &len);
1008 ctx->heap.front += len+1;
1009 return result;
1010 }
1011
1002 char *uw_Basis_attrifyFloat(uw_context ctx, uw_Basis_float n) { 1012 char *uw_Basis_attrifyFloat(uw_context ctx, uw_Basis_float n) {
1003 char *result; 1013 char *result;
1004 int len; 1014 int len;
1005 uw_check_heap(ctx, FLOATS_MAX); 1015 uw_check_heap(ctx, FLOATS_MAX);
1006 result = ctx->heap.front; 1016 result = ctx->heap.front;
1500 sprintf(r, "%lld::int8%n", n, &len); 1510 sprintf(r, "%lld::int8%n", n, &len);
1501 ctx->heap.front += len+1; 1511 ctx->heap.front += len+1;
1502 return r; 1512 return r;
1503 } 1513 }
1504 1514
1515 char *uw_Basis_sqlifyChannel(uw_context ctx, uw_Basis_channel n) {
1516 int len;
1517 char *r;
1518
1519 uw_check_heap(ctx, INTS_MAX + 6);
1520 r = ctx->heap.front;
1521 sprintf(r, "%lld::int4%n", (long long)n, &len);
1522 ctx->heap.front += len+1;
1523 return r;
1524 }
1525
1505 char *uw_Basis_sqlifyIntN(uw_context ctx, uw_Basis_int *n) { 1526 char *uw_Basis_sqlifyIntN(uw_context ctx, uw_Basis_int *n) {
1506 if (n == NULL) 1527 if (n == NULL)
1507 return "NULL"; 1528 return "NULL";
1508 else 1529 else
1509 return uw_Basis_sqlifyInt(ctx, *n); 1530 return uw_Basis_sqlifyInt(ctx, *n);
1671 return r; 1692 return r;
1672 } else 1693 } else
1673 return NULL; 1694 return NULL;
1674 } 1695 }
1675 1696
1697 uw_Basis_channel *uw_Basis_stringToChannel(uw_context ctx, uw_Basis_string s) {
1698 char *endptr;
1699 uw_Basis_channel n = strtoll(s, &endptr, 10);
1700
1701 if (*s != '\0' && *endptr == '\0') {
1702 uw_Basis_channel *r = uw_malloc(ctx, sizeof(uw_Basis_channel));
1703 *r = n;
1704 return r;
1705 } else
1706 return NULL;
1707 }
1708
1676 uw_Basis_float *uw_Basis_stringToFloat(uw_context ctx, uw_Basis_string s) { 1709 uw_Basis_float *uw_Basis_stringToFloat(uw_context ctx, uw_Basis_string s) {
1677 char *endptr; 1710 char *endptr;
1678 uw_Basis_float n = strtod(s, &endptr); 1711 uw_Basis_float n = strtod(s, &endptr);
1679 1712
1680 if (*s != '\0' && *endptr == '\0') { 1713 if (*s != '\0' && *endptr == '\0') {
1736 1769
1737 if (*s != '\0' && *endptr == '\0') 1770 if (*s != '\0' && *endptr == '\0')
1738 return n; 1771 return n;
1739 else 1772 else
1740 uw_error(ctx, FATAL, "Can't parse int: %s", s); 1773 uw_error(ctx, FATAL, "Can't parse int: %s", s);
1774 }
1775
1776 uw_Basis_channel uw_Basis_stringToChannel_error(uw_context ctx, uw_Basis_string s) {
1777 char *endptr;
1778 uw_Basis_channel n = strtoll(s, &endptr, 10);
1779
1780 if (*s != '\0' && *endptr == '\0')
1781 return n;
1782 else
1783 uw_error(ctx, FATAL, "Can't parse channel int: %s", s);
1741 } 1784 }
1742 1785
1743 uw_Basis_float uw_Basis_stringToFloat_error(uw_context ctx, uw_Basis_string s) { 1786 uw_Basis_float uw_Basis_stringToFloat_error(uw_context ctx, uw_Basis_string s) {
1744 char *endptr; 1787 char *endptr;
1745 uw_Basis_float n = strtod(s, &endptr); 1788 uw_Basis_float n = strtod(s, &endptr);