added a global 'error_log' for debugging
authorChristian Thaeter <ct@pipapo.org>
Wed, 26 Dec 2007 20:31:55 +0000 (21:31 +0100)
committerChristian Thaeter <ct@pipapo.org>
Wed, 26 Dec 2007 20:31:55 +0000 (21:31 +0100)
src/ctgit.c
src/ctgit.h
src/options.c

index c838debb17c61185d834df5fdb2a49448e4350a3..f7cf4725f49e171522419425c6f456edff910c42 100644 (file)
 #include <string.h>
 #include <time.h>
 
+Html error_log;
 
 int
 main (int argc, char**argv)
 {
+  Html page;
   struct ctgit_query query;
 
+  error_log = html_list();
+
   clock_t timestat = clock();
 
   ctgit_query_init (&query);
@@ -52,18 +56,11 @@ main (int argc, char**argv)
   setenv ("CTGIT_CONFIG", CTGIT_CONFIG, 0);
 
   if (ctgit_commandline_dispatch (argc, argv, &query))
-    {
-      fprintf (stderr, "Commandline parsing error\n");
-      return 10;
-    }
+    goto error;
 
   // read config
   if (ctgit_configfile_dispatch (getenv("CTGIT_CONFIG"), &query))
-    {
-      fprintf (stderr, "Configfile parsing error\n");
-      return 10;
-    }
-
+    goto error;
 
 
   // parse request/query What to show?
@@ -78,19 +75,84 @@ main (int argc, char**argv)
   
   // generate page
   
-  Html page = ctgit_action_dispatch (&query);
-
-
+  //Html page = ctgit_action_dispatch (&query);
+
+  page = html(
+              html_httpheader(
+                              html_httpfield(
+                                             "Content-type",
+                                             "text/html",
+                                             html_attr("charset", "UTF-8")
+                                             )//,
+                              //html_httpfield("Last-Modified", cgit_page.modified),
+                              //html_httpfield("Expires", cgit_page.expires)
+                              ),
+              html_document(
+                            "-//W3C//DTD XHTML 1.0 Transitional//EN",
+                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
+                            html_content(
+                                         /*head*/
+                                         html(
+                                              html(html_tag("title"), "ctgit"),
+                                              html_nl(),
+                                              html_meta("generator", "ctgit")//,
+                                              //html_link_rel("stylesheet", "text/css", cgit_page.stylesheet)
+                                              ),
+                                         /*body*/
+                                         html (
+                                               html_tag("div"),
+                                               ctgit_action_dispatch (&query)
+                                               ),
+                                         html_attr("xmlns", "http://www.w3.org/1999/xhtml"),
+                                         html_attr("xml:lang", "en"),
+                                         html_attr("lang", "en")
+                                         )
+                            )
+              );
 
   html_fprint (stdout, page);
-  printf ("\n");
 
   timestat = clock() - timestat;
   fprintf (stderr, "processing took %g secs\n", timestat/(float)CLOCKS_PER_SEC);
 
   html_free (page);
+  html_free (error_log);
 
   ctgit_query_destroy (&query);
 
   return 0;
+
+ error:
+  page = html(
+              html_httpheader(
+                              html_httpfield(
+                                             "Content-type",
+                                             "text/html",
+                                             html_attr("charset", "UTF-8")
+                                             )                              ),
+              html_document(
+                            "-//W3C//DTD XHTML 1.0 Transitional//EN",
+                            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
+                            html_content(
+                                         /*head*/
+                                         html(
+                                              html(html_tag("title"), "ERROR: ctgit"),
+                                              html_nl(),
+                                              html_meta("generator", "ctgit")
+                                              ),
+                                         /*body*/
+                                         html(
+                                              html_tag("div"),
+                                              error_log
+                                              ),
+                                         html_attr("xmlns", "http://www.w3.org/1999/xhtml"),
+                                         html_attr("xml:lang", "en"),
+                                         html_attr("lang", "en")
+                                         )
+                            )
+              );
+
+  html_fprint (stdout, page);
+  html_free (page);
+  return 10;
 }
index 1250e543815ba4fba4c3ffecfbe9a9ecc9840463..5287f7852d339e4db00462dba62f448881c975f3 100644 (file)
@@ -25,6 +25,9 @@
 
 #include "llist.h"
 
+extern Html error_log;
+
+
 struct ctgit_repo_info
 {
   llist node;
index a54bbba17168914beed322ae16857f3d0e5627b3..06574928098e4583401364b6cbca18cd63c85aa2 100644 (file)
@@ -80,7 +80,14 @@ ctgit_commandline_dispatch (int argc, char**argv, struct ctgit_query* query)
           if (!strncmp (j->name, argv[i], strlen (j->name)))
             {
               if (j->cb (query, argv[i+1]))
-                return -1;
+                {
+                  html_list_append (error_log,
+                                    html_fmt (
+                                              "Commandline parsing error '%s' '%s'\n",
+                                              argv[i], argv[i+1])
+                                    );
+                  return -1;
+                }
               break;
             }
         }
@@ -104,7 +111,13 @@ ctgit_configfile_dispatch (const char* file, struct ctgit_query* query)
 
   FILE* f = fopen (file, "r");
   if (!f)
-    return -1;
+    {
+      html_list_append (error_log,
+                        html_fmt (
+                                  "Configfile opening error '%s'\n", file)
+                        );
+      return -1;
+    }
 
   char buf[1024];
 
@@ -133,6 +146,11 @@ ctgit_configfile_dispatch (const char* file, struct ctgit_query* query)
               if (j->cb (query, m+1))
                 {
                   fclose (f);
+                  html_list_append (error_log,
+                                    html_fmt (
+                                              "Configfile parsing error '%s' '%s'\n",
+                                              buf, m+1)
+                                    );
                   return -1;
                 }
               break;