/* -------------------------------------------------------------------- File: libgourm.cc Author: Doug Beeferman Date: 2/23/97 Description: exports "print_recipe" function for generating recipes -------------------------------------------------------------------- */ #include #include #include #include #include #include #define MAX_FOODS 512 #define MAX_CHARS 1024 #define ALLOC_BLOCK_SIZE 50000 static int cFoods=0; #define NAMES 0 #define UNITS 1 #define ADJECTIVES 2 #define ACTIONS 3 #define ADVERBS 0 #define STARTING_CONTAINERS 1 #define LASTLINES 2 #define TITLES 3 static char *rgszFoodInfo[MAX_FOODS][4]; static int rgcFoodInfoCount[MAX_FOODS][4]; static char *rgszGlobalInfo[10]; static int rgcGlobalInfoCount[10]; static int rgfFoodsUsed[MAX_FOODS]; static char szBuffer[MAX_CHARS]; static char rgszVars[128][100]; static char rgszIng[MAX_FOODS][100]; static int count_fields(char *szStr); static char *return_field(char *szStr, int iIndex); static int bernoulli_trial(int iSuccessPercent, int iMaxVal); static char *normalize_word(char *s, int fPlural, int fAtomic); static void read_cookbook(char *szFilename); static void translate_string(char *s); void print_recipe( /* char szString */ ) { int iSeed1=0,iSeed2=0, i=1, iLastLine, iTitle, iTitleY=0; int cIngredients, iTemp, cServed, cFoodsUsed=0; char *pch = NULL; /* szString */; char szIngDesc[MAX_CHARS]; char szAdj[MAX_CHARS], szUnit[MAX_CHARS], szIng[MAX_CHARS]; /* Load cookbook */ read_cookbook("/home/doug/rrg/cookbook"); #if 0 /* Use string to initialize random number generator. */ while (*pch++) { iSeed1 += i * (unsigned char) *pch; iSeed2 += (unsigned char) *pch * (unsigned char) *pch; i++; } srandom(iSeed1); #endif srandom(time(NULL)); /* 1. Choose number of ingredients to use */ cIngredients = 2 + bernoulli_trial(80, 20); /* 2. Choose ingredients to use */ for (i=0; i=0; i--) if ((rgfFoodsUsed[i] == 1)&&(random()%2)) iTitleY = i; strcpy(rgszVars['Y'], normalize_word(return_field(rgszFoodInfo [iTitleY][NAMES], 0), 0, 0)); sprintf(rgszVars['D'], "%d", 25 + (random()%100)*10); sprintf(rgszVars['T'], "%d", 5 + (random()%115)); strcpy(szIngDesc, return_field(rgszGlobalInfo[TITLES], iTitle)); translate_string(szIngDesc); szIngDesc[0] = toupper(szIngDesc[0]); fprintf(stdout, "\n\n\t\t%s\n", szIngDesc); /* 5. For each selected ingredient, generate ingredient list entry */ fprintf(stdout, "\nIngredients:\n\n"); for (i=0; i")); /* Normalize words */ strcpy(szIng, normalize_word(return_field(rgszFoodInfo[i][NAMES], iIngred), ((!fAtomic) || (iQuant>1)), fAtomic)); strcpy(rgszIng[i], szIng); strcpy(szUnit, normalize_word(return_field(rgszFoodInfo[i][UNITS], iUnit), (iQuant>1), fAtomic)); if (!strcmp(return_field(rgszFoodInfo[i][ADJECTIVES], iAdj), "")) strcpy(szAdj, ""); else { strcpy(szAdj, return_field(rgszFoodInfo[i][ADJECTIVES], iAdj)); strcat(szAdj, " "); } if (fAtomic) sprintf(szIngDesc, "%d %s%s", iQuant, szAdj, szIng); else sprintf(szIngDesc, "%d %s of %s%s", iQuant, szUnit, szAdj, szIng); translate_string(szIngDesc); fprintf(stdout, "\t* %s\n", szIngDesc); cFoodsUsed++; } srandom(iSeed2); fprintf(stdout, "\nPreparation:\n\n"); /* 6. For each selected ingredient, generate action */ cFoodsUsed = 0; strcpy(rgszVars['C'], return_field(rgszGlobalInfo[STARTING_CONTAINERS], random()% rgcGlobalInfoCount[STARTING_CONTAINERS])); strcpy(rgszVars['Y'], rgszVars['C']); for (i=0; i