Check-in by ben on 2022-12-23 16:59:00 Accept both MMMMM and ----- Meal-Master heading formats. INSERTED DELETED 9 9 mmhtml.awk 9 9 mmrtf.awk 18 18 TOTAL over 2 changed files Index: mmhtml.awk ================================================================== --- mmhtml.awk +++ mmhtml.awk @@ -1,8 +1,8 @@ # Pretty-print Meal-Master recipe to HTML format # Usage: awk -f mmhtml.awk recipe.html -# Only works with single-column MMMMM format +# Only works with single-column Meal-Master format # https://github.com/wedesoft/anymeal/blob/master/anymeal/html.cc function array_size(a) { retval = 0 for (i in a) { @@ -261,14 +261,14 @@ } { gsub(/\r/, "") if (NR == 1) { - if (/^MMMMM-----/) { + if (/^(MMMMM|-----)----- Recipe via Meal-Master/) { in_heading = 1 } else { - print "Error: Not in Meal-Master MMMMM format\n" + print "Error: Not in Meal-Master format\n" exit 0 } } else if (NR == 2) { # ignore second line } else if (in_heading) { @@ -281,11 +281,11 @@ } else if (/^[[:space:]]*$/) { in_heading = 0 in_ingredients = 1 } } else if (in_ingredients) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { in_ingredients = 0 in_gsection = 1 gsection = substr($0, RLENGTH+1) gsub(/-+$/, "", gsection) } else if (/^[[:space:]]*$/) { @@ -302,20 +302,20 @@ amounts[gsection,i] = amount units[gsection,i] = unit ingredients[gsection,i] = ingredient } } else if (after_ingredients) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { after_ingredients = 0 in_gsection = 1 gsection = substr($0, RLENGTH+1) gsub(/-+$/, "", gsection) } else { after_ingredients = 0 in_instructions = 1 } else if (in_gsection) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { in_gsection = 1 gsection = substr($0, RLENGTH+1) gsub(/-+$/, "", gsection) } else if (/^[[:space:]]*$/) { in_gsection = 0 @@ -330,11 +330,11 @@ amounts[gsection,i] = amount units[gsection,i] = unit ingredients[gsection,i] = ingredient } } else if (after_gsection) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { after_gsection = 0 in_gsection = 1 gsection = substr($0, RLENGTH+1) gsub(/-+$/, "", gsection) } else { @@ -341,14 +341,14 @@ after_gsection = 0 in_instructions = 1 } } if (in_instructions) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { tsection = substr($0, RLENGTH+1) gsub(/-+$/, "", tsection) - } else if (/^MMMMM$/) { + } else if (/^(MMMMM|-----)$/) { in_instructions = 0 at_end = 1 } else if (/^[[:space:]]*\* /) { in_instructions = 0 in_list = 1 Index: mmrtf.awk ================================================================== --- mmrtf.awk +++ mmrtf.awk @@ -1,8 +1,8 @@ # Pretty-print Meal-Master recipe to .RTF format # Usage: awk -f mmrtf.awk recipe.rtf -# Only works with single-column MMMMM format +# Only works with single-column Meal-Master format # # RTF hints: # # * https://metacpan.org/dist/RTF-Writer/view/lib/RTF/Cookbook.pod # * https://en.wikipedia.org/wiki/Rich_Text_Format @@ -283,14 +283,14 @@ } { gsub(/\r/, "") if (NR == 1) { - if (/^MMMMM-----/) { + if (/^(MMMMM|-----)----- Recipe via Meal-Master/) { in_heading = 1 } else { - print "Error: Not in Meal-Master MMMMM format\n" + print "Error: Not in Meal-Master format\n" exit 0 } } else if (NR == 2) { # ignore second line } else if (in_heading) { @@ -303,11 +303,11 @@ } else if (/^[[:space:]]*$/) { in_heading = 0 in_ingredients = 1 } } else if (in_ingredients) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { in_ingredients = 0 in_gsection = 1 gsection = substr($0, RLENGTH+1) gsub(/-+$/, "", gsection) } else if (/^[[:space:]]*$/) { @@ -324,21 +324,21 @@ amounts[gsection,i] = amount units[gsection,i] = unit ingredients[gsection,i] = ingredient } } else if (after_ingredients) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { after_ingredients = 0 in_gsection = 1 gsection = substr($0, RLENGTH+1) gsub(/-+$/, "", gsection) } else { after_ingredients = 0 in_instructions = 1 } } else if (in_gsection) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { in_gsection = 1 gsection = substr($0, RLENGTH+1) gsub(/-+$/, "", gsection) } else if (/^[[:space:]]*$/) { in_gsection = 0 @@ -353,11 +353,11 @@ amounts[gsection,i] = amount units[gsection,i] = unit ingredients[gsection,i] = ingredient } } else if (after_gsection) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { after_gsection = 0 in_gsection = 1 gsection = substr($0, RLENGTH+1) gsub(/-+$/, "", gsection) } else { @@ -364,14 +364,14 @@ after_gsection = 0 in_instructions = 1 } } if (in_instructions) { - if (match($0, /^MMMMM-+/)) { + if (match($0, /^(MMMMM|-----)-+/)) { tsection = substr($0, RLENGTH+1) gsub(/-+$/, "", tsection) - } else if (/^MMMMM$/) { + } else if (/^(MMMMM|-----)$/) { in_instructions = 0 at_end = 1 } else if (/^[[:space:]]*\* /) { in_instructions = 0 in_list = 1