@REM=(" c:\bin\perl.exe c:\bin\makemstr.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 @goto end ") if 0; # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Alan Jackson; the # contents of this file may not be disclosed to third parties, copied or # duplicated in any form, in whole or in part, without the prior written # permission of Alan Jackson. # # Permission is hereby granted solely to the licencee for use of this # source code in its unaltered state. This source code may not be # modified by licencee except under direction of Alan Jackson. Neither # may this source code be given under any circumstances to non-licensees # in any form, including source or binary. Modification of this source # constitutes breach of contract, which voids any potential pending # support responsibilities by Alan Jackson. Divulging the exact or # paraphrased contents of this source code to unlicensed parties either # directly or indirectly constitutes violation of federal and # international copyright and trade secret laws, and will be duly # prosecuted to the fullest extent permitted under law. # This code is provided for personal use only. Commercial use requires # a different license than provided here. # # This software is provided by Alan Jackson ``as is'' and any express or # implied warranties, including, but not limited to, the implied # warranties of merchantability and fitness for a particular purpose are # disclaimed. In no event shall the regents or contributors be liable for # any direct, indirect, incidental, special, exemplary, or consequential # damages (including, but not limited to, procurement of substitute goods # or services; loss of use, data, or profits; or business interruption) # however caused and on any theory of liability, whether in contract, # strict liability, or tort (including negligence or otherwise) arising in # any way out of the use of this software, even if advised of the # possibility of such damage. # Last updated 7/30/95 - version 1.3 # Last updated 8/20/95 - version 1.3.1 # Last updated 8/22/95 - version 1.3.2 # Last updated 8/26/95 - version 1.3.3 # Last updated 2/26/96 - version 1.3.4 %units = ( "bag","bag", "bunch","bunch", "cn","can", "can","can", "tin","can", "carton","carton", "cm","centimeter", "clove","clove", "centimeter","centimeter", "c","cup", "cp","cup", "handful","cup", "cup","cup", "dash","dash", "dashe","dash", "dl","deciliter", "deciliter","deciliter", "dz","dozen", "dozen","dozen", "dp","drop", "dr","drop", "drp","drop", "drop","drop", "ea","each", "each","each", "ear","ear", "env","envelope", "envelope","envelope", "gal","gallon", "gallon","gallon", "g","gram", "gr","gram", "gram","gram", "head","head", "\"","inch", "jar","jar", "jigger","jigger", "kg","kilogram", "kilogram","kilogram", "lg","large", "lge","large", "large","large", "md","medium", "med","medium", "medium-size","medium", "medium","medium", "ml","milliliter", "milliliter","milliliter", "mm","millimeter", "millimeter","millimeter", "oz","ounce", "ounce","ounce", "floz","ounce", "pk","package", "pkg","package", "package","package", "pkt","packet", "packet","packet", "piece","piece", "pn","pinch", "pinch","pinch", "pt","pint", "pint","pint", "lb","pound", "pound","pound", "qt","quart", "quart","quart", "scoop","scoop", "serving","serving", "shot","shot", "sl","slice", "strip","slice", "slice","slice", "sm","small", "small","small", "sprig","sprig", "sq","square", "sqr","square", "square","square", "rib","stalk", "stalk","stalk", "stick","stick", "tb","tablespoon", "tbl","tablespoon", "tblsp","tablespoon", "tbsp","tablespoon", "tab","tablespoon", "tablespoon","tablespoon", "t","teaspoon", "tsp","teaspoon", "tea","teaspoon", "teas","teaspoon", "teasp","teaspoon", "teaspoon","teaspoon", "whole","whole" ); @adjectives = ("and","or","finely","coarsely","trimmed","seeded","scrubbed", "mashed","diced","sliced","grated","unpeeled","peeled","heaping", "chopped","freshly","ground","crushed","toasted","melted","very", "strained","blanched","sweetened","flaked","squeezed","creamed", "slightly","sifted","well-beaten","beaten","shelled", "crisp", "crumbled","snipped","shredded","unbaked","shaved", "lukewarm","drained","undrained","minced","cubed","poached", "scalded","boiling","cooked","dry","dried","fresh","warm"); foreach $adj (@adjectives){ $adjectives{$adj} = 1; } if (!@ARGV) { die "\n$0: Usage: $0 [-u -a ] [..]\n"; } if ("-u" eq $ARGV[0]) { print STDOUT "\n------- Units Database for MAKEMSTR -------\n\n"; foreach $a (sort keys(%units)) { print "$units{$a} \t$a\n"; } exit; } if ("-a" eq $ARGV[0]) { print STDOUT "\n------- Adjective Database for MAKEMSTR -------\n\n"; foreach $a (sort @adjectives) { print "$a\n"; } exit; } foreach $file (@ARGV) { if (!-e $file) { print STDERR "File $file not found\n"; } else { ($fname, $type) = ($file =~ /^([^.]+)\.?(.*)$/); if ($type eq 'mxp') { print STDERR "Cannot use MasterCook export files as input.\n"; print STDERR "File $file not used\n"; } else { push(@INFILES, $file); push(@INNAMES, $fname); } } } print STDERR "@INFILES\n"; foreach $file (@INFILES) { $fname = shift @INNAMES; open (FILE,"<$file") || die "Can't open $file $!\n"; print STDOUT "\nReading input file: $file\n"; open (OUTPUT,">$fname.mxp") || die "Can't open output file $fname.mxp\n"; print STDOUT "\nWriting output file: $fname.mxp\n"; select(STDOUT); &initialize; $skip = 1; while (){ if (/^\s*#name:/i) { if(!$skip) {$do_output=1;} $skip = 0; } if (!$skip && /^\s*-+\s*end\s*-+/i ) {$do_output = 1;$skip=1;} if ($do_output) { &output; } if (!$skip && eof(FILE)) { $do_output = 1;} next if $skip; chop; s/_/ /g; if (/^\s*#name:\s*(.*)$/i) { $name = $1; if ($names{$name}) { $names{$name}++; $name .= "-" . $names{$name}; } $names{$name}++; print STDOUT " Processing recipe : $name\n"; next; } if ($block eq 'header') { if (/^\s*From:?\s*(.*)$/i) { $source = $1; next; } if (/^\s*Source:?\s*(.*)$/i) { $source = $1; next; } if (/^\s*Recipe By\s*:?\s*(.*)$/i) { $source = $1; next; } if (/^\s*category:?\s*(.*)$/i) { @category = split(/\s*,\s*/,$1); next; } if (/^\s*Categories\s*:?\s*(.*)$/i) { @category = split(/\s*,\s*/,$1); next; } if (/^\s*Servings?:?\s*(\d+)/i) { $serves = $1; next; } if (/^\s*Serves?:?\s*(\d+)/i) { $serves = $1; next; } if (/^\s*Serving Size\s*:?\s*(\d+)/i) { $serves = $1; next; } if (/^\s*Yields?:?\s*(\d+)/i) { $serves = $1; next; } } /^\s*per / && (next); /^MMMMM/ && (next); /^\s*Ingredients:?/i && (next); /^\s*Instructions:?/i && (next); /^\s*[*-=+>= 1) { $val = shift @arr; if ($val eq "level") {$val = shift @arr;} if ($val eq "heaping") {$val = shift @arr;push (@arr,"heaping");} if ($val =~ /^\(/ ) {push (@arr, $val); $val = shift @arr;} if ($val =~ /\)$/ ) {push (@arr, $val); $val = shift @arr;} unshift (@arr,$val); $val =~ s/\.//g; $val =~ s/^T$/tb/; $val =~ tr/A-Z/a-z/; $val =~ s/^ts$/tsp/; $val =~ s/^ds$/dash/; $val =~ s/s$//; if (defined($units{$val})) { $units[$i] = $units{$val}; shift @arr; } } @ing='';@prep=''; $rest = join(' ',@arr); $rest =~ s/^;//; $rest =~ s/([^\\])([;,]| - )/\1 -- /; $rest =~ s/\\(.)/\1/; $rest =~ s/\s*$//; if ($rest !~ / -- /) { $rest =~ s/(\*+)$/ -- \1/; $rest =~ s/(\(.*\))$/ -- \1/; } $rest =~ s/^of //; ($a,$b) = ($rest =~ /^\s*(\(.*\))\s*(.*)$/); $c = " "; if ($rest !~ / -- /) {$c = " -- ";} if (defined($a)) {$rest = $b . $c . $a;} @ing = split(/\s+/,$rest); $l = 0; foreach $ing (@ing) { if ($ing eq '--'){ @prep = splice(@ing,$l,99); shift @prep; last; } $l++; } &move_adj; $ing = join(' ',@ing); @ing = ''; $prep = join(' ',@prep); @prep = ''; $ing =~ s/\#//g; $prep =~ s/\#//g; (@ing) = (($ing . " ") =~ /\s*(.{1,41})\s+/g); (@prep) = (($prep . " ") =~ /\s*(.{1,19})\s+/g); $ingred[$i] = $ing[0]; $ingred[$i] .= " -- " . $prep[0] if defined($prep[0]); $lmax = $#ing; if ($lmax < $#prep) {$lmax = $#prep;} for ($l=1;$l<=$lmax;$l++) { $i++; $amt[$i] = " "; $units[$i] = " "; $ingred[$i] = $ing[$l] if defined($ing[$l]); $ingred[$i] .= " -- " . $prep[$l] if defined($prep[$l]); } if ($problem ne '') { $i++; $ingred[$i] = $problem; $amt[$i] = " "; $units[$i] = " "; $problem = ''; $i++; $ingred[$i] = "***** above line had a problem *****"; $amt[$i] = " "; $units[$i] = " "; } } } continue { if ($do_output) { &output; } } close(OUTPUT); } format HEADER = * Exported from MasterCook II * @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| $name Recipe By : @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $source Serving Size : @<<< Preparation Time :0:00 $serves Categories : @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $category[0],$category[1] @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $category[2],$category[3] Amount Measure Ingredient -- Preparation Method -------- ------------ -------------------------------- . format INGRED = @>>>>>>> @<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $amt[$k], $units[$k], $ingred[$k] . format TEXT = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $text[$k] . sub output { select(OUTPUT); @category = (@category, ' ',' ',' ',' '); $~ = 'HEADER'; write OUTPUT; $~ = 'INGRED'; for ($k=1;$k<=$i;$k++) { write OUTPUT; } $~ = 'TEXT'; for ($k=0;$k<=$j;$k++) { write OUTPUT; } print OUTPUT "\n - - - - - - - - - - - - - - - - - - \n"; &initialize ; } sub move_adj { local($i, $imax, $ing); if ($ing[0] =~ /^\s*(\([^)]*\))/) { push (@prep, $ing[0]); shift @ing; } $imax = $#ing; for ($i=0;$i<=$imax;$i++) { $ing = shift @ing; ($tst = $ing) =~ tr/A-Z/a-z/; if (defined($adjectives{$tst})) { push (@prep, $ing); } else { unshift (@ing, $ing); return; } } } sub initialize { $do_output = 0; $block = 'header'; $i=0; $j=0; @amt=""; @units=""; @ingred=""; @prep=""; @text=''; $text[0]="\n"; $name=""; $source = ""; $serves = ""; @category = (' ',' ',' ',' '); $~ = 'HEADER'; $problem = ''; } @REM=(" :end ") if 0;