<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>hash.c</filename>
    </added>
    <added>
      <filename>hash.h</filename>
    </added>
    <added>
      <filename>test.c</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,20 +1,25 @@
 .SUFFIXES : .c .o 
 CFLAGS = -g -O0 -Wall -I./
 CC = gcc
-OBJS = main.o clog.o db.o
+OBJS = main.o clog.o hash.o db.o
+TEST_OBJS = test.o hash.o
 SRCS = $(OBJS:.o=.c)
 
 clog: $(OBJS)
 	$(CC) -o clog.cgi $(OBJS) -lsqlite3 -lfcgi
 
+test: $(TEST_OBJS)
+	$(CC) -o test $(TEST_OBJS) -lsqlite3 -lfcgi
+
 dep:
 	gccmakedep $(SRCS)
 
 clean:
 	rm -f $(OBJS) clog core *~
 
+test.o: test.c
 main.o: main.c clog.h
 clog.o: clog.c db.h
+hash.o: hash.c
 db.o: db.c
 
-</diff>
      <filename>Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,7 @@
 #include &lt;time.h&gt;
 #include &lt;stdarg.h&gt;
 #include &lt;ctype.h&gt;
+#include &quot;hash.h&quot;
 #include &quot;clog.h&quot;
 
 int db_modify_table(const char *q) {
@@ -142,11 +143,18 @@ int generate_entries(int window, int id, const char *template_file) {
         return rc;
     }
 
-    entry_t entries[r];
+    hast_table entries[r];
 
     int index;
     for (row = 1; row &lt;= r; row++) {
         index = row - 1;
+
+        hash_table_init(entries[index]);
+        for (col = 0; col &lt; c; col++) {
+            hash_add(entries[index], results[col], results[row * c + col], NULL);
+        }
+/* 
+
         entries[index].id = strtol(results[CLOG_ID], NULL, 10);
         entries[index].title   = results[CLOG_TITLE];
         entries[index].content = results[CLOG_CONTENT];
@@ -156,19 +164,25 @@ int generate_entries(int window, int id, const char *template_file) {
         entries[index].comment_count = strtol(results[CLOG_COMMENT_COUNT], NULL, 10);
 
         if (results[CLOG_C_TIME] == NULL) {
+            free(entries[index].c_time);
             entries[index].c_time = NULL;
         } else {
             rfc_date(entries[index].c_time, strtol(results[CLOG_C_TIME], NULL, 10));
         }
 
         if (results[CLOG_U_TIME] == NULL) {
+            free(entries[index].u_time);
             entries[index].u_time = NULL;
         } else {
             rfc_date(entries[index].u_time, strtol(results[CLOG_U_TIME], NULL, 10));
         }
+*/
     }
 
+    print_template(template_file, entries);
 
+
+/*
     fc = fopen(template_file, &quot;r&quot;);
     if (fc == NULL) {
         error_log(&quot;Failed opening template file: %s\n&quot;, template_file);
@@ -186,7 +200,7 @@ int generate_entries(int window, int id, const char *template_file) {
         }
 
         if (strcmp(buffer, CLOG_LOOP_END) == 0) {
-            /* now that we ended the loop parse the loop_str for each entries */
+            // now that we ended the loop parse the loop_str for each entries 
             //printf(&quot;%s&quot;, loop_str);
             for (row = 0; row &lt; r; row++) {
                 output_entry(loop_str, entries[row]);
@@ -197,11 +211,6 @@ int generate_entries(int window, int id, const char *template_file) {
 
         switch (ts) {
             case CLOG_INSIDE_LOOP:
-                /*
-                if (sizeof(loop_str) &lt; (sizeof(char) * (strlen(loop_str) + strlen(buffer) + 1))) {
-                    loop_str = (char *)realloc(loop_str, sizeof(char) * 2 * (sizeof(loop_str) + strlen(buffer) + 1));
-                }
-                */
                 loop_str = (char *)realloc(loop_str, sizeof(char) * (strlen(loop_str) + strlen(buffer) + 1));
                 strcat(loop_str, buffer);
                 break;
@@ -214,6 +223,7 @@ int generate_entries(int window, int id, const char *template_file) {
     free(loop_str);
 
     free_entries(entries, r);
+*/
 
     sqlite3_free_table(results);
 
@@ -263,6 +273,97 @@ void output_entry(char *tmplate, const entry_t e) {
 }
 
 int generate_comments(int entry_id, const char *template_file) {
+    sqlite3 *db;
+
+    char *zErrMsg = 0;
+    int rc;
+    char *q;
+    char **results = 0;
+    int r, c, row;
+    int ts;
+    FILE *fc;
+    char buffer[FILE_BUFFER_SIZE];
+
+    q = (char *)malloc(sizeof(char) * 250);
+
+    sprintf(q, &quot;SELECT &quot;
+               &quot;comment, c_time &quot;
+               &quot;FROM comments &quot;
+               &quot;WHERE entry_id = %d &quot; 
+               &quot;ORDER BY c_time ASC &quot;,
+               entry_id);
+
+    if((rc = sqlite3_open(DATABASE, &amp;db)))
+        return rc;
+    
+    rc = sqlite3_get_table(db, q, &amp;results, &amp;r, &amp;c, &amp;zErrMsg);
+    if (rc != SQLITE_OK) {
+        error_log(&quot;SQL error: %s\n&quot;, zErrMsg);
+        sqlite3_free(zErrMsg);
+        return rc;
+    }
+
+    char *comments[r];
+    char *c_times[r];
+    for (row = 1; row &lt;= r; row++) {
+        comments[row-1] = results[row * c];
+        c_times[row-1] = (char *)malloc(sizeof(char) * 32);
+        if (results[row*c+1] == NULL) {
+            free(c_times[row-1]);
+            c_times[row-1] = NULL;
+        } else {
+            rfc_date(c_times[row-1], strtol(results[row*c+1], NULL, 10));
+        }
+        printf(&quot;%s - %s\n&quot;, comments[row-1], c_times[row-1]);
+    }
+
+
+    fc = fopen(template_file, &quot;r&quot;);
+    if (fc == NULL) {
+        error_log(&quot;Failed opening template file: %s\n&quot;, template_file);
+        return errno;
+    }
+
+    /*
+    ts = CLOG_BEFORE_LOOP;
+    loop_str = (char *)malloc(sizeof(char));
+    *(loop_str) = 0;
+
+    while (fgets(buffer, sizeof(buffer), fc)) {
+        if (strcmp(buffer, CLOG_LOOP_BEGIN) == 0) {
+            ts = CLOG_INSIDE_LOOP;
+            continue;
+        }
+
+        if (strcmp(buffer, CLOG_LOOP_END) == 0) {
+            // now that we ended the loop parse the loop_str for each entries 
+            //printf(&quot;%s&quot;, loop_str);
+            for (row = 0; row &lt; r; row++) {
+
+            }
+            ts = CLOG_AFTER_LOOP;
+            continue;
+        }
+
+        switch (ts) {
+            case CLOG_INSIDE_LOOP:
+                loop_str = (char *)realloc(loop_str, sizeof(char) * (strlen(loop_str) + strlen(buffer) + 1));
+                strcat(loop_str, buffer);
+                break;
+            default:
+                printf(&quot;%s&quot;, buffer);
+                break;
+        }
+    }
+    */
+
+    
+    for(row = 0; row &lt; r; row++) {
+        free(comments[row]);
+        free(c_times[row]);
+    }
+    sqlite3_free_table(results);
+    sqlite3_close(db);
     return 0;
 }
 
@@ -300,6 +401,15 @@ void htmlize_print(char *str) {
     }
 }
 
+
+void print_template(char *filename, hash_table tables[], int rows) {
+    int i;
+    for (int i = 0; i &lt; rows; i++) {
+        hash_print_all(tables[i]);
+    }
+}
+
+/* TODO: write the error to the file */
 int error_log(const char *fmt, ...) {
     int ret;
     va_list ap;</diff>
      <filename>clog.c</filename>
    </modified>
    <modified>
      <diff>@@ -21,6 +21,3 @@ CREATE TABLE IF NOT EXISTS comments
 CREATE TABLE IF NOT EXISTS entry_tag
    (entry_id INTEGER REFERENCES entries (id),
 	tag_id INTEGER REFERENCES tags (id));
-
-
-  </diff>
      <filename>init_db.sql</filename>
    </modified>
    <modified>
      <diff>@@ -45,20 +45,21 @@ int main() {
             break;
         }
 
-        /* generate comments */
         if (strcmp(comments, &quot;true&quot;) == 0) {
             strcat(type, &quot;_comment.ct&quot;);
             generate_comments(strtol(entry, NULL, 10), type);
-            break;
+        } else {
+            /* defaults to creating the main blog */
+            strcat(type, &quot;.ct&quot;);
+            if(strcmp(entry,&quot;0&quot;) == 0) {
+                generate_entries(10, 1, type);
+            } else { 
+                generate_entries(1, strtol(entry, NULL, 10), type);
+            }
         }
 
 
-        strcat(type, &quot;.ct&quot;);
-        if(strcmp(entry,&quot;0&quot;) == 0) {
-            generate_entries(10, 1, type);
-        } else { 
-            generate_entries(1, strtol(entry, NULL, 10), type);
-        }
+        generate_comments(5, NULL);
     }
     return 0;
 }</diff>
      <filename>main.c</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>abc05efe636f2bb4c4decd2c429a50c789142cba</id>
    </parent>
  </parents>
  <author>
    <name>Timothy Kim</name>
    <email>highwind@terra.local</email>
  </author>
  <url>http://github.com/highwind/clog/commit/105db3530b17753bee62901d55a78286ab221be6</url>
  <id>105db3530b17753bee62901d55a78286ab221be6</id>
  <committed-date>2009-05-20T15:59:36-07:00</committed-date>
  <authored-date>2009-05-20T15:59:36-07:00</authored-date>
  <message>hash table done, working on templating</message>
  <tree>0087ba0e95ebca22efb6e4c88d03ef598d672cf2</tree>
  <committer>
    <name>Timothy Kim</name>
    <email>highwind@terra.local</email>
  </committer>
</commit>
