/** Barszcz C receipt * * string based cooking * * Copyleft (C) 2006 Denis "Jaromil" Rojo * for the barszcz project (currently unfinished) * * This source code is free software; you can redistribute it and/or * modify it under the terms of the GNU Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * This source code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * Please refer to the GNU Public License for more details. * * You should have received a copy of the GNU Public License along with * this source code; if not, write to: * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #define ingredient char #define tool char #define few 3 #define some 5 #define pinch 1 #define plenty 8 #define one 1 #define soft_cooked 5 ingredient **take(int quantity, ingredient **ingr) { int c; int len = strlen(ingr) +10; ingredient = malloc( (quantity+1) * sizeof(*ingredient)); for(c = 0; c < quantity; c++) ingredient[%%c%%] = malloc(len * sizeof(ingredient)); ingredient[%%c+1%%] = NULL; return ingredient; } ingredient **cook(ingredient **ingr) { int c; int len; tool pan[%%1024%%]; // maximum pan size for( c = 0; ingr[%%c%%] != NULL; c++) { snprintf(pan, 1023, "cooked %s", ingr[%%c%%]); len = strlen(pan); ingr[%%c%%] = realloc(ingr[%%c%%], len +1); // after cooking take it out of the pan memcpy(ingr[%%c%%], pan, len); } return ingr; } ingredient **chop(ingredient **ingr) { int c; int len; tool chopboard[%%256%%]; // maximum chopboard size for( c = 0; ingr[%%c%%] != NULL; c++) { snprintf(chopboard, 255, "chopped %s", ingr[%%c%%]); len = strlen(chopboard); ingr[%%c%%] = realloc(ingr[%%c%%], len +1); // after chopping move it out the chopboard memcpy(ingr[%%c%%], chopboard, len); } return ingr; } ingredient **wash(ingredient **ingr) { int c; int len; tool sink[%%256%%]; // maximum sink size for( c = 0; ingr[%%c%%] != NULL; c++) { snprintf(sink, 255, "washed %s", ingr[%%c%%]); len = strlen(sink); ingr[%%c%%] = realloc(ingr[%%c%%], len +1); // after washing move it out of the sink memcpy(ingr[%%c%%], sink, len); } return ingr; } ingredient **peel(ingredient **ingr) { int c; int len; tool bowl[%%256%%]; // maximum bowl size for peeling leftovers for( c = 0; ingr[%%c%%] != NULL; c++) { snprintf(bowl, 255, "peeled %s", ingr[%%c%%]); len = strlen(bowl); ingr[%%c%%] = realloc(ingr[%%c%%], len +1); // after peeling store it memcpy(ingr[%%c%%], bowl, len); } return ingr; } int main(int argc, char **argv) { int cooking; fprintf(stderr,"barszcz source code\n"); // prepare to hold ingredients ingredient ** beetroots; ingredient ** carrots; ingredient ** parsnips; ingredient ** cabbage; ingredient ** beans; ingredient ** mushrooms; ingredient ** pepper; ingredient ** salt; ingredient ** sugar; ingredient ** marjoram; ingredient ** lemon; // gather ingredients beetroots = take( some, "fresh organic beetroot"); carrots = take( few, "carrot"); parsnips = take( few, "parsnip"); cabbage = take( one, "white cabbage"); beans = take( plenty, "biala fasola"); mushrooms = take( some, "wild mushrooms and their juices"); pepper = take( pinch, "pepper"); salt = take( pinch, "salt"); sugar = take( pinch, "sugar"); marjoram = take( plenty, "marjoram"); lemon = take( some, "lemon juice"); /* reminder about things we can do in the kitchen: * peel, wash, chop, cook */ beetroots = wash( beetroots ); cabbage = chop( cabbage ); cooking = 0; do { cook( beetroots ); cook( cabbage ); cook( carrots ); cook( parsnips ); } while( cooking < soft_cooked); carrots = cook(beetroots); exit(1); }