summaryrefslogtreecommitdiff
path: root/src/c/urweb.c
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-03-26 16:22:34 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-03-26 16:22:34 -0400
commitdac2c194b1416d7710081d5c57c24d52e110a224 (patch)
tree8ca09d90791aae6d8161cff1362f5c94480788f3 /src/c/urweb.c
parent024acc734f4a323883adb5e9a68f5f4f753e60cc (diff)
Preliminary work supporting channels in databases
Diffstat (limited to 'src/c/urweb.c')
-rw-r--r--src/c/urweb.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 5fa2af42..75f7675f 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -999,6 +999,16 @@ char *uw_Basis_attrifyInt(uw_context ctx, uw_Basis_int n) {
return result;
}
+char *uw_Basis_attrifyChannel(uw_context ctx, uw_Basis_channel n) {
+ char *result;
+ int len;
+ uw_check_heap(ctx, INTS_MAX);
+ result = ctx->heap.front;
+ sprintf(result, "%lld%n", (long long)n, &len);
+ ctx->heap.front += len+1;
+ return result;
+}
+
char *uw_Basis_attrifyFloat(uw_context ctx, uw_Basis_float n) {
char *result;
int len;
@@ -1502,6 +1512,17 @@ char *uw_Basis_sqlifyInt(uw_context ctx, uw_Basis_int n) {
return r;
}
+char *uw_Basis_sqlifyChannel(uw_context ctx, uw_Basis_channel n) {
+ int len;
+ char *r;
+
+ uw_check_heap(ctx, INTS_MAX + 6);
+ r = ctx->heap.front;
+ sprintf(r, "%lld::int4%n", (long long)n, &len);
+ ctx->heap.front += len+1;
+ return r;
+}
+
char *uw_Basis_sqlifyIntN(uw_context ctx, uw_Basis_int *n) {
if (n == NULL)
return "NULL";
@@ -1673,6 +1694,18 @@ uw_Basis_int *uw_Basis_stringToInt(uw_context ctx, uw_Basis_string s) {
return NULL;
}
+uw_Basis_channel *uw_Basis_stringToChannel(uw_context ctx, uw_Basis_string s) {
+ char *endptr;
+ uw_Basis_channel n = strtoll(s, &endptr, 10);
+
+ if (*s != '\0' && *endptr == '\0') {
+ uw_Basis_channel *r = uw_malloc(ctx, sizeof(uw_Basis_channel));
+ *r = n;
+ return r;
+ } else
+ return NULL;
+}
+
uw_Basis_float *uw_Basis_stringToFloat(uw_context ctx, uw_Basis_string s) {
char *endptr;
uw_Basis_float n = strtod(s, &endptr);
@@ -1740,6 +1773,16 @@ uw_Basis_int uw_Basis_stringToInt_error(uw_context ctx, uw_Basis_string s) {
uw_error(ctx, FATAL, "Can't parse int: %s", s);
}
+uw_Basis_channel uw_Basis_stringToChannel_error(uw_context ctx, uw_Basis_string s) {
+ char *endptr;
+ uw_Basis_channel n = strtoll(s, &endptr, 10);
+
+ if (*s != '\0' && *endptr == '\0')
+ return n;
+ else
+ uw_error(ctx, FATAL, "Can't parse channel int: %s", s);
+}
+
uw_Basis_float uw_Basis_stringToFloat_error(uw_context ctx, uw_Basis_string s) {
char *endptr;
uw_Basis_float n = strtod(s, &endptr);