Changeset 15513 for trunk/psModules/src/config/pmConfigRecipes.c
- Timestamp:
- Nov 8, 2007, 11:53:00 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfigRecipes.c (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfigRecipes.c
r12916 r15513 5 5 #include <stdio.h> 6 6 #include <string.h> 7 #include <strings.h> /* for strn?casecmp */7 #include <strings.h> /* for strn?casecmp */ 8 8 #include <unistd.h> 9 9 #include <libgen.h> … … 33 33 options = psMetadataAlloc (); 34 34 success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "OPTIONS", PS_DATA_METADATA, "", options); 35 assert (success); // type mismatch : OPTIONS already defined but wrong type36 psFree (options); // drop extra reference35 assert (success); // type mismatch : OPTIONS already defined but wrong type 36 psFree (options); // drop extra reference 37 37 } 38 38 … … 44 44 recipe = psMetadataAlloc(); 45 45 success = psMetadataAddPtr(options, PS_LIST_TAIL, recipeName, PS_DATA_METADATA, "", recipe); 46 assert (success); // type mismatch : OPTIONS already defined but wrong type47 psFree (recipe); // drop extra reference46 assert (success); // type mismatch : OPTIONS already defined but wrong type 47 psFree (recipe); // drop extra reference 48 48 } 49 49 return recipe; … … 67 67 // master recipe files in the site:recipe location when they are built. 68 68 if (config->site && (source & PM_RECIPE_SOURCE_SITE)) { 69 if (!loadRecipeSite(&status, config, config->site)) {69 if (!loadRecipeSite(&status, config, config->site)) { 70 70 psError(PS_ERR_IO, false, "Failed to read recipes from site config"); 71 return false;72 } 73 psTrace ("psModules.config", 3, "read recipes from site config");71 return false; 72 } 73 psTrace ("psModules.config", 3, "read recipes from site config"); 74 74 } 75 75 … … 81 81 if (!loadRecipeCamera(&status, config, config->camera)) { 82 82 psError(PS_ERR_IO, false, "Failed to read recipes from camera config"); 83 return false;84 } 85 if (status) {86 psTrace ("psModules.config", 3, "read recipes from camera config");87 } else {88 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by camera config");89 }83 return false; 84 } 85 if (status) { 86 psTrace ("psModules.config", 3, "read recipes from camera config"); 87 } else { 88 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by camera config"); 89 } 90 90 } 91 91 … … 94 94 if (!loadRecipeFromArguments(&status, config)) { 95 95 psError(PS_ERR_IO, false, "Failed to read recipes from command-line arguments"); 96 return false;97 } 98 if (status) {99 psTrace ("psModules.config", 3, "read recipes from command-line arguments");100 } else {101 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments");102 }96 return false; 97 } 98 if (status) { 99 psTrace ("psModules.config", 3, "read recipes from command-line arguments"); 100 } else { 101 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied on command-line arguments"); 102 } 103 103 if (!loadRecipeSymbols(&status, config)) { 104 104 psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references"); 105 return false;106 } 107 if (status) {108 psTrace ("psModules.config", 3, "read recipes from symbolic references");109 } else {110 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference");111 }105 return false; 106 } 107 if (status) { 108 psTrace ("psModules.config", 3, "read recipes from symbolic references"); 109 } else { 110 psLogMsg ("psModules.config", PS_LOG_DETAIL, "no recipe supplied by symbolic reference"); 111 } 112 112 if (!loadRecipeOptions(&status, config)) { 113 113 psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references"); 114 return false;115 } 116 if (status) {114 return false; 115 } 116 if (status) { 117 117 psTrace ("psModules.config", 3, "read recipes from command-line arguments"); 118 118 } else { … … 135 135 options = psMetadataAlloc(); 136 136 success = psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "OPTIONS", PS_DATA_METADATA, "Command-line options specified with -D", options); 137 assert (success); // type mismatch : OPTIONS already defined but wrong type138 psFree (options); // drop extra reference137 assert (success); // type mismatch : OPTIONS already defined but wrong type 138 psFree (options); // drop extra reference 139 139 } 140 140 … … 176 176 recipe = psMetadataAlloc(); 177 177 success = psMetadataAddPtr(options, PS_LIST_TAIL, recipeName, PS_DATA_METADATA, "", recipe); 178 assert (success); // type mismatch : recipe already defined but wrong type179 psFree (recipe); // drop extra reference178 assert (success); // type mismatch : recipe already defined but wrong type 179 psFree (recipe); // drop extra reference 180 180 } 181 181 … … 216 216 bool pmConfigLoadRecipeArguments (int *argc, char **argv, pmConfig *config) 217 217 { 218 bool success; 218 bool success; 219 219 220 220 psMetadata *recipes = psMetadataLookupMetadata(&success, config->arguments, "RECIPES"); … … 222 222 recipes = psMetadataAlloc(); 223 223 success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPES", PS_DATA_METADATA, "", recipes); 224 assert (success);225 psFree (recipes);224 assert (success); 225 psFree (recipes); 226 226 } 227 227 … … 271 271 // Load the recipe files for SITE : REQUIRED 272 272 static bool loadRecipeSite(bool *status, 273 pmConfig *config, // The configuration into which to read the recipes274 psMetadata *source // The source configuration, from which to read the filenames273 pmConfig *config, // The configuration into which to read the recipes 274 psMetadata *source // The source configuration, from which to read the filenames 275 275 ) 276 276 { … … 300 300 if (fileItem->type != PS_DATA_STRING) { 301 301 psError(PS_ERR_IO, true, "%s in site configuration RECIPES is not of type STR", fileItem->name); 302 return false;302 return false; 303 303 } 304 304 305 305 // Read the recipe file. if we fail on a file, give a warning, but continue 306 306 psMetadata *recipe = NULL; 307 if (!pmConfigFileRead(&recipe, fileItem->data.V, "recipe")) { 308 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in site configuration\n", (char *)fileItem->data.V); 309 return false; 307 if (!pmConfigFileRead(&recipe, fileItem->data.str, "recipe")) { 308 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in site configuration\n", 309 fileItem->data.str); 310 return false; 310 311 } 311 312 312 313 // if this named recipe exists, supplement it 313 psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE,314 fileItem->comment, recipe);314 psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE, 315 fileItem->comment, recipe); 315 316 psFree(recipe); // Drop reference 316 317 } … … 326 327 // for sourceType == SITE | CAMERA, RECIPES contains a list of files to be read (pmConfigFileRead) 327 328 static bool loadRecipeCamera(bool *status, // status variable 328 pmConfig *config, // The configuration into which to read the recipes329 psMetadata *source // The source configuration, from which to read the filenames329 pmConfig *config, // The configuration into which to read the recipes 330 psMetadata *source // The source configuration, from which to read the filenames 330 331 ) 331 332 { … … 345 346 psMetadata *recipes = psMetadataLookupMetadata(&success, source, "RECIPES"); // The list of recipes 346 347 if (!recipes) { 347 psTrace ("psModules.config", 3, "RECIPES not found in the camera configuration\n");348 psTrace ("psModules.config", 3, "RECIPES not found in the camera configuration\n"); 348 349 return true; 349 350 } … … 355 356 psMetadataItem *fileItem = NULL; // MD item containing the filename, from recipe iteration 356 357 while ((fileItem = psMetadataGetAndIncrement(recipesIter))) { 357 char *recipeName = fileItem->name;358 char *recipeFile = fileItem->data.V;359 360 psTrace("psModules.config", 3, "Supplementing %s from %s within camera configuration.\n", recipeName, recipeFile);358 char *recipeName = fileItem->name; 359 char *recipeFile = fileItem->data.str; 360 361 psTrace("psModules.config", 3, "Supplementing %s from %s within camera configuration.\n", recipeName, recipeFile); 361 362 362 363 // type mismatch is a serious error … … 368 369 psMetadata *recipe = NULL; 369 370 if (!pmConfigFileRead(&recipe, recipeFile, "recipe")) { 370 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in camera configuration\n", recipeFile); 371 return false; 371 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in camera configuration\n", 372 recipeFile); 373 return false; 372 374 } 373 375 374 376 // the named recipe must exist; supplement it 375 psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, recipeName);376 if (!current) {377 psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", recipeName);378 psFree(recipe); // Drop reference379 return false;380 }381 382 if (!psMetadataUpdate(current, recipe)) {383 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);384 psFree(recipe); // Drop reference385 return false;386 }377 psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, recipeName); 378 if (!current) { 379 psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", recipeName); 380 psFree(recipe); // Drop reference 381 return false; 382 } 383 384 if (!psMetadataUpdate(current, recipe)) { 385 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName); 386 psFree(recipe); // Drop reference 387 return false; 388 } 387 389 psFree(recipe); // Drop reference 388 390 } … … 397 399 // entries for an existing recipe metadata 398 400 static bool loadRecipeFromArguments(bool *status, 399 pmConfig *config // The configuration into which to read the recipes401 pmConfig *config // The configuration into which to read the recipes 400 402 ) 401 403 { … … 425 427 // increment the ref counter to protect the data 426 428 427 psMetadata *recipe = item->data. V; // Recipe of interest429 psMetadata *recipe = item->data.md; // Recipe of interest 428 430 429 431 // if this named recipe exists, supplement it 430 432 psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, item->name); 431 433 if (!current) { 432 psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", item->name);433 psFree(recipe); // Drop reference434 return false;435 }436 psTrace("psModules.config", 3, "Supplementing %s from arguments.\n", item->name);434 psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", item->name); 435 psFree(recipe); // Drop reference 436 return false; 437 } 438 psTrace("psModules.config", 3, "Supplementing %s from arguments.\n", item->name); 437 439 438 440 if (!psMetadataUpdate (current, recipe)) { 439 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", item->name);440 return false;441 }441 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", item->name); 442 return false; 443 } 442 444 } 443 445 psFree(recipesIter); … … 449 451 // entries for an existing recipe metadata 450 452 static bool loadRecipeSymbols(bool *status, 451 pmConfig *config // The configuration into which to read the recipes453 pmConfig *config // The configuration into which to read the recipes 452 454 ) 453 455 { … … 465 467 while ((item = psMetadataGetAndIncrement(iter))) { 466 468 assert(item->type == PS_DATA_STRING); // It should be this type: we put it in ourselves 467 const char *sourceName = item->data. V; // The name of the symbolic reference469 const char *sourceName = item->data.str; // The name of the symbolic reference 468 470 const char *targetName = item->name; 469 psTrace("psModules.config", 3, "Supplementing %s from %s.\n", targetName, sourceName);470 471 // the target recipe must exist; select it472 psMetadata *targetMD = psMetadataLookupMetadata(&found, config->recipes, targetName);473 if (!targetMD) {474 psError(PS_ERR_IO, true, "Failed to find recipe for %s in master recipe list", targetName);475 return false;476 }471 psTrace("psModules.config", 3, "Supplementing %s from %s.\n", targetName, sourceName); 472 473 // the target recipe must exist; select it 474 psMetadata *targetMD = psMetadataLookupMetadata(&found, config->recipes, targetName); 475 if (!targetMD) { 476 psError(PS_ERR_IO, true, "Failed to find recipe for %s in master recipe list", targetName); 477 return false; 478 } 477 479 478 480 // search for sourceName : it may be in config->recipes or target MD 479 481 psMetadata *sourceMD = NULL; 480 sourceMD = psMetadataLookupMetadata(&found, config->recipes, sourceName);482 sourceMD = psMetadataLookupMetadata(&found, config->recipes, sourceName); 481 483 if (!sourceMD) { 482 sourceMD = psMetadataLookupMetadata(&found, targetMD, sourceName);483 if (!sourceMD) {484 psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName);485 return false;486 }487 }488 489 if (!psMetadataUpdate(targetMD, sourceMD)) {490 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", targetName);491 return false;492 }484 sourceMD = psMetadataLookupMetadata(&found, targetMD, sourceName); 485 if (!sourceMD) { 486 psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName); 487 return false; 488 } 489 } 490 491 if (!psMetadataUpdate(targetMD, sourceMD)) { 492 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", targetName); 493 return false; 494 } 493 495 } 494 496 psFree(iter); … … 501 503 // entries for an existing recipe metadata 502 504 static bool loadRecipeOptions(bool *status, 503 pmConfig *config // The configuration into which to read the recipes505 pmConfig *config // The configuration into which to read the recipes 504 506 ) 505 507 { … … 524 526 psMetadataItem *item = NULL; // MD item containing the filename, from recipe iteration 525 527 while ((item = psMetadataGetAndIncrement(recipesIter))) { 526 char *recipeName = item->name;527 psMetadata *recipe = item->data. V;528 char *recipeName = item->name; 529 psMetadata *recipe = item->data.md; 528 530 529 531 // type mismatch is a serious error … … 535 537 psMetadata *current = psMetadataLookupMetadata(NULL, config->recipes, recipeName); 536 538 if (!current) { 537 psError(PS_ERR_IO, false, "Selected recipe %s is not found in camera recipe", recipeName);538 return false;539 }539 psError(PS_ERR_IO, false, "Selected recipe %s is not found in camera recipe", recipeName); 540 return false; 541 } 540 542 if (!psMetadataUpdate (current, recipe)) { 541 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);542 return false;543 }543 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName); 544 return false; 545 } 544 546 } 545 547 psFree(recipesIter);
Note:
See TracChangeset
for help on using the changeset viewer.
