repo_index.c (1348B)
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 free(index); 25 } 26 27 void gopher_repoindex_begin(GopherRepoIndex* index) { 28 assert(index != NULL); 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 void gopher_repoindex_add_repo(GopherRepoIndex* index, const GitRepo* repo) { 37 assert(index != NULL); 38 assert(repo != NULL); 39 FILE* out = index->out; 40 fprintf(out, "[1|"); 41 print_gopher_link_padded(out, repo->short_name, 20, ' '); 42 fprintf(out, " "); 43 print_gopher_link_padded(out, repo->description, 39, ' '); 44 fprintf(out, " "); 45 if (repo->last_commit_time > 0) { 46 print_time_short(out, repo->last_commit_time); 47 } 48 fprintf(out, "|"); 49 print_gopher_link(out, repo->short_name); 50 fprintf(out, "/log.gph|server|port]\n"); 51 } 52 53 void gopher_repoindex_end(GopherRepoIndex* index) { 54 assert(index != NULL); 55 (void)index; 56 }