From 86e10d50ea069694feb2a43fd2bf92aee564f4b1 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Sun, 9 May 2021 22:29:01 +0000 Subject: remove \t; add handle argument '-i, --stdin'; print full html file => works as cgi-script --- ctimeline.c | 81 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/ctimeline.c b/ctimeline.c index 505a683..63d55e7 100644 --- a/ctimeline.c +++ b/ctimeline.c @@ -5,6 +5,8 @@ #include "xstring.h" +#define APP_VERSION "1.0" +#define CONFIG_PATH "/etc/ctimelines" #define COMMENT_CHAR '#' #define INIT_CAPACITY_LIST 8 @@ -54,26 +56,27 @@ void emit_timeline_html() int i; struct branch *ptr; - printf("\t\n"); } struct branch *add_branch(const char *name) @@ -164,61 +167,73 @@ int read_config_line(FILE *f, string *name, string *value) return 0; } -int parse_config_file(const char *filename) +void parse_config_file(FILE *f) { string *name = string_alloc(NULL); string *value = string_alloc(NULL); - FILE *f; - - f = fopen(filename, "r"); - if(!f) - return 1; - + while(read_config_line(f, name, value) == 0) { // printf("name: %s; value: %s\n", name->s, value->s); handle_config_context(name->s, value->s); string_reset(name); string_reset(value); } - - fclose(f); + string_release(name); string_release(value); - return 0; } void usage() { - printf("Usage: ctimeline [-h, --help] config_path\n" + printf("Usage: ctimeline [-h, --help | -i, --stdin]\n" "Copyright (C) 2021 Aleksandr D. Goncharov (Joursoir)\n" + "Version: %s\n" "License: GNU GPL version 3 + X11 License\n" "This is free software: you are free to change and redistribute it.\n" - "This program comes with ABSOLUTELY NO WARRANTY.\n"); + "This program comes with ABSOLUTELY NO WARRANTY.\n", APP_VERSION); } int main(int argc, char **argv) { - int result; - const char *config; + FILE *config; if(argc < 2) { - usage(); - return 1; + config = fopen(CONFIG_PATH, "r"); + if(!config) { + perror(CONFIG_PATH); + return 1; + } } - if(strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) { + else if(strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) { usage(); return 0; } - config = argv[1]; - - result = parse_config_file(config); - if(result) { - perror(config); + else if(strcmp(argv[1], "--stdin") == 0 || strcmp(argv[1], "-i") == 0) + config = stdin; + else { + usage(); return 1; } + parse_config_file(config); + fclose(config); + sort_branches_by_age(); + printf("Content-type: text/html\n" + "\n" + "\n" + "\n" + " ctimeline\n" + " \n" + "\n" + "" + "\n" + "
\n"); emit_timeline_html(); + printf("
\n" + "\n" + "\n"); + free(branches.list); return 0; } -- cgit v1.2.3-18-g5258