Changeset 15727 for trunk/psModules/src/config/pmConfigRecipes.c
- Timestamp:
- Nov 30, 2007, 1:43:49 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfigRecipes.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfigRecipes.c
r15513 r15727 6 6 #include <string.h> 7 7 #include <strings.h> /* for strn?casecmp */ 8 #include <unistd.h>9 #include <libgen.h>10 8 #include <assert.h> 11 #include <sys/types.h>12 #include <sys/stat.h>13 #include <glob.h>14 9 #include <pslib.h> 15 10 #include "pmConfig.h" … … 227 222 228 223 // Go through the command-line arguments 229 int argNum; // Argument number for "-recipe" 224 int argNum; // Argument number 225 226 // -recipe-file: read recipe from file 227 while ((argNum = psArgumentGet(*argc, argv, "-recipe-file")) > 0) { 228 psArgumentRemove(argNum, argc, argv); 229 if (argNum + 1 >= *argc) { 230 psError(PS_ERR_IO, false, 231 "-recipe command-line switch provided without the required recipe and filename\n"); 232 return false; 233 } 234 235 psString recipeName = psStringCopy(argv[argNum]); // Name of the recipe 236 psArgumentRemove(argNum, argc, argv); 237 psString filename = psStringCopy(argv[argNum]); // Filename for the recipe 238 psArgumentRemove(argNum, argc, argv); 239 240 psMetadata *recipe = NULL; // Recipe from file 241 if (!pmConfigFileRead(&recipe, filename, "recipe")) { 242 psError(PS_ERR_IO, "Error reading config file %s\n", filename); 243 psFree(recipeName); 244 psFree(filename); 245 return false; 246 } 247 248 psString comment = NULL; 249 psStringAppend(&comment, "Recipe added at command line from file %s", filename); 250 psMetadataAdd(recipes, PS_LIST_TAIL, recipeName, PS_DATA_METADATA | PS_META_REPLACE, 251 comment, recipe); 252 psFree(comment); 253 psFree(recipe); // Drop reference 254 psFree(recipeName); 255 psFree(filename); 256 } 257 258 // -recipe: read recipe from symbolic link 230 259 while ((argNum = psArgumentGet(*argc, argv, "-recipe")) > 0) { 231 260 psArgumentRemove(argNum, argc, argv); 232 261 if (argNum + 1 >= *argc) { 233 psError(PS_ERR_IO, false, "-recipe command-line switch provided without the required recipe and source\n"); 262 psError(PS_ERR_IO, false, 263 "-recipe command-line switch provided without the required recipe and source\n"); 234 264 return false; 235 265 } … … 240 270 psArgumentRemove(argNum, argc, argv); 241 271 242 if (access(recipeSource, R_OK) == 0) { 243 // The source is a file: load onto config->arguments 244 // save the recipes onto config->arguments:RECIPES 245 246 psMetadata *recipe = NULL; // Recipe from file 247 if (pmConfigFileRead(&recipe, recipeSource, "recipe")) { 248 psString comment = psStringCopy("Recipe added at command line from "); 249 psStringAppend(&comment, "%s", recipeSource); 250 psMetadataAdd(recipes, PS_LIST_TAIL, recipeName, PS_DATA_METADATA | PS_META_REPLACE, 251 comment, recipe); 252 psFree(comment); 253 psFree(recipe); // Drop reference 254 } else { 255 psAbort("error reading config file %s\n", recipeSource); 256 } 257 } else { 258 // Assume it's a symbolic reference to something that's not yet read in. 259 // it will be loaded later by pmConfigReadRecipes with option CL 260 psMetadataAddStr(config->recipeSymbols, PS_LIST_TAIL, recipeName, PS_META_REPLACE, "", 261 recipeSource); 262 } 272 // Assume it's a symbolic reference to something that's not yet read in. 273 // it will be loaded later by pmConfigReadRecipes with option CL 274 psMetadataAddStr(config->recipeSymbols, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, 275 recipeSource); 276 263 277 psTrace ("psModules.config", 3, "read recipe %s from %s", recipeName, recipeSource); 264 278 psFree(recipeName); 265 279 psFree(recipeSource); 266 } // Iterating through the command-line arguments280 } 267 281 268 282 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
