summaryrefslogtreecommitdiffstats
path: root/types.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2021-11-06 13:01:47 +0200
committergramanas <anastasis.gramm2@gmail.com>2021-11-06 13:01:47 +0200
commit66a86d1b20a1e97b2d008e73db7557887fc44edf (patch)
treed778fa893496fc7d4c3609dc8d3d8f667182217d /types.c
parent9deed51aa2df7ca5979963f7452a6439ad2d3767 (diff)
downloadfoodtools-66a86d1b20a1e97b2d008e73db7557887fc44edf.tar.gz
foodtools-66a86d1b20a1e97b2d008e73db7557887fc44edf.tar.bz2
foodtools-66a86d1b20a1e97b2d008e73db7557887fc44edf.zip
Progress
Diffstat (limited to 'types.c')
-rw-r--r--types.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/types.c b/types.c
index 4eb3a1b..091ff8d 100644
--- a/types.c
+++ b/types.c
@@ -11,10 +11,13 @@ new_recipe()
if (!r)
die("Couldn't allocate memory for recipe");
+ r->n = 1;
r->i = NULL;
r->in = 0;
r->s = NULL;
r->sn = 0;
+ r->r = NULL;
+ r->rn = 0;
r->filename = NULL;
r->path = NULL;
r->title = NULL;
@@ -22,6 +25,17 @@ new_recipe()
}
void
+new_subrecipe(recipe * r, recipe * src)
+{
+ r->r = (recipe **)realloc(r->r, (r->rn + 1) * sizeof(recipe *));
+ if (!r->r)
+ die("Couldn't allocate memory for subricepie");
+
+ r->r[r->rn] = src;
+ r->rn++;
+}
+
+void
new_item(recipe * r)
{
r->i = (item **)realloc(r->i, (r->in + 1) * sizeof(item *));
@@ -97,6 +111,12 @@ free_recipe(recipe * r)
free(r->s);
}
+ if (r->r) {
+ for (int i = 0; i < r->rn; i++)
+ free_recipe(r->r[i]);
+ free(r->r);
+ }
+
if (r->filename)
free(r->filename);
if (r->path)
@@ -128,7 +148,18 @@ tojson(recipe * r)
{
printf("{\"filename\":\"%s\",", r->filename);
printf("\"dirname\":\"%s\",", r->path);
- printf("\"title\":\"%s\"", r->title);
+ printf("\"title\":\"%s\",", r->title);
+ printf("\"n\":\"%d\"", r->n);
+ if (r->rn) {
+ printf(",\"subrecipes\":[");
+ int i = 0;
+ for (; i < r->rn - 1; i++) {
+ tojson(r->r[i]);
+ printf(",");
+ }
+ tojson(r->r[i]);
+ printf("]");
+ }
if (r->in) {
printf(",\"ingredients\":{");
int i = 0;
@@ -143,7 +174,7 @@ tojson(recipe * r)
printf("\"%s\",", r->s[i]->inst);
printf("\"%s\"]", r->s[i]->inst);
}
- printf("}\n");
+ printf("}");
}
void
@@ -157,12 +188,23 @@ torcp(recipe * r)
{
printf("# %s/%s\n\n", r->path, r->filename);
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);
+ }
for (int i = 0; i < r->in; i++)
printf("%s = %s\n", r->i[i]->name, r->i[i]->qty);
if (r->sn) {
printf("\n---\n\n");
- for (int i = 0; i < r->sn; i++)
- printf("%s %s\n", r->s[i]->type == PREP ? "-" : ">", r->s[i]->inst);
+ 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("%c %s\n", c, r->s[i]->inst);
+ }
}
}