changeset 922:d6a71f19a3d8

Find chances to use mstrcat()
author Adam Chlipala <adamc@hcoop.net>
date Wed, 09 Sep 2009 08:15:46 -0400
parents ae0110465421
children 0a91c6ee7eec
files include/urweb.h src/c/urweb.c src/cjr_print.sml
diffstat 3 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/include/urweb.h	Wed Sep 09 08:00:45 2009 -0400
+++ b/include/urweb.h	Wed Sep 09 08:15:46 2009 -0400
@@ -120,6 +120,7 @@
 uw_Basis_char uw_Basis_strsub(uw_context, const char *, uw_Basis_int);
 uw_Basis_string uw_Basis_strsuffix(uw_context, const char *, uw_Basis_int);
 uw_Basis_string uw_Basis_strcat(uw_context, const char *, const char *);
+uw_Basis_string uw_Basis_mstrcat(uw_context ctx, ...);
 uw_Basis_int *uw_Basis_strindex(uw_context, const char *, uw_Basis_char);
 uw_Basis_string uw_Basis_strchr(uw_context, const char *, uw_Basis_char);
 uw_Basis_int uw_Basis_strcspn(uw_context, const char *, const char *);
--- a/src/c/urweb.c	Wed Sep 09 08:00:45 2009 -0400
+++ b/src/c/urweb.c	Wed Sep 09 08:15:46 2009 -0400
@@ -2836,3 +2836,23 @@
   return r;
 }
 
+uw_Basis_string uw_Basis_mstrcat(uw_context ctx, ...) {
+  va_list ap;
+  size_t len = 1;
+  char *s, *r, *s2;
+  
+  va_start(ap, ctx);
+  for (s = va_arg(ap, char*); s; s = va_arg(ap, char*))
+    len += strlen(s);
+  va_end(ap);
+
+  r = uw_malloc(ctx, len);
+  va_start(ap, ctx);
+  for (s2 = r, s = va_arg(ap, char*); s; s = va_arg(ap, char*))
+    while (*s)
+      *s2++ = *s++;
+  va_end(ap);
+  *s2 = 0;
+
+  return r;
+}
--- a/src/cjr_print.sml	Wed Sep 09 08:00:45 2009 -0400
+++ b/src/cjr_print.sml	Wed Sep 09 08:15:46 2009 -0400
@@ -1468,6 +1468,24 @@
       | EApp ((EReturnBlob {blob, mimeType, t = (TFun (_, ran), _)}, loc), _) =>
         p_exp env (EReturnBlob {blob = blob, mimeType = mimeType, t = ran}, loc)
 
+      | EFfiApp ("Basis", "strcat", [e1, e2]) =>
+        let
+            fun flatten e =
+                case #1 e of
+                    EFfiApp ("Basis", "strcat", [e1, e2]) => flatten e1 @ flatten e2
+                  | _ => [e]
+        in
+            case flatten e1 @ flatten e2 of
+                [e1, e2] => box [string "uw_Basis_strcat(ctx, ",
+                                 p_exp env e1,
+                                 string ",",
+                                 p_exp env e2,
+                                 string ")"]
+              | es => box [string "uw_Basis_mstrcat(ctx, ",
+                           p_list (p_exp env) es,
+                           string ", NULL)"]
+        end
+
       | EFfiApp (m, x, []) => box [string "uw_",
                                    p_ident m,
                                    string "_",