summaryrefslogtreecommitdiffstats
path: root/src/types.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2022-01-28 13:45:30 +0200
committergramanas <anastasis.gramm2@gmail.com>2022-01-28 13:45:30 +0200
commit53ab9ae05a579a19c626e8be0c1e2cf9244bf863 (patch)
treee6ec5ce8920124e8f4dd59d2ca20f45f30b4640e /src/types.c
parent98849f6afb8e216000f6c642d9c9ffa26a58bd4c (diff)
downloadfoodtools-53ab9ae05a579a19c626e8be0c1e2cf9244bf863.tar.gz
foodtools-53ab9ae05a579a19c626e8be0c1e2cf9244bf863.tar.bz2
foodtools-53ab9ae05a579a19c626e8be0c1e2cf9244bf863.zip
sha1 sum and others
Diffstat (limited to 'src/types.c')
-rw-r--r--src/types.c64
1 files changed, 61 insertions, 3 deletions
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;
}
@@ -137,6 +138,12 @@ pprint_items(recipe * r)
}
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)
{
printf("Filename\t%s\n", r->filename);
@@ -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("<div class=\"recipe\">\n");
+ printf("<!-- %s/%s -->\n", r->path, r->filename);
+ printf("<h1>%s</h1>\n\n", r->title);
+ if (r->rn) {
+ printf("<ul class=\"list items subrecipes\">\n");
+ for (int i = 0; i < r->rn; i++) {
+ printf("<li>!%s/%s</li>\n", r->r[i]->path, r->r[i]->filename);
+ }
+ printf("</ul>\n");
+ }
+ if (r->in) {
+ printf("<ul class=\"list items\">\n");
+ for (int i = 0; i < r->in; i++) {
+ printf("<li>%s = %s</li>\n", r->i[i]->name, r->i[i]->qty);
+ }
+ printf("</ul>\n");
+ }
+ if (r->sn) {
+ printf("<br><p>---</p><br>\n");
+ printf("<ul class=\"list steps\">\n");
+ for (int i = 0; i < r->sn; i++) {
+ char c;
+ if (r->s[i]->type == PREP)
+ c = '-';
+ else if (r->s[i]->type == COOK)
+ c = '>';
+ else
+ c = '+';
+ printf("<li>%c %s</li>\n", c, r->s[i]->inst);
+ }
+ printf("</ul>\n");
+ }
+ printf("<hr>\n</div>\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);
@@ -218,6 +262,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)
{
if (!dst || !src) return;