gout

A static git page generator
git clone https://git.bracken.jp/gout.git
Log | Files | Refs | README | LICENSE

repo_index.c (1369B)


      1 #include "writer/gopher/repo_index.h"
      2 
      3 #include <assert.h>
      4 #include <stdlib.h>
      5 
      6 #include "format.h"
      7 #include "utils.h"
      8 
      9 struct GopherRepoIndex {
     10   FILE* out;
     11 };
     12 
     13 GopherRepoIndex* gopher_repoindex_create(FILE* out) {
     14   assert(out != NULL);
     15   GopherRepoIndex* index = ecalloc(1, sizeof(GopherRepoIndex));
     16   index->out = out;
     17   return index;
     18 }
     19 
     20 void gopher_repoindex_free(GopherRepoIndex* index) {
     21   if (!index) {
     22     return;
     23   }
     24   index->out = NULL;
     25   free(index);
     26 }
     27 
     28 void gopher_repoindex_begin(GopherRepoIndex* index) {
     29   assert(index != NULL);
     30   FILE* out = index->out;
     31   fprintf(out, "Repositories\n\n");
     32   fprintf(out, "%-20.20s  ", "Name");
     33   fprintf(out, "%-39.39s  ", "Description");
     34   fprintf(out, "%s\n", "Last commit");
     35 }
     36 
     37 void gopher_repoindex_add_repo(GopherRepoIndex* index, const GitRepo* repo) {
     38   assert(index != NULL);
     39   assert(repo != NULL);
     40   FILE* out = index->out;
     41   fprintf(out, "[1|");
     42   print_gopher_link_padded(out, repo->short_name, 20, ' ');
     43   fprintf(out, "  ");
     44   print_gopher_link_padded(out, repo->description, 39, ' ');
     45   fprintf(out, "  ");
     46   if (repo->last_commit_time > 0) {
     47     print_time_short(out, repo->last_commit_time);
     48   }
     49   fprintf(out, "|");
     50   print_gopher_link(out, repo->short_name);
     51   fprintf(out, "/log.gph|server|port]\n");
     52 }
     53 
     54 void gopher_repoindex_end(GopherRepoIndex* index) {
     55   assert(index != NULL);
     56   (void)index;
     57 }