From bdc12a5eb8e122eacf272f9f53c8912f42f3f571 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Sat, 15 May 2021 07:56:30 +0000 Subject: move code that generate html to sub-module 'ui-common' * Generate new html-code --- ctimeline.c | 30 ---------------------- ui-common.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ui-common.h | 10 ++++++++ 3 files changed, 93 insertions(+), 30 deletions(-) create mode 100644 ui-common.c create mode 100644 ui-common.h diff --git a/ctimeline.c b/ctimeline.c index 6259433..c6f99d5 100644 --- a/ctimeline.c +++ b/ctimeline.c @@ -53,35 +53,6 @@ void sort_branches_by_age() } } -void emit_timeline_html() -{ - int i; - struct branch *ptr; - - printf("\n"); -} - - struct ctimeline_branch *add_branch(const char *name) { struct ctimeline_branch *br; @@ -226,7 +197,6 @@ int main(int argc, char **argv) "" "\n" "
\n"); - emit_timeline_html(); printf("
\n" "\n" "\n"); diff --git a/ui-common.c b/ui-common.c new file mode 100644 index 0000000..66ad5f7 --- /dev/null +++ b/ui-common.c @@ -0,0 +1,83 @@ +#include + +#include "ui-common.h" +#include "ctimeline.h" + +void print_http_headers() +{ + printf("Content-type: text/html\n"); + printf("\n"); +} + +void print_document_start() +{ + printf("\n"); + printf("\n"); + printf("%s\n", ctx.head_title); + printf("\n", ctx.css); + printf("\n"); + printf("\n"); +} + +void print_document_header() +{ + printf("
\n"); + printf("
\n"); + printf("\n"); + + printf("\n"); + printf( + "\n", ctx.header_title); + printf("\n"); + + printf("\n"); + printf( + "\n", ctx.header_desc); + printf("\n"); + + printf("

%s

%s
\n"); + printf("
\n"); +} + +void print_timelines() +{ + if(ctx.branches.count <= 0) + return; + + int i; + struct ctimeline_branch *br; + + printf("
    \n"); + + for(i = 0; i < ctx.branches.count; i++) { + br = &ctx.branches.list[i]; + printf( + "
  • \n" + "
    \n" + "
    \n" + " %s\n" + " %d-%d\n" + "
    \n" + "
    %s
    \n" + "
    \n" + "
  • \n", + (i % 2) ? "left" : "right", br->name->s, + br->age_from, br->age_to, br->desc->s); + string_release(br->name); + string_release(br->desc); + } + + printf("
\n"); +} + +void print_document_end() +{ + printf("\n"); + printf("
\n"); // + printf("\n"); + printf("\n"); +} diff --git a/ui-common.h b/ui-common.h new file mode 100644 index 0000000..efa509e --- /dev/null +++ b/ui-common.h @@ -0,0 +1,10 @@ +#ifndef CTIMELINE_UI_COMMON_H +#define CTIMELINE_UI_COMMON_H + +void print_http_headers(); +void print_document_start(); +void print_document_header(); +void print_timelines(); +void print_document_end(); + +#endif /* CTIMELINE_UI_COMMON_H */ -- cgit v1.2.3-18-g5258