Changeset 18908 for trunk/psModules/src/config/pmConfigRecipes.c
- Timestamp:
- Aug 4, 2008, 5:45:56 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfigRecipes.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfigRecipes.c
r17512 r18908 28 28 if (!options) { 29 29 options = psMetadataAlloc (); 30 success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "OPTIONS", PS_DATA_METADATA, "", options); 30 success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "OPTIONS", PS_DATA_METADATA, "", 31 options); 31 32 assert (success); // type mismatch : OPTIONS already defined but wrong type 32 33 psFree (options); // drop extra reference … … 47 48 48 49 // this function may be called several times. it attempts to load the recipe data from one of three 49 // locations: config-> complete, config->camera, and argv. We cannot read the recipes from50 // locations: config->system, config->camera, and argv. We cannot read the recipes from 50 51 // config->camera until a camera has been read BUT, the argv recipes must override the camera and 51 52 // system recipes. This command strips the argv elements it uses from the argv list. … … 60 61 61 62 // Read the recipe file names from the system configuration and camera configuration 62 // It is an error for config-> complete:recipes not to exist. all programs install their63 // It is an error for config->system:recipes not to exist. all programs install their 63 64 // master recipe files in the system:recipe location when they are built. 64 psAssert (config->complete, "base config data defined");65 psAssert(config->system, "base config data defined"); 65 66 if (source & PM_RECIPE_SOURCE_SYSTEM) { 66 if (!loadRecipeSystem(&status, config, config-> complete)) {67 if (!loadRecipeSystem(&status, config, config->system)) { 67 68 psError(PS_ERR_IO, false, "Failed to read recipes from system config"); 68 69 return false; … … 75 76 // for an identified camera (in pmConfigCameraFormatFromHeader). the second 76 77 // set should not override the first set 77 if (config->camera && (source & PM_RECIPE_SOURCE_CAMERA) && !(config->recipesRead & PM_RECIPE_SOURCE_CAMERA)) { 78 if (config->camera && (source & PM_RECIPE_SOURCE_CAMERA) && 79 !(config->recipesRead & PM_RECIPE_SOURCE_CAMERA)) { 78 80 if (!loadRecipeCamera(&status, config, config->camera)) { 79 81 psError(PS_ERR_IO, false, "Failed to read recipes from camera config"); … … 87 89 } 88 90 89 // merge camera and sytem recipes, apply recipes loaded into config->arguments based on command-line arguments 91 // merge camera and sytem recipes, apply recipes loaded into config->arguments based on command-line 92 // arguments 90 93 if (config->arguments && (source & PM_RECIPE_SOURCE_CL)) { 91 94 92 // update the system-level recipes with the symbolically-defined recipes 95 // update the system-level recipes with the symbolically-defined recipes 93 96 if (!loadRecipeSymbols(&status, config, PM_RECIPE_SOURCE_SYSTEM)) { 94 97 psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references"); … … 101 104 } 102 105 103 // merge the SYSTEM and CAMERA recipes106 // merge the SYSTEM and CAMERA recipes 104 107 if (!mergeRecipeCamera(&status, config)) { 105 108 psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references"); 106 109 return false; 107 110 } 108 psLogMsg ("psModules.config", PS_LOG_DETAIL, "merged camera recipes with system recipes");109 110 // load recipe-files specified on the command line111 psLogMsg ("psModules.config", PS_LOG_DETAIL, "merged camera recipes with system recipes"); 112 113 // load recipe-files specified on the command line 111 114 if (!loadRecipeFromArguments(&status, config)) { 112 115 psError(PS_ERR_IO, false, "Failed to read recipes from command-line arguments"); … … 119 122 } 120 123 121 // update the system-level recipes with the symbolically-defined recipes 124 // update the system-level recipes with the symbolically-defined recipes 122 125 if (!loadRecipeSymbols(&status, config, PM_RECIPE_SOURCE_CAMERA)) { 123 126 psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references"); … … 130 133 } 131 134 132 // override any specific values with values from the command line135 // override any specific values with values from the command line 133 136 if (!loadRecipeOptions(&status, config)) { 134 137 psError(PS_ERR_IO, false, "Failed to read recipes from symbolic references"); … … 155 158 if (!options) { 156 159 options = psMetadataAlloc(); 157 success = psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "OPTIONS", PS_DATA_METADATA, "Command-line options specified with -D", options); 160 success = psMetadataAddPtr(config->arguments, PS_LIST_TAIL, "OPTIONS", PS_DATA_METADATA, 161 "Command-line options specified with -D", options); 158 162 assert (success); // type mismatch : OPTIONS already defined but wrong type 159 163 psFree (options); // drop extra reference … … 178 182 recipeName = config->defaultRecipe; 179 183 if (!config->defaultRecipe) { 180 psError(PS_ERR_IO, true, "syntax error in parameter: no default recipe available; must specify recipe"); 184 psError(PS_ERR_IO, true, 185 "syntax error in parameter: no default recipe available; must specify recipe"); 181 186 return false; 182 187 } … … 242 247 if (!recipes) { 243 248 recipes = psMetadataAlloc(); 244 success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPES", PS_DATA_METADATA, "", recipes); 249 success = psMetadataAddPtr (config->arguments, PS_LIST_TAIL, "RECIPES", PS_DATA_METADATA, "", 250 recipes); 245 251 assert (success); 246 252 psFree (recipes); … … 298 304 // Assume it's a symbolic reference to something that's not yet read in. 299 305 // it will be loaded later by pmConfigReadRecipes with option CL 300 psMetadataAddStr(config->recipeSymbols, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, recipeSource); 306 psMetadataAddStr(config->recipeSymbols, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, 307 recipeSource); 301 308 302 309 psTrace ("psModules.config", 3, "read recipe %s from %s", recipeName, recipeSource); … … 319 326 320 327 if (!source) { 321 psError(PS_ERR_IO, true, "The system configuration has not been read --- cannot read recipes from this location.\n"); 328 psError(PS_ERR_IO, true, 329 "The system configuration has not been read --- cannot read recipes from this location.\n"); 322 330 config->recipesRead &= ~PM_RECIPE_SOURCE_SYSTEM; 323 331 return false; … … 334 342 // If it's not of the correct type, we can tell the user which file it's in, so they can find it easier. 335 343 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(recipes, PS_LIST_HEAD, NULL); // Iterator 336 psMetadataItem *fileItem = NULL; // MD item containing the filename, from recipe iteration 337 while ((fileItem = psMetadataGetAndIncrement(recipesIter))) { 338 char *recipeName = fileItem->name; 339 char *recipeFile = fileItem->data.str; 340 341 // type mismatch is a serious error 342 if (fileItem->type != PS_DATA_STRING) { 343 psAbort("%s in system configuration RECIPES is not of type STR", recipeName); 344 } 345 346 // Read the recipe file. if we fail on a file, give a warning, but continue 347 psMetadata *recipe = NULL; 348 if (!pmConfigFileRead(&recipe, recipeFile, "recipe")) { 349 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in system configuration\n", recipeFile); 350 return false; 351 } 352 353 // and the contents of this recipe file to config->recipes 354 psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, recipe); 355 psFree(recipe); // Drop reference 344 psMetadataItem *item = NULL; // MD item containing the filename, from recipe iteration 345 while ((item = psMetadataGetAndIncrement(recipesIter))) { 346 if (!pmConfigFileIngest(item, "recipe")) { 347 psError(PS_ERR_IO, false, "Failed to read recipe %s listed in system configuration", 348 item->name); 349 psFree(recipesIter); 350 return false; 351 } 352 353 // add the contents of this recipe file to config->recipes 354 psMetadataAdd(config->recipes, PS_LIST_TAIL, item->name, PS_DATA_METADATA | PS_META_REPLACE, 355 item->comment, item->data.md); 356 356 } 357 357 psFree(recipesIter); … … 375 375 376 376 if (!source) { 377 psError(PS_ERR_IO, true, "The camera configuration has not been read --- cannot read recipes from this location.\n"); 377 psError(PS_ERR_IO, true, 378 "The camera configuration has not been read --- cannot read recipes from this location.\n"); 378 379 config->recipesRead &= ~PM_RECIPE_SOURCE_CAMERA; 379 380 return false; … … 392 393 // If it's not of the correct type, we can tell the user which file it's in, so they can find it easier. 393 394 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(recipes, PS_LIST_HEAD, NULL); // Iterator 394 psMetadataItem *fileItem = NULL; // MD item containing the filename, from recipe iteration 395 while ((fileItem = psMetadataGetAndIncrement(recipesIter))) { 396 char *recipeName = fileItem->name; 397 char *recipeFile = fileItem->data.str; 398 399 psTrace("psModules.config", 3, "loading %s from %s within camera configuration.\n", recipeName, recipeFile); 400 401 // type mismatch is a serious error 402 if (fileItem->type != PS_DATA_STRING) { 403 psAbort("%s in camera configuration RECIPES is not of type STR", recipeName); 404 } 405 406 // Read the recipe file. if we fail on a file, give a warning, but continue 407 psMetadata *recipe = NULL; 408 if (!pmConfigFileRead(&recipe, recipeFile, "recipe")) { 409 psError(PS_ERR_IO, false, "Failed to read recipe file %s listed in camera configuration\n", recipeFile); 410 return false; 411 } 395 psMetadataItem *item = NULL; // MD item containing the filename, from recipe iteration 396 while ((item = psMetadataGetAndIncrement(recipesIter))) { 397 if (!pmConfigFileIngest(item, "recipe")) { 398 psError(PS_ERR_IO, false, "Failed to read recipe %s listed in camera configuration", 399 item->name); 400 return false; 401 } 402 const char *recipeName = item->name; // Name of the recipe 403 psMetadata *recipe = item->data.md; // The recipe 412 404 413 405 // the named recipe must exist at the system level … … 415 407 if (!current) { 416 408 psError(PS_ERR_IO, false, "Failed to find recipe for %s in master recipe list", recipeName); 417 psFree(recipe); // Drop reference418 409 return false; 419 410 } 420 411 421 412 // add the contents of this recipe file to config->recipesCamera 422 psMetadataAdd(config->recipesCamera, PS_LIST_TAIL, recipeName, PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, recipe);423 psFree(recipe); // Drop reference413 psMetadataAdd(config->recipesCamera, PS_LIST_TAIL, recipeName, PS_DATA_METADATA | PS_META_REPLACE, 414 item->comment, recipe); 424 415 } 425 416 psFree(recipesIter); … … 441 432 // We could use psMetadataCopy for this, but it's better to check that everything's of the correct type. 442 433 // If it's not of the correct type, we can tell the user which file it's in, so they can find it easier. 443 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(config->recipesCamera, PS_LIST_HEAD, NULL); // Iterator434 psMetadataIterator *recipesIter = psMetadataIteratorAlloc(config->recipesCamera, PS_LIST_HEAD, NULL); 444 435 psMetadataItem *folderItem = NULL; // MD item containing the filename, from recipe iteration 445 436 while ((folderItem = psMetadataGetAndIncrement(recipesIter))) { … … 459 450 460 451 // update the contents of this recipe from the one on config->recipesCamera 461 if (!psMetadataUpdate(current, recipe)) {462 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName);463 return false;464 }452 if (!psMetadataUpdate(current, recipe)) { 453 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", recipeName); 454 return false; 455 } 465 456 } 466 457 psFree(recipesIter); … … 552 543 553 544 // search for sourceName in config->recipes (folder name is targetName) 554 psMetadata *folder = psMetadataLookupMetadata(&found, config->recipes, targetName);555 psMetadata *sourceMD = psMetadataLookupMetadata(&found, folder, sourceName);556 557 // if we find the desired symbolic name at this level, set the item comment to say "FOUND"545 psMetadata *folder = psMetadataLookupMetadata(&found, config->recipes, targetName); 546 psMetadata *sourceMD = psMetadataLookupMetadata(&found, folder, sourceName); 547 548 // if we find the desired symbolic name at this level, set the item comment to say "FOUND" 558 549 if (sourceMD) { 559 if (!psMetadataUpdate(targetMD, sourceMD)) {550 if (!psMetadataUpdate(targetMD, sourceMD)) { 560 551 psError(PS_ERR_IO, false, "Failed to update recipe for %s from camera recipe", targetName); 561 552 return false; 562 }563 psStringAppend (&item->comment, "(FOUND)");564 } 565 566 // if we have not found it by the camera level, we have a problem567 if (source == PM_RECIPE_SOURCE_CAMERA) {568 if (strstr (item->comment, "(FOUND)") == NULL) {569 psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName);570 return false;571 }572 }553 } 554 psStringAppend (&item->comment, "(FOUND)"); 555 } 556 557 // if we have not found it by the camera level, we have a problem 558 if (source == PM_RECIPE_SOURCE_CAMERA) { 559 if (strstr (item->comment, "(FOUND)") == NULL) { 560 psError(PS_ERR_IO, false, "Selected symbolic name %s does not exist in recipes", sourceName); 561 return false; 562 } 563 } 573 564 } 574 565 psFree(iter); … … 594 585 } 595 586 596 psMetadata *recipes = psMetadataLookupMetadata(&found, config->arguments, "OPTIONS"); // The list of recipes587 psMetadata *recipes = psMetadataLookupMetadata(&found, config->arguments, "OPTIONS"); // List of recipes 597 588 if (!recipes) { 598 589 psTrace("psModules.config", 4, "no OPTIONS in config->arguments, nothing to read here");
Note:
See TracChangeset
for help on using the changeset viewer.
