mash/beerxml.c

changeset 538
6d139c21e22c
parent 537
4eebab50993e
child 539
300b5c4cd977
equal deleted inserted replaced
537:4eebab50993e 538:6d139c21e22c
1 /*****************************************************************************
2 * Copyright (C) 2014
3 *
4 * Michiel Broek <mbroek at mbse dot eu>
5 *
6 * This file is part of the mbsePi-apps
7 *
8 * This is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * mbsePi-apps is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with EC-65K; see the file COPYING. If not, write to the Free
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/
22
23 #include "mash.h"
24 #include "beerxml.h"
25
26
27 recipe_rec *recipes = NULL;
28
29
30 int parseStyle(xmlDocPtr, xmlNodePtr, style_rec **);
31 int parseEquipment(xmlDocPtr, xmlNodePtr, equipment_rec **);
32 int parseMashStep(xmlDocPtr, xmlNodePtr, mash_step **);
33 int parseMashSteps(xmlDocPtr, xmlNodePtr, mash_step **);
34 int parseMash(xmlDocPtr, xmlNodePtr, mash_profile **);
35 int parseFermentable(xmlDocPtr, xmlNodePtr, fermentable_rec **);
36 int parseFermentables(xmlDocPtr, xmlNodePtr, fermentable_rec **);
37
38
39
40
41 /*
42 * Parse style
43 */
44 int parseStyle(xmlDocPtr doc, xmlNodePtr cur, style_rec **style)
45 {
46 xmlChar *key;
47 style_rec *item;
48 float val;
49
50 item = (style_rec *)malloc(sizeof(style_rec));
51 item->name = item->category = item->category_number = item->style_letter = item-> style_guide =
52 item->type = item->notes = item->profile = item->ingredients = item->examples = NULL;
53 item->og_min = item->og_max = item->fg_min = item->fg_max = item->ibu_min = item->ibu_max =
54 item->color_min = item->color_max = item->carb_min = item->carb_max =
55 item->abv_min = item->abv_max = 0.0;
56
57 cur = cur->xmlChildrenNode;
58 while (cur != NULL) {
59 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
60 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
61 if (xmlStrcmp(key, (const xmlChar *)"1")) {
62 xmlFree(key);
63 return 1;
64 }
65 item->version = 1;
66 xmlFree(key);
67 }
68 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
69 item->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
70 }
71 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CATEGORY"))) {
72 item->category = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
73 }
74 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CATEGORY_NUMBER"))) {
75 item->category_number = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
76 }
77 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STYLE_LETTER"))) {
78 item->style_letter = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
79 }
80 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STYLE_GUIDE"))) {
81 item->style_guide = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
82 }
83 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TYPE"))) {
84 item->type = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
85 }
86 if ((!xmlStrcmp(cur->name, (const xmlChar *)"OG_MIN"))) {
87 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
88 if (sscanf((const char *)key, "%f", &val) == 1)
89 item->og_min = val;
90 xmlFree(key);
91 }
92 if ((!xmlStrcmp(cur->name, (const xmlChar *)"OG_MAX"))) {
93 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
94 if (sscanf((const char *)key, "%f", &val) == 1)
95 item->og_max = val;
96 xmlFree(key);
97 }
98 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FG_MIN"))) {
99 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
100 if (sscanf((const char *)key, "%f", &val) == 1)
101 item->fg_min = val;
102 xmlFree(key);
103 }
104 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FG_MAX"))) {
105 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
106 if (sscanf((const char *)key, "%f", &val) == 1)
107 item->fg_max = val;
108 xmlFree(key);
109 }
110 if ((!xmlStrcmp(cur->name, (const xmlChar *)"IBU_MIN"))) {
111 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
112 if (sscanf((const char *)key, "%f", &val) == 1)
113 item->ibu_min = val;
114 xmlFree(key);
115 }
116 if ((!xmlStrcmp(cur->name, (const xmlChar *)"IBU_MAX"))) {
117 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
118 if (sscanf((const char *)key, "%f", &val) == 1)
119 item->ibu_max = val;
120 xmlFree(key);
121 }
122 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COLOR_MIN"))) {
123 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
124 if (sscanf((const char *)key, "%f", &val) == 1)
125 item->color_min = val;
126 xmlFree(key);
127 }
128 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COLOR_MAX"))) {
129 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
130 if (sscanf((const char *)key, "%f", &val) == 1)
131 item->color_max = val;
132 xmlFree(key);
133 }
134 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CARB_MIN"))) {
135 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
136 if (sscanf((const char *)key, "%f", &val) == 1)
137 item->carb_min = val;
138 xmlFree(key);
139 }
140 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CARB_MAX"))) {
141 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
142 if (sscanf((const char *)key, "%f", &val) == 1)
143 item->carb_max = val;
144 xmlFree(key);
145 }
146 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ABV_MIN"))) {
147 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
148 if (sscanf((const char *)key, "%f", &val) == 1)
149 item->abv_min = val;
150 xmlFree(key);
151 }
152 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ABV_MAX"))) {
153 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
154 if (sscanf((const char *)key, "%f", &val) == 1)
155 item->abv_max = val;
156 xmlFree(key);
157 }
158 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NOTES"))) {
159 item->notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
160 }
161 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE"))) {
162 item->profile = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
163 }
164 if ((!xmlStrcmp(cur->name, (const xmlChar *)"INGREDIENTS"))) {
165 item->ingredients = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
166 }
167 if ((!xmlStrcmp(cur->name, (const xmlChar *)"EXAMPLES"))) {
168 item->examples = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
169 }
170 cur = cur->next;
171 }
172
173 *style = item;
174 return 0;
175 }
176
177
178
179 /*
180 * Parse equipment
181 */
182 int parseEquipment(xmlDocPtr doc, xmlNodePtr cur, equipment_rec **equipment)
183 {
184 xmlChar *key;
185 equipment_rec *item;
186 float val;
187
188 item = (equipment_rec *)malloc(sizeof(equipment_rec));
189 item->name = item->notes = NULL;
190 item->version = 0;
191 item->boil_size = item->batch_size = item->tun_volume = item->tun_weight =
192 item->tun_specific_heat = item->top_up_water = item->trub_chiller_loss =
193 item->evap_rate = item->boil_time = item->lauter_deadspace =
194 item->top_up_kettle = item->hop_utilization = 0.0;
195 item->calc_boil_volume = FALSE;
196
197 cur = cur->xmlChildrenNode;
198 while (cur != NULL) {
199 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
200 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
201 if (xmlStrcmp(key, (const xmlChar *)"1")) {
202 xmlFree(key);
203 return 1;
204 }
205 xmlFree(key);
206 item->version = 1;
207 }
208 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
209 item->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
210 }
211 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOIL_SIZE"))) {
212 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
213 if (sscanf((const char *)key, "%f", &val) == 1)
214 item->boil_size = val;
215 xmlFree(key);
216 }
217 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BATCH_SIZE"))) {
218 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
219 if (sscanf((const char *)key, "%f", &val) == 1)
220 item->batch_size = val;
221 xmlFree(key);
222 }
223 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TUN_VOLUME"))) {
224 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
225 if (sscanf((const char *)key, "%f", &val) == 1)
226 item->tun_volume = val;
227 xmlFree(key);
228 }
229 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TUN_WEIGHT"))) {
230 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
231 if (sscanf((const char *)key, "%f", &val) == 1)
232 item->tun_weight = val;
233 xmlFree(key);
234 }
235 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TUN_SPECIFIC_HEAT"))) {
236 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
237 if (sscanf((const char *)key, "%f", &val) == 1)
238 item->tun_specific_heat = val;
239 xmlFree(key);
240 }
241 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TOP_UP_WATER"))) {
242 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
243 if (sscanf((const char *)key, "%f", &val) == 1)
244 item->top_up_water = val;
245 xmlFree(key);
246 }
247 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TRUB_CHILLER_LOSS"))) {
248 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
249 if (sscanf((const char *)key, "%f", &val) == 1)
250 item->trub_chiller_loss = val;
251 xmlFree(key);
252 }
253 if ((!xmlStrcmp(cur->name, (const xmlChar *)"EVAP_RATE"))) {
254 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
255 if (sscanf((const char *)key, "%f", &val) == 1)
256 item->evap_rate = val;
257 xmlFree(key);
258 }
259 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOIL_TIME"))) {
260 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
261 if (sscanf((const char *)key, "%f", &val) == 1)
262 item->boil_time = val;
263 xmlFree(key);
264 }
265 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CALC_BOIL_VOLUME"))) {
266 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
267 if (! xmlStrcmp(key, (const xmlChar *)"TRUE"))
268 item->calc_boil_volume = TRUE;
269 }
270 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LAUTER_DEADSPACE"))) {
271 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
272 if (sscanf((const char *)key, "%f", &val) == 1)
273 item->lauter_deadspace = val;
274 xmlFree(key);
275 }
276 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HOP_UTILIZATION"))) {
277 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
278 if (sscanf((const char *)key, "%f", &val) == 1)
279 item->hop_utilization = val;
280 xmlFree(key);
281 }
282 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NOTES"))) {
283 item->notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
284 }
285 cur = cur->next;
286 }
287
288 *equipment = item;
289 return 0;
290 }
291
292
293
294 /*
295 * Parse a Mash step and add it to the linked list
296 */
297 int parseMashStep(xmlDocPtr doc, xmlNodePtr cur, mash_step **mashstep)
298 {
299 xmlChar *key;
300 mash_step *step, *tmp;
301 float val;
302
303 cur = cur->xmlChildrenNode;
304
305 step = (mash_step *)malloc(sizeof(mash_step));
306 step->next = NULL;
307 step->name = NULL;
308 step->type = NULL;
309 step->infuse_amount = 0.0;
310 step->step_temp = 0.0;
311 step->end_temp = 0.0;
312 step->step_time = 0.0;
313 step->ramp_time = 0.0;
314 step->version = 0;
315
316 while (cur != NULL) {
317 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
318 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
319 if (xmlStrcmp(key, (const xmlChar *)"1")) {
320 xmlFree(key);
321 return 1;
322 }
323 step->version = 1;
324 xmlFree(key);
325 }
326 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
327 step->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
328 }
329 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TYPE"))) {
330 step->type = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
331 }
332 if ((!xmlStrcmp(cur->name, (const xmlChar *)"INFUSE_AMOUNT"))) {
333 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
334 if (sscanf((const char *)key, "%f", &val) == 1)
335 step->infuse_amount = val;
336 xmlFree(key);
337 }
338 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STEP_TEMP"))) {
339 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
340 if (sscanf((const char *)key, "%f", &val) == 1)
341 step->step_temp = val;
342 xmlFree(key);
343 }
344 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STEP_TIME"))) {
345 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
346 if (sscanf((const char *)key, "%f", &val) == 1)
347 step->step_time = val;
348 xmlFree(key);
349 }
350 if ((!xmlStrcmp(cur->name, (const xmlChar *)"END_TEMP"))) {
351 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
352 if (sscanf((const char *)key, "%f", &val) == 1)
353 step->end_temp = val;
354 xmlFree(key);
355 }
356 if ((!xmlStrcmp(cur->name, (const xmlChar *)"RAMP_TIME"))) {
357 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
358 if (sscanf((const char *)key, "%f", &val) == 1)
359 step->ramp_time = val;
360 xmlFree(key);
361 }
362
363 cur = cur->next;
364 }
365
366 if (*mashstep == NULL) {
367 *mashstep = step;
368 } else {
369 for (tmp = *mashstep; tmp; tmp = tmp->next) {
370 if (tmp->next == NULL) {
371 tmp->next = step;
372 break;
373 }
374 }
375 }
376 return 0;
377 }
378
379
380
381 /*
382 * Parse all Mash steps
383 */
384 int parseMashSteps(xmlDocPtr doc, xmlNodePtr cur, mash_step **step)
385 {
386 int rc;
387
388 cur = cur->xmlChildrenNode;
389 while (cur != NULL) {
390 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASH_STEP"))) {
391 if ((rc = parseMashStep(doc, cur, step)))
392 return 1;
393 }
394 cur = cur->next;
395 }
396 return 0;
397 }
398
399
400
401 /*
402 * Parse Mash profile
403 */
404 int parseMash(xmlDocPtr doc, xmlNodePtr cur, mash_profile **mash)
405 {
406 xmlChar *key;
407 mash_profile *mashprofile;
408 float val;
409
410 mashprofile = (mash_profile *)malloc(sizeof(mash_profile));
411 mashprofile->name = NULL;
412 mashprofile->version = 0;
413 mashprofile->notes = NULL;
414 mashprofile->grain_temp = 0.0;
415 mashprofile->mash_steps = NULL;
416 mashprofile->tun_temp = 0.0;
417 mashprofile->sparge_temp = 0.0;
418 mashprofile->ph = 0.0;
419 mashprofile->tun_weight = 0.0;
420 mashprofile->tun_specific_heat = 0.0;
421 mashprofile->equip_adjust = FALSE;
422
423 cur = cur->xmlChildrenNode;
424 while (cur != NULL) {
425 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
426 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
427 if (xmlStrcmp(key, (const xmlChar *)"1")) {
428 xmlFree(key);
429 return 1;
430 }
431 mashprofile->version = 1;
432 xmlFree(key);
433 }
434 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
435 mashprofile->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
436 }
437 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NOTES"))) {
438 mashprofile->notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
439 }
440 if ((!xmlStrcmp(cur->name, (const xmlChar *)"GRAIN_TEMP"))) {
441 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
442 if (sscanf((const char *)key, "%f", &val) == 1)
443 mashprofile->grain_temp = val;
444 xmlFree(key);
445 }
446 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TUN_TEMP"))) {
447 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
448 if (sscanf((const char *)key, "%f", &val) == 1)
449 mashprofile->tun_temp = val;
450 xmlFree(key);
451 }
452 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SPARGE_TEMP"))) {
453 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
454 if (sscanf((const char *)key, "%f", &val) == 1)
455 mashprofile->sparge_temp = val;
456 xmlFree(key);
457 }
458 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PH"))) {
459 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
460 if (sscanf((const char *)key, "%f", &val) == 1)
461 mashprofile->ph = val;
462 xmlFree(key);
463 }
464 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TUN_WEIGHT"))) {
465 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
466 if (sscanf((const char *)key, "%f", &val) == 1)
467 mashprofile->tun_weight = val;
468 xmlFree(key);
469 }
470 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TUN_SPECIFIC_HEAT"))) {
471 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
472 if (sscanf((const char *)key, "%f", &val) == 1)
473 mashprofile->tun_specific_heat = val;
474 xmlFree(key);
475 }
476 if ((!xmlStrcmp(cur->name, (const xmlChar *)"EQUIP_ADJUST"))) {
477 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
478 if (! xmlStrcmp(key, (const xmlChar *)"TRUE"))
479 mashprofile->equip_adjust = TRUE;
480 }
481 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASH_STEPS"))) {
482 parseMashSteps(doc, cur, &(mashprofile)->mash_steps);
483 }
484 cur = cur->next;
485 }
486
487 *mash = mashprofile;
488 return 0;
489 }
490
491
492
493 /*
494 * Parse fermentable
495 */
496 int parseFermentable(xmlDocPtr doc, xmlNodePtr cur, fermentable_rec **fr)
497 {
498 xmlChar *key;
499 fermentable_rec *item, *tmp;
500 float val;
501
502 item = (fermentable_rec *)malloc(sizeof(fermentable_rec));
503 item->next = NULL;
504 item->name = item->type = item->notes = item->origin = item->supplier = NULL;
505 item->version = 0;
506 item->amount = item->yield = item->color = item->coarse_fine_diff = item->moisture =
507 item->diastatic_power = item->protein = item->max_in_batch = 0.0;
508 item->add_after_boil = item->recommend_mash = FALSE;
509
510 cur = cur->xmlChildrenNode;
511 while (cur != NULL) {
512 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
513 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
514 if (xmlStrcmp(key, (const xmlChar *)"1")) {
515 xmlFree(key);
516 return 1;
517 }
518 item->version = 1;
519 xmlFree(key);
520 }
521 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
522 item->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
523 }
524 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NOTES"))) {
525 item->notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
526 }
527 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TYPE"))) {
528 item->type = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
529 }
530 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ORIGIN"))) {
531 item->origin = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
532 }
533 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SUPPLIER"))) {
534 item->supplier = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
535 }
536 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AMOUNT"))) {
537 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
538 if (sscanf((const char *)key, "%f", &val) == 1)
539 item->amount = val;
540 xmlFree(key);
541 }
542 if ((!xmlStrcmp(cur->name, (const xmlChar *)"YIELD"))) {
543 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
544 if (sscanf((const char *)key, "%f", &val) == 1)
545 item->yield = val;
546 xmlFree(key);
547 }
548 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COLOR"))) {
549 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
550 if (sscanf((const char *)key, "%f", &val) == 1)
551 item->color = val;
552 xmlFree(key);
553 }
554 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ADD_AFTER_BOIL"))) {
555 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
556 if (! xmlStrcmp(key, (const xmlChar *)"TRUE"))
557 item->add_after_boil = TRUE;
558 }
559 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COARSE_FINE_DIFF"))) {
560 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
561 if (sscanf((const char *)key, "%f", &val) == 1)
562 item->coarse_fine_diff = val;
563 xmlFree(key);
564 }
565 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MOISTURE"))) {
566 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
567 if (sscanf((const char *)key, "%f", &val) == 1)
568 item->moisture = val;
569 xmlFree(key);
570 }
571 if ((!xmlStrcmp(cur->name, (const xmlChar *)"DIASTATIC_POWER"))) {
572 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
573 if (sscanf((const char *)key, "%f", &val) == 1)
574 item->diastatic_power = val;
575 xmlFree(key);
576 }
577 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROTEIN"))) {
578 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
579 if (sscanf((const char *)key, "%f", &val) == 1)
580 item->protein = val;
581 xmlFree(key);
582 }
583 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MAX_IN_BATCH"))) {
584 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
585 if (sscanf((const char *)key, "%f", &val) == 1)
586 item->max_in_batch = val;
587 xmlFree(key);
588 }
589 if ((!xmlStrcmp(cur->name, (const xmlChar *)"RECOMMEND_MASH"))) {
590 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
591 if (! xmlStrcmp(key, (const xmlChar *)"TRUE"))
592 item->recommend_mash = TRUE;
593 }
594 cur = cur->next;
595 }
596
597 if (*fr == NULL) {
598 *fr = item;
599 } else {
600 for (tmp = *fr; tmp; tmp = tmp->next) {
601 if (tmp->next == NULL) {
602 tmp->next = item;
603 break;
604 }
605 }
606 }
607
608 return 0;
609 }
610
611
612
613 /*
614 * Parse fermentables
615 */
616 int parseFermentables(xmlDocPtr doc, xmlNodePtr cur, fermentable_rec **fr)
617 {
618 cur = cur->xmlChildrenNode;
619 while (cur != NULL) {
620 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTABLE"))) {
621 parseFermentable(doc, cur, fr);
622 }
623 cur = cur->next;
624 }
625 return 0;
626 }
627
628
629
630 /*
631 * Parse hop
632 */
633 int parseHop(xmlDocPtr doc, xmlNodePtr cur, hop_rec **hr)
634 {
635 xmlChar *key;
636 hop_rec *item, *tmp;
637 float val;
638
639 item = (hop_rec *)malloc(sizeof(hop_rec));
640 item->next = NULL;
641 item->name = item->use = item->notes = item->type = item->form =
642 item->origin = item->substitutes = NULL;
643 item->version = 0;
644 item->alpha = item->amount = item->time = item->beta = item->hsi =
645 item->humulene = item->caryophyllene = item->cohumulone = item->myrcene = 0.0;
646
647 cur = cur->xmlChildrenNode;
648 while (cur != NULL) {
649 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
650 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
651 if (xmlStrcmp(key, (const xmlChar *)"1")) {
652 xmlFree(key);
653 return 1;
654 }
655 item->version = 1;
656 xmlFree(key);
657 }
658 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
659 item->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
660 }
661 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ALPHA"))) {
662 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
663 if (sscanf((const char *)key, "%f", &val) == 1)
664 item->alpha = val;
665 xmlFree(key);
666 }
667 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AMOUNT"))) {
668 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
669 if (sscanf((const char *)key, "%f", &val) == 1)
670 item->amount = val;
671 xmlFree(key);
672 }
673 if ((!xmlStrcmp(cur->name, (const xmlChar *)"USE"))) {
674 item->use = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
675 }
676 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TIME"))) {
677 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
678 if (sscanf((const char *)key, "%f", &val) == 1)
679 item->time = val;
680 xmlFree(key);
681 }
682 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NOTES"))) {
683 item->notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
684 }
685 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TYPE"))) {
686 item->type = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
687 }
688 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FORM"))) {
689 item->form = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
690 }
691 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BETA"))) {
692 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
693 if (sscanf((const char *)key, "%f", &val) == 1)
694 item->beta = val;
695 xmlFree(key);
696 }
697 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HSI"))) {
698 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
699 if (sscanf((const char *)key, "%f", &val) == 1)
700 item->hsi = val;
701 xmlFree(key);
702 }
703 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ORIGIN"))) {
704 item->origin = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
705 }
706 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SUBSTITITES"))) {
707 item->substitutes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
708 }
709 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HUMULENE"))) {
710 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
711 if (sscanf((const char *)key, "%f", &val) == 1)
712 item->humulene = val;
713 xmlFree(key);
714 }
715 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CARYOPHYLLENE"))) {
716 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
717 if (sscanf((const char *)key, "%f", &val) == 1)
718 item->caryophyllene = val;
719 xmlFree(key);
720 }
721 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COHUMULONE"))) {
722 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
723 if (sscanf((const char *)key, "%f", &val) == 1)
724 item->cohumulone = val;
725 xmlFree(key);
726 }
727 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MYRCENE"))) {
728 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
729 if (sscanf((const char *)key, "%f", &val) == 1)
730 item->myrcene = val;
731 xmlFree(key);
732 }
733 cur = cur->next;
734 }
735
736 if (*hr == NULL) {
737 *hr = item;
738 } else {
739 for (tmp = *hr; tmp; tmp = tmp->next) {
740 if (tmp->next == NULL) {
741 tmp->next = item;
742 break;
743 }
744 }
745 }
746
747 return 0;
748 }
749
750
751
752 /*
753 * Parse hops
754 */
755 int parseHops(xmlDocPtr doc, xmlNodePtr cur, hop_rec **hr)
756 {
757 cur = cur->xmlChildrenNode;
758 while (cur != NULL) {
759 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HOP"))) {
760 parseHop(doc, cur, hr);
761 }
762 cur = cur->next;
763 }
764 return 0;
765 }
766
767
768
769 /*
770 * Parse Yeast
771 */
772 int parseYeast(xmlDocPtr doc, xmlNodePtr cur, yeast_rec **yr)
773 {
774 xmlChar *key;
775 yeast_rec *item, *tmp;
776 float val;
777 int ival;
778
779 item = (yeast_rec *)malloc(sizeof(yeast_rec));
780 item->next = NULL;
781 item->name = item->type = item->form = item->laboratory = item->product_id = item->flocculation = item->notes = item->best_for = NULL;
782 item->amount = item->min_temperature = item->max_temperature = item->attenuation = 0.0;
783 item->amount_is_weight = item->add_to_secondary = FALSE;
784 item->version = item->times_cultured = item->max_reuse = 0;
785
786 cur = cur->xmlChildrenNode;
787 while (cur != NULL) {
788 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
789 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
790 if (xmlStrcmp(key, (const xmlChar *)"1")) {
791 xmlFree(key);
792 return 1;
793 }
794 item->version = 1;
795 xmlFree(key);
796 }
797 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
798 item->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
799 }
800 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TYPE"))) {
801 item->type = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
802 }
803 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FORM"))) {
804 item->form = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
805 }
806 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AMOUNT"))) {
807 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
808 if (sscanf((const char *)key, "%f", &val) == 1)
809 item->amount = val;
810 xmlFree(key);
811 }
812 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AMOUNT_IS_WEIGHT"))) {
813 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
814 if (! xmlStrcmp(key, (const xmlChar *)"TRUE"))
815 item->amount_is_weight = TRUE;
816 }
817 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LABORATORY"))) {
818 item->laboratory = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
819 }
820 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRODUCT_ID"))) {
821 item->product_id = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
822 }
823 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MIN_TEMPERATURE"))) {
824 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
825 if (sscanf((const char *)key, "%f", &val) == 1)
826 item->min_temperature = val;
827 xmlFree(key);
828 }
829 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MAX_TEMPERATURE"))) {
830 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
831 if (sscanf((const char *)key, "%f", &val) == 1)
832 item->max_temperature = val;
833 xmlFree(key);
834 }
835 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FLOCCULATION"))) {
836 item->flocculation = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
837 }
838 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ATTENUATION"))) {
839 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
840 if (sscanf((const char *)key, "%f", &val) == 1)
841 item->attenuation = val;
842 xmlFree(key);
843 }
844 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NOTES"))) {
845 item->notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
846 }
847 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEST_FOR"))) {
848 item->best_for = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
849 }
850 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TIMES_CULTURED"))) {
851 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
852 if (sscanf((const char *)key, "%d", &ival) == 1)
853 item->times_cultured = ival;
854 xmlFree(key);
855 }
856 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MAX_REUSE"))) {
857 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
858 if (sscanf((const char *)key, "%d", &ival) == 1)
859 item->max_reuse = ival;
860 xmlFree(key);
861 }
862 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ADD_TO_SECONDARY"))) {
863 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
864 if (! xmlStrcmp(key, (const xmlChar *)"TRUE"))
865 item->add_to_secondary = TRUE;
866 }
867 cur = cur->next;
868 }
869
870 if (*yr == NULL) {
871 *yr = item;
872 } else {
873 for (tmp = *yr; tmp; tmp = tmp->next) {
874 if (tmp->next == NULL) {
875 tmp->next = item;
876 break;
877 }
878 }
879 }
880
881 return 0;
882 }
883
884
885
886 /*
887 * Parse Yeasts
888 */
889 int parseYeasts(xmlDocPtr doc, xmlNodePtr cur, yeast_rec **yr)
890 {
891 cur = cur->xmlChildrenNode;
892 while (cur != NULL) {
893 if ((!xmlStrcmp(cur->name, (const xmlChar *)"YEAST"))) {
894 parseYeast(doc, cur, yr);
895 }
896 cur = cur->next;
897 }
898 return 0;
899 }
900
901
902
903 /*
904 * Parse Misc
905 */
906 int parseMisc(xmlDocPtr doc, xmlNodePtr cur, misc_rec **mr)
907 {
908 xmlChar *key;
909 misc_rec *item, *tmp;
910 float val;
911
912 item = (misc_rec *)malloc(sizeof(misc_rec));
913 item->next = NULL;
914 item->name = item->type = item->use = item->use_for = item->notes = NULL;
915 item->amount = item->time = 0.0;
916 item->amount_is_weight = FALSE;
917 item->version = 0;
918
919 cur = cur->xmlChildrenNode;
920 while (cur != NULL) {
921 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
922 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
923 if (xmlStrcmp(key, (const xmlChar *)"1")) {
924 xmlFree(key);
925 return 1;
926 }
927 item->version = 1;
928 xmlFree(key);
929 }
930 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
931 item->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
932 }
933 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TYPE"))) {
934 item->type = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
935 }
936 if ((!xmlStrcmp(cur->name, (const xmlChar *)"USE"))) {
937 item->use = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
938 }
939 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TIME"))) {
940 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
941 if (sscanf((const char *)key, "%f", &val) == 1)
942 item->time = val;
943 xmlFree(key);
944 }
945 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AMOUNT"))) {
946 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
947 if (sscanf((const char *)key, "%f", &val) == 1)
948 item->amount = val;
949 xmlFree(key);
950 }
951 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AMOUNT_IS_WEIGHT"))) {
952 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
953 if (! xmlStrcmp(key, (const xmlChar *)"TRUE"))
954 item->amount_is_weight = TRUE;
955 }
956 if ((!xmlStrcmp(cur->name, (const xmlChar *)"USE_FOR"))) {
957 item->use_for = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
958 }
959 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NOTES"))) {
960 item->notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
961 }
962 cur = cur->next;
963 }
964
965 if (*mr == NULL) {
966 *mr = item;
967 } else {
968 for (tmp = *mr; tmp; tmp = tmp->next) {
969 if (tmp->next == NULL) {
970 tmp->next = item;
971 break;
972 }
973 }
974 }
975
976 return 0;
977 }
978
979
980
981 /*
982 * Parse Miscs
983 */
984 int parseMiscs(xmlDocPtr doc, xmlNodePtr cur, misc_rec **mr)
985 {
986 cur = cur->xmlChildrenNode;
987 while (cur != NULL) {
988 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MISC"))) {
989 parseMisc(doc, cur, mr);
990 }
991 cur = cur->next;
992 }
993 return 0;
994 }
995
996
997
998 /*
999 * Parse Water
1000 */
1001 int parseWater(xmlDocPtr doc, xmlNodePtr cur, water_rec **wr)
1002 {
1003 xmlChar *key;
1004 water_rec *item, *tmp;
1005 float val;
1006
1007 item = (water_rec *)malloc(sizeof(water_rec));
1008 item->next = NULL;
1009 item->name = item->notes = NULL;
1010 item->amount = item->calcium = item->bicarbonate = item->sulfate = item->chloride = item->sodium = item->magnesium = item->ph = 0.0;
1011 item->version = 0;
1012
1013 cur = cur->xmlChildrenNode;
1014 while (cur != NULL) {
1015 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
1016 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1017 if (xmlStrcmp(key, (const xmlChar *)"1")) {
1018 xmlFree(key);
1019 return 1;
1020 }
1021 item->version = 1;
1022 xmlFree(key);
1023 }
1024 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
1025 item->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1026 }
1027 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AMOUNT"))) {
1028 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1029 if (sscanf((const char *)key, "%f", &val) == 1)
1030 item->amount = val;
1031 xmlFree(key);
1032 }
1033 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CALCIUM"))) {
1034 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1035 if (sscanf((const char *)key, "%f", &val) == 1)
1036 item->calcium = val;
1037 xmlFree(key);
1038 }
1039 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BICARBONATE"))) {
1040 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1041 if (sscanf((const char *)key, "%f", &val) == 1)
1042 item->bicarbonate = val;
1043 xmlFree(key);
1044 }
1045 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SULFATE"))) {
1046 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1047 if (sscanf((const char *)key, "%f", &val) == 1)
1048 item->sulfate = val;
1049 xmlFree(key);
1050 }
1051 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CHLORIDE"))) {
1052 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1053 if (sscanf((const char *)key, "%f", &val) == 1)
1054 item->chloride = val;
1055 xmlFree(key);
1056 }
1057 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SODIUM"))) {
1058 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1059 if (sscanf((const char *)key, "%f", &val) == 1)
1060 item->sodium = val;
1061 xmlFree(key);
1062 }
1063 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MAGNESIUM"))) {
1064 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1065 if (sscanf((const char *)key, "%f", &val) == 1)
1066 item->magnesium = val;
1067 xmlFree(key);
1068 }
1069 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PH"))) {
1070 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1071 if (sscanf((const char *)key, "%f", &val) == 1)
1072 item->ph = val;
1073 xmlFree(key);
1074 }
1075 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NOTES"))) {
1076 item->notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1077 }
1078 cur = cur->next;
1079 }
1080
1081 if (*wr == NULL) {
1082 *wr = item;
1083 } else {
1084 for (tmp = *wr; tmp; tmp = tmp->next) {
1085 if (tmp->next == NULL) {
1086 tmp->next = item;
1087 break;
1088 }
1089 }
1090 }
1091
1092 return 0;
1093 }
1094
1095
1096
1097 /*
1098 * Parse Waters
1099 */
1100 int parseWaters(xmlDocPtr doc, xmlNodePtr cur, water_rec **wr)
1101 {
1102 cur = cur->xmlChildrenNode;
1103 while (cur != NULL) {
1104 if ((!xmlStrcmp(cur->name, (const xmlChar *)"WATER"))) {
1105 parseWater(doc, cur, wr);
1106 }
1107 cur = cur->next;
1108 }
1109 return 0;
1110 }
1111
1112
1113
1114 /*
1115 * Parse a recipe
1116 */
1117 void parseRecipe(xmlDocPtr doc, xmlNodePtr cur)
1118 {
1119 xmlChar *key;
1120 recipe_rec *recipe, *tmp;
1121 float val;
1122 int ival;
1123
1124 recipe = (recipe_rec *)malloc(sizeof(recipe_rec));
1125 recipe->next = NULL;
1126 recipe->name = NULL;
1127 recipe->brewer = NULL;
1128 recipe->asst_brewer = NULL;
1129 recipe->type = NULL;
1130 recipe->style = NULL;
1131 recipe->equipment = NULL;
1132 recipe->batch_size = 0.0;
1133 recipe->boil_time = 0.0;
1134 recipe->efficiency = 0.0;
1135 recipe->hops = NULL;
1136 recipe->fermentables = NULL;
1137 recipe->miscs = NULL;
1138 recipe->yeasts = NULL;
1139 recipe->waters = NULL;
1140 recipe->notes = NULL;
1141 recipe->taste_notes = NULL;
1142 recipe->taste_rating = 0.0;
1143 recipe->og = 0.0;
1144 recipe->fg = 0.0;
1145 recipe->fermentation_stages = 0;
1146 recipe->primary_age = recipe->secondary_age = recipe->tertiary_age = recipe->age = 0;
1147 recipe->primary_temp = recipe->secondary_temp = recipe->tertiary_temp = recipe->age_temp = 0.0;
1148 recipe->date = NULL;
1149 recipe->carbonation = 0.0;
1150 recipe->forced_carbonation = FALSE;
1151 recipe->priming_sugar_name = NULL;
1152 recipe->carbonation_temp = 0.0;
1153 recipe->priming_sugar_equiv = recipe->keg_priming_factor = 0.0;
1154
1155 cur = cur->xmlChildrenNode;
1156 while (cur != NULL) {
1157 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
1158 recipe->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1159 }
1160 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TYPE"))) {
1161 recipe->type = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1162 }
1163 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STYLE"))) {
1164 parseStyle(doc, cur, &(recipe)->style);
1165 }
1166 if ((!xmlStrcmp(cur->name, (const xmlChar *)"EQUIPMENT"))) {
1167 parseEquipment(doc, cur, &(recipe)->equipment);
1168 }
1169 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BREWER"))) {
1170 recipe->brewer = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1171 }
1172 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ASST_BREWER"))) {
1173 recipe->asst_brewer = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1174 }
1175 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BATCH_SIZE"))) {
1176 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1177 if (sscanf((const char *)key, "%f", &val) == 1)
1178 recipe->batch_size = val;
1179 xmlFree(key);
1180 }
1181 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOIL_SIZE"))) {
1182 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1183 if (sscanf((const char *)key, "%f", &val) == 1)
1184 recipe->boil_size = val;
1185 xmlFree(key);
1186 }
1187 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOIL_TIME"))) {
1188 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1189 if (sscanf((const char *)key, "%f", &val) == 1)
1190 recipe->boil_time = val;
1191 xmlFree(key);
1192 }
1193 if ((!xmlStrcmp(cur->name, (const xmlChar *)"EFFICIENCY"))) {
1194 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1195 if (sscanf((const char *)key, "%f", &val) == 1)
1196 recipe->efficiency = val;
1197 xmlFree(key);
1198 }
1199 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HOPS"))) {
1200 parseHops(doc, cur, &(recipe)->hops);
1201 }
1202 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTABLES"))) {
1203 parseFermentables(doc, cur, &(recipe)->fermentables);
1204 }
1205 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MISCS"))) {
1206 parseMiscs(doc, cur, &(recipe)->miscs);
1207 }
1208 if ((!xmlStrcmp(cur->name, (const xmlChar *)"YEASTS"))) {
1209 parseYeasts(doc, cur, &(recipe)->yeasts);
1210 }
1211 if ((!xmlStrcmp(cur->name, (const xmlChar *)"WATERS"))) {
1212 parseWaters(doc, cur, &(recipe)->waters);
1213 }
1214 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASH"))) {
1215 parseMash(doc, cur, &(recipe)->mash);
1216 }
1217 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NOTES"))) {
1218 recipe->notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1219 }
1220 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TASTE_NOTES"))) {
1221 recipe->taste_notes = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1222 }
1223 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TASTE_RATING"))) {
1224 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1225 if (sscanf((const char *)key, "%f", &val) == 1)
1226 recipe->taste_rating = val;
1227 xmlFree(key);
1228 }
1229 if ((!xmlStrcmp(cur->name, (const xmlChar *)"OG"))) {
1230 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1231 if (sscanf((const char *)key, "%f", &val) == 1)
1232 recipe->og = val;
1233 xmlFree(key);
1234 }
1235 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FG"))) {
1236 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1237 if (sscanf((const char *)key, "%f", &val) == 1)
1238 recipe->fg = val;
1239 xmlFree(key);
1240 }
1241 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTATION_STAGES"))) {
1242 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1243 if (sscanf((const char *)key, "%d", &ival) == 1)
1244 recipe->fermentation_stages = ival;
1245 xmlFree(key);
1246 }
1247 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRIMARY_AGE"))) {
1248 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1249 if (sscanf((const char *)key, "%d", &ival) == 1)
1250 recipe->primary_age = ival;
1251 xmlFree(key);
1252 }
1253 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRIMARY_TEMP"))) {
1254 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1255 if (sscanf((const char *)key, "%f", &val) == 1)
1256 recipe->primary_temp = val;
1257 xmlFree(key);
1258 }
1259 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SECONDARY_AGE"))) {
1260 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1261 if (sscanf((const char *)key, "%d", &ival) == 1)
1262 recipe->secondary_age = ival;
1263 xmlFree(key);
1264 }
1265 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SECONDARY_TEMP"))) {
1266 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1267 if (sscanf((const char *)key, "%f", &val) == 1)
1268 recipe->secondary_temp = val;
1269 xmlFree(key);
1270 }
1271 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TERTIARY_AGE"))) {
1272 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1273 if (sscanf((const char *)key, "%d", &ival) == 1)
1274 recipe->tertiary_age = ival;
1275 xmlFree(key);
1276 }
1277 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TERTIARY_TEMP"))) {
1278 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1279 if (sscanf((const char *)key, "%f", &val) == 1)
1280 recipe->tertiary_temp = val;
1281 xmlFree(key);
1282 }
1283 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AGE"))) {
1284 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1285 if (sscanf((const char *)key, "%d", &ival) == 1)
1286 recipe->age = ival;
1287 xmlFree(key);
1288 }
1289 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AGE_TEMP"))) {
1290 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1291 if (sscanf((const char *)key, "%f", &val) == 1)
1292 recipe->age_temp = val;
1293 xmlFree(key);
1294 }
1295 if ((!xmlStrcmp(cur->name, (const xmlChar *)"DATE"))) {
1296 recipe->date = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1297 }
1298 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CARBONATION"))) {
1299 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1300 if (sscanf((const char *)key, "%f", &val) == 1)
1301 recipe->carbonation = val;
1302 xmlFree(key);
1303 }
1304 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FORCED_CARBONATION"))) {
1305 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1306 if (! xmlStrcmp(key, (const xmlChar *)"TRUE"))
1307 recipe->forced_carbonation = TRUE;
1308 }
1309 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRIMING_SUGAR_NAME"))) {
1310 recipe->priming_sugar_name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1311 }
1312 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CARBONATION_TEMP"))) {
1313 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1314 if (sscanf((const char *)key, "%f", &val) == 1)
1315 recipe->carbonation_temp = val;
1316 xmlFree(key);
1317 }
1318 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRIMING_SUGAR_EQUIV"))) {
1319 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1320 if (sscanf((const char *)key, "%f", &val) == 1)
1321 recipe->priming_sugar_equiv = val;
1322 xmlFree(key);
1323 }
1324 if ((!xmlStrcmp(cur->name, (const xmlChar *)"KEG_PRIMING_FACTOR"))) {
1325 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1326 if (sscanf((const char *)key, "%f", &val) == 1)
1327 recipe->keg_priming_factor = val;
1328 xmlFree(key);
1329 }
1330 cur = cur->next;
1331 }
1332
1333 if (recipes == NULL) {
1334 recipes = recipe;
1335 } else {
1336 for (tmp = recipes; tmp; tmp = tmp->next) {
1337 if (tmp->next == NULL) {
1338 tmp->next = recipe;
1339 break;
1340 }
1341 }
1342 }
1343 }
1344
1345
1346
1347 int parseBeerXML(char *docname)
1348 {
1349 xmlDocPtr doc;
1350 xmlNodePtr cur;
1351
1352 if ((doc = xmlParseFile(docname)) == NULL) {
1353 fprintf(stderr, "XML file %s errors.\n", docname);
1354 return 1;
1355 }
1356
1357 if ((cur = xmlDocGetRootElement(doc)) == NULL) {
1358 fprintf(stderr, "XML file %s empty.\n", docname);
1359 xmlFreeDoc(doc);
1360 return 1;
1361 }
1362
1363 if (xmlStrcmp(cur->name, (const xmlChar*)"RECIPES")) {
1364 fprintf(stderr, "XML file %s is not a BeerXML file.\n", docname);
1365 xmlFreeDoc(doc);
1366 return 1;
1367 }
1368
1369 /*
1370 * Parse all recipes
1371 */
1372 cur = cur->xmlChildrenNode;
1373 while (cur != NULL) {
1374 if ((!xmlStrcmp(cur->name, (const xmlChar *)"RECIPE"))) {
1375 parseRecipe(doc, cur);
1376 }
1377 cur = cur->next;
1378 }
1379
1380 xmlFreeDoc(doc);
1381 return 0;
1382 }
1383
1384
1385
1386 /*
1387 * For debugging purposes, dump the recipes
1388 */
1389 void printBeerXML(void)
1390 {
1391 recipe_rec *tmp0;
1392 mash_step *tmp1;
1393 fermentable_rec *tmp2;
1394 equipment_rec *tmp3;
1395 style_rec *tmp4;
1396 hop_rec *tmp5;
1397 yeast_rec *tmp6;
1398 misc_rec *tmp7;
1399 water_rec *tmp8;
1400 int mashstep = 0;
1401 float grain_weight = 0.0, water_grain_ratio, tun_water = 0.0, temp;
1402
1403 for (tmp0 = recipes; tmp0; tmp0 = tmp0->next) {
1404 printf("--------------------------------------------------------------------------------\n");
1405 printf("Recipe: %s\n", tmp0->name);
1406 printf("Type: %s\n", tmp0->type);
1407 if (tmp0->notes)
1408 printf("Notes: %s\n", tmp0->notes);
1409 if (tmp0->brewer || tmp0->asst_brewer)
1410 printf("Brewer: %s Assistent brewer: %s\n", tmp0->brewer, tmp0->asst_brewer);
1411 printf("Batch size: %5.1f Boil time: %5.1f Efficiency: %5.1f\n", tmp0->batch_size, tmp0->boil_time, tmp0->efficiency);
1412 printf("Taste rate: %5.1f Taste notes: %s\n", tmp0->taste_rating, tmp0->taste_notes);
1413 printf("Original G: %5.3f Final G: %5.3f\n", tmp0->og, tmp0->fg);
1414 printf("\n");
1415
1416 if (tmp0->equipment) {
1417 tmp3 = tmp0->equipment;
1418 printf("Equipment: %s\n", tmp3->name);
1419 if (tmp3->notes)
1420 printf(" Notes: %s\n", tmp3->notes);
1421 printf(" Boil size: %5.1f Batch size: %5.1f Boil time: %5.1f\n", tmp3->boil_size, tmp3->batch_size, tmp3->boil_time);
1422 printf(" Tun volume: %5.1f Tun weight: %5.1f Specific heat: %5.1f\n", tmp3->tun_volume, tmp3->tun_weight, tmp3->tun_specific_heat);
1423 printf(" TopUp: %5.1f Chiller loss: %5.1f Evaporation rate: %5.1f\n", tmp3->top_up_water, tmp3->trub_chiller_loss, tmp3->evap_rate);
1424 printf(" Tun loss: %5.1f TopUp kettle: %5.1f Hop utilization: %5.1f\n", tmp3->lauter_deadspace, tmp3->top_up_kettle, tmp3->hop_utilization);
1425 printf(" CalcBoilVol: %s\n", tmp3->calc_boil_volume ? "YES":"NO");
1426 printf("\n");
1427 }
1428
1429 if (tmp0->style) {
1430 tmp4 = tmp0->style;
1431 printf("Style: %s-%s Type: %s\n", tmp4->style_letter, tmp4->name, tmp4->type);
1432 if (tmp4->category || tmp4->category_number || tmp4->style_guide)
1433 printf(" Category: %s Cat nr: %s Guide: %s\n", tmp4->category, tmp4->category_number, tmp4->style_guide);
1434 printf(" OG: %5.3f - %5.3f\n", tmp4->og_min, tmp4->og_max);
1435 printf(" FG: %5.3f - %5.3f\n", tmp4->fg_min, tmp4->fg_max);
1436 printf(" Bittern: %5.1f - %5.1f IBU\n", tmp4->ibu_min, tmp4->ibu_max);
1437 printf(" Color: %5.1f - %5.1f SRM\n", tmp4->color_min, tmp4->color_max);
1438 printf(" Carb: %5.1f - %5.1f V-CO2\n", tmp4->carb_min, tmp4->carb_max);
1439 printf(" ABV: %5.1f - %5.1f %%\n", tmp4->abv_min, tmp4->abv_max);
1440 if (tmp4->notes)
1441 printf(" Notes: %s\n", tmp4->notes);
1442 if (tmp4->profile)
1443 printf(" Profile: %s\n", tmp4->profile);
1444 if (tmp4->examples)
1445 printf(" Examples: %s\n", tmp4->examples);
1446 printf("\n");
1447 }
1448
1449 printf("Fermentables:\n");
1450 printf(" Type Name Kg Mash Moist\n");
1451 for (tmp2 = tmp0->fermentables; tmp2; tmp2 = tmp2->next) {
1452 printf(" %-12s %-25s %6.3f %-5s %5.1f\n", tmp2->type, tmp2->name, tmp2->amount,
1453 tmp2->recommend_mash ? "TRUE":"FALSE", tmp2->moisture);
1454 if (tmp2->recommend_mash)
1455 grain_weight += tmp2->amount;
1456 }
1457 printf("\n");
1458
1459 if (tmp0->hops) {
1460 printf("Hops:\n");
1461 // 123456789 1234567890 1234567890123456789012345 123456 12345 12345
1462 printf(" Type Use Name Kg Time Alpha\n");
1463 for (tmp5 = tmp0->hops; tmp5; tmp5 = tmp5->next) {
1464 printf(" %-9s %-10s %-25s %6.3f %5.1f %5.1f\n", tmp5->type, tmp5->use, tmp5->name, tmp5->amount, tmp5->time, tmp5->alpha);
1465 }
1466 printf("\n");
1467 }
1468
1469 if (tmp0->miscs) {
1470 printf("Miscs:\n");
1471 // 12345678901 123456789 1234567890123456789012345 123456 12345 12345
1472 printf(" Type Use Name Kg Time\n");
1473 for (tmp7 = tmp0->miscs; tmp7; tmp7 = tmp7->next) {
1474 printf(" %-11s %-9s %-25s %6.3f %5.1f\n", tmp7->type, tmp7->use, tmp7->name, tmp7->amount, tmp7->time);
1475 }
1476 printf("\n");
1477 }
1478
1479 if (tmp0->waters) {
1480 printf("Wateren:\n");
1481 // 1234567890123456789012345 12345 12345 1234...
1482 printf(" Name Ltrs PH Notes\n");
1483 for (tmp8 = tmp0->waters; tmp8; tmp8 = tmp8->next) {
1484 printf(" %-25s %5.1f %5.1f %s\n", tmp8->name, tmp8->amount, tmp8->ph, tmp8->notes);
1485 }
1486 printf("\n");
1487 }
1488
1489 printf("Mash profile: %s\n", tmp0->mash->name);
1490 if (tmp0->mash->notes)
1491 printf(" Notes: %s\n", tmp0->mash->notes);
1492 printf(" Grain temp: %5.1f Tun temp: %5.1f Sparge temp: %5.1f\n", tmp0->mash->grain_temp, tmp0->mash->tun_temp, tmp0->mash->sparge_temp);
1493 printf(" PH: %5.1f Tun weight: %6.2f Tun specific heat: %6.2f\n", tmp0->mash->ph, tmp0->mash->tun_weight, tmp0->mash->tun_specific_heat);
1494 printf(" Equip adjust: %s\n", tmp0->mash->equip_adjust ? "TRUE":"FALSE");
1495 printf("\n");
1496
1497 if (tmp0->mash->mash_steps) {
1498 mashstep = 0;
1499 printf("st Name Type Temp Endtmp Dur Rmp Inf/Dec L/Kg\n");
1500 for (tmp1 = tmp0->mash->mash_steps; tmp1; tmp1 = tmp1->next) {
1501 mashstep++;
1502 tun_water += tmp1->infuse_amount;
1503 water_grain_ratio = tun_water / grain_weight;
1504 temp = tmp1->infuse_amount;
1505 // if ((tmp1->infuse_amount == 0.0) && (tmp1->decotion_amt > 0.0))
1506 // temp = tmp1->decotion_amt;
1507 printf("%2d %-16s %-12s %6.1f %6.1f %3.0f %3.0f %6.1f %6.2f\n", mashstep, tmp1->name, tmp1->type,
1508 tmp1->step_temp, tmp1->end_temp, tmp1->step_time, tmp1->ramp_time, temp, water_grain_ratio);
1509 }
1510 printf("\n");
1511 }
1512
1513 if (tmp0->yeasts) {
1514 for (tmp6 = tmp0->yeasts; tmp6; tmp6 = tmp6->next) {
1515 printf("Yeast: %s\n", tmp6->name);
1516 printf(" Type: %-20s Form: %-20s Amount: %7.4f %s\n",
1517 tmp6->type, tmp6->form, tmp6->amount, tmp6->amount_is_weight ? "Kg":"L");
1518 printf(" Lab: %-20s Product id: %-20s Flocculation: %s\n", tmp6->laboratory, tmp6->product_id, tmp6->flocculation);
1519 printf(" Min temp: %5.1f Max temp: %5.1f Attenuation: %5.1f\n",
1520 tmp6->min_temperature, tmp6->max_temperature, tmp6->attenuation);
1521 if (tmp6->notes)
1522 printf(" Notes: %s\n", tmp6->notes);
1523 printf("\n");
1524 }
1525 }
1526
1527 printf("\n");
1528 }
1529 }
1530
1531

mercurial