From 53ab9ae05a579a19c626e8be0c1e2cf9244bf863 Mon Sep 17 00:00:00 2001 From: gramanas Date: Fri, 28 Jan 2022 13:45:30 +0200 Subject: sha1 sum and others --- src/types.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) (limited to 'src/types.c') diff --git a/src/types.c b/src/types.c index dbc7458..3233323 100644 --- a/src/types.c +++ b/src/types.c @@ -21,6 +21,7 @@ new_recipe() r->filename = NULL; r->path = NULL; r->title = NULL; + r->sha1[0] = '\0'; return r; } @@ -136,6 +137,12 @@ pprint_items(recipe * r) printf("\n"); } +void +listing(recipe * r) +{ + printf("%.*s %d:%d\t%d\t%s\n", 8, (strcmp(r->sha1, "") ? r->sha1 : "neval"), r->in, r->sn, r->rn, r->title); +} + void show(recipe * r) { @@ -158,7 +165,9 @@ tojson(recipe * r) printf("{\"filename\":\"%s\",", r->filename); printf("\"dirname\":\"%s\",", r->path); printf("\"title\":\"%s\",", r->title); - printf("\"n\":\"%d\"", r->n); + printf("\"n\":\"%d\",", r->n); + printf("\"sha1_short\":\"%.*s\",", 8, r->sha1); + printf("\"sha1\":\"%s\"", r->sha1); if (r->rn) { printf(",\"subrecipes\":["); int i = 0; @@ -189,16 +198,51 @@ tojson(recipe * r) void tohtml(recipe * r) { - printf("todo\n"); + printf("
\n"); + printf("\n", r->path, r->filename); + printf("

%s

\n\n", r->title); + if (r->rn) { + printf("\n"); + } + if (r->in) { + printf("\n"); + } + if (r->sn) { + printf("

---


\n"); + printf("\n"); + } + printf("
\n
\n"); } void torcp(recipe * r) { printf("# %s/%s\n\n", r->path, r->filename); + if (r->sha1[0] != '\0') { + printf("# %s\n\n", r->sha1); + } printf("@%s\n\n", r->title); for (int i = 0; i < r->rn; i++) { - printf("!%s/%s\n", r->r[i]->path, r->r[i]->filename); + printf("%s!%s/%s\n", (r->sha1[0] != '\0') ? "# ": "", r->r[i]->path, r->r[i]->filename); } for (int i = 0; i < r->in; i++) printf("%s = %s\n", r->i[i]->name, r->i[i]->qty); @@ -217,6 +261,20 @@ torcp(recipe * r) } } +void +copy_subrecipes(recipe * dst, recipe * src) +{ + if (!dst || !src) return; + for (int i = 0; i < src->rn; i++) { + recipe * r = new_recipe(); + r->title = strdup(src->r[i]->title); + r->path = strdup(src->r[i]->path); + r->filename = strdup(src->r[i]->filename); + r->n = src->r[i]->n; + new_subrecipe(dst, r); + } +} + void copy_metadata(recipe * dst, recipe * src) { -- cgit v1.2.3