From 361bb55f01ba28960a8127b0a16c1e7a7a8de61a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 17 Sep 2021 20:57:05 +0200 Subject: Rewrite mktpl script in C The Perl version didn't handle multiple interpolations on the same line. --- t/front.t | 34 +++++++++++++++++++--------------- t/front.tc | 25 ++++++++++++------------- t/post.t | 1 + t/post.tc | 3 +++ t/user.t | 1 + t/user.tc | 5 +++++ 6 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 t/post.t create mode 100644 t/post.tc create mode 100644 t/user.t create mode 100644 t/user.tc (limited to 't') diff --git a/t/front.t b/t/front.t index 0a372a6..a9badb0 100644 --- a/t/front.t +++ b/t/front.t @@ -1,16 +1,20 @@

<%= site.name %>

-<% printf("Hello world!"); %> -
-Request method: <%= getenv("REQUEST_METHOD") %> -
-<% - char *a, *b, *bv; - a = nextparam(512); - printf("%s (%d)
", a, TRUNCATED(a)); - b = nextparam(512); - printf("%s (%d)
", b, TRUNCATED(b)); - bv = split(b); - printf("'%s' contains '%s'
", b, bv); - printf("Next: %s\n", nextparam(512)); - printf("Next: %s\n", nextparam(512)); -%> \ No newline at end of file +

Thanks for the <%= getenv("REQUEST_METHOD") %> request!

+ + + + + + <% + char *p, *v; + while(p = nextparam(GET, 512)){ + v = split(p); + %> + + + + + <% + } + %> +
KeyValue
<%= p %><%= v %>
\ No newline at end of file diff --git a/t/front.tc b/t/front.tc index 89e665a..3307c21 100644 --- a/t/front.tc +++ b/t/front.tc @@ -1,16 +1,15 @@ printf("

"); printf("%s", site.name ); -printf("

\n"); - printf("Hello world!"); printf("\n
\nRequest method: "); +printf("\n

Thanks for the "); printf("%s", getenv("REQUEST_METHOD") ); -printf("
\n"); - char *a, *b, *bv; - a = nextparam(512); - printf("%s (%d)
", a, TRUNCATED(a)); - b = nextparam(512); - printf("%s (%d)
", b, TRUNCATED(b)); - bv = split(b); - printf("'%s' contains '%s'
", b, bv); - printf("Next: %s\n", nextparam(512)); - printf("Next: %s\n", nextparam(512)); -printf("\n"); +printf(" request!

\n\n \n \n \n \n "); + char *p, *v; + while(p = nextparam(GET, 512)){ + v = split(p); + printf("\n \n \n \n \n "); + } + printf("\n
KeyValue
"); +printf("%s", p ); +printf(""); +printf("%s", v ); +printf("
"); diff --git a/t/post.t b/t/post.t new file mode 100644 index 0000000..a74f29a --- /dev/null +++ b/t/post.t @@ -0,0 +1 @@ +

Post <% printf("%d", id); %>

diff --git a/t/post.tc b/t/post.tc new file mode 100644 index 0000000..7c36950 --- /dev/null +++ b/t/post.tc @@ -0,0 +1,3 @@ +printf("

Post "); +printf("%d", id); +printf("

\n"); diff --git a/t/user.t b/t/user.t new file mode 100644 index 0000000..9a0fd49 --- /dev/null +++ b/t/user.t @@ -0,0 +1 @@ +

User <% printf("%d", id); %>: <%= user->name %>

\ No newline at end of file diff --git a/t/user.tc b/t/user.tc new file mode 100644 index 0000000..3d92e16 --- /dev/null +++ b/t/user.tc @@ -0,0 +1,5 @@ +printf("

User "); +printf("%d", id); +printf(": "); +printf("%s", user->name ); +printf("

"); -- cgit v1.2.3