gitout

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

repo_index.c (1462B)


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