Changeset 23719 for branches/pap/ppSub/src/ppSubArguments.c
- Timestamp:
- Apr 6, 2009, 6:52:51 PM (17 years ago)
- Location:
- branches/pap/ppSub/src
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ppSubArguments.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/ppSub/src
- Property svn:ignore
-
old new 10 10 stamp-h1 11 11 ppSubKernel 12 ppSubErrorCodes.h 13 ppSubErrorCodes.c
-
- Property svn:ignore
-
branches/pap/ppSub/src/ppSubArguments.c
r23704 r23719 39 39 psLibFinalize(); 40 40 exit(PS_EXIT_CONFIG_ERROR); 41 }42 43 // Get a float-point value from the command-line or recipe, and add it to the arguments44 #define VALUE_ARG_RECIPE_FLOAT(ARGNAME, RECIPENAME, TYPE) { \45 ps##TYPE value = psMetadataLookup##TYPE(NULL, config->arguments, ARGNAME); \46 if (isnan(value)) { \47 bool mdok; \48 value = psMetadataLookup##TYPE(&mdok, recipe, RECIPENAME); \49 if (!mdok) { \50 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find %s in recipe %s", \51 RECIPENAME, PPSUB_RECIPE); \52 goto ERROR; \53 } \54 } \55 psMetadataAdd##TYPE(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \56 }57 58 // Get an integer value from the command-line or recipe, and add it to the arguments59 #define VALUE_ARG_RECIPE_INT(ARGNAME, RECIPENAME, TYPE, UNSET) { \60 ps##TYPE value = psMetadataLookup##TYPE(NULL, config->arguments, ARGNAME); \61 if (value == UNSET) { \62 bool mdok; \63 value = psMetadataLookup##TYPE(&mdok, recipe, RECIPENAME); \64 if (!mdok) { \65 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find %s in recipe %s", \66 RECIPENAME, PPSUB_RECIPE); \67 goto ERROR; \68 } \69 } \70 psMetadataAdd##TYPE(recipe, PS_LIST_TAIL, RECIPENAME, PS_META_REPLACE, NULL, value); \71 }72 73 /**74 * Get a string value from the command-line and add it to the target75 */76 static bool valueArgStr(psMetadata *arguments, // Command-line arguments77 const char *argName, // Argument name in the command-line arguments78 const char *mdName, // Name for value in the metadata79 psMetadata *target // Target metadata to which to add value80 )81 {82 psString value = psMetadataLookupStr(NULL, arguments, argName); // Value of interest83 if (value && strlen(value) > 0) {84 return psMetadataAddStr(target, PS_LIST_TAIL, mdName, PS_META_REPLACE, NULL, value);85 }86 return false;87 }88 89 /**90 * Get a string value from the command-line or recipe and add it to the target91 */92 static bool valueArgRecipeStr(psMetadata *arguments, // Command-line arguments93 psMetadata *recipe, // Recipe94 const char *argName, // Argument name in the command-line arguments95 const char *mdName, // Name for value in the metadata and recipe96 psMetadata *target // Target metadata to which to add value97 )98 {99 bool mdok; // Status of MD lookup100 psString value = psMetadataLookupStr(&mdok, arguments, argName); // Value of interest101 if (!value) {102 value = psMetadataLookupStr(&mdok, recipe, mdName);103 if (!value) {104 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find %s in recipe %s",105 mdName, PPSUB_RECIPE);106 return false;107 }108 }109 return psMetadataAddStr(target, PS_LIST_TAIL, mdName, PS_META_REPLACE, NULL, value);110 }111 112 /**113 * Get a vector from the command-line or recipe, and add it to the target114 */115 static bool vectorArgRecipe(psMetadata *arguments, // Command-line arguments116 const char *argName, // Argument name in the command-line arguments117 const psMetadata *recipe, // Recipe118 const char *recipeName, // Name for value in the recipe119 psMetadata *target, // Target to which to add value120 psElemType type // Type for vector121 )122 {123 psVector *vector; // Vector124 psString string = psMetadataLookupStr(NULL, arguments, argName); // String from arguments125 if (string) {126 psArray *array = psStringSplitArray(string, ", ", false); // Array of strings127 vector = psVectorAlloc(array->n, type);128 for (int i = 0; i < array->n; i++) {129 const char *subString = array->data[i]; // String with a value130 char *end; // Ptr to end of string parsed131 132 switch (type) {133 case PS_TYPE_F32:134 vector->data.F32[i] = strtof(subString, &end);135 break;136 case PS_TYPE_S32: {137 long value = strtol(subString, &end, 10);138 if (value > PS_MAX_S32 || value < PS_MIN_S32) {139 psError(PS_ERR_BAD_PARAMETER_VALUE, true,140 "%s list includes value beyond S32 representation: %s",141 argName, string);142 psFree(vector);143 return false;144 }145 vector->data.S32[i] = value;146 break;147 }148 default:149 psAbort("Unsupported type: %x\n", type);150 }151 if (end == subString) {152 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to decipher %s list: %s",153 argName, string);154 psFree(vector);155 return false;156 }157 }158 psFree(array);159 } else {160 vector = psMetadataLookupPtr(NULL, recipe, recipeName);161 if (!psMemCheckVector(vector) || vector->type.type != type) {162 psError(PS_ERR_BAD_PARAMETER_TYPE, false, "%s in recipe %s is not a vector of type F32.",163 recipeName, PPSUB_RECIPE);164 return false;165 }166 psMemIncrRefCounter(vector);167 }168 169 psMetadataAddVector(target, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL, vector);170 psFree(vector); // Drop reference171 172 return true;173 41 } 174 42 … … 255 123 } 256 124 257 data->stamps = psMe tadataLookupStr(NULL, arguments, "-stamps");125 data->stamps = psMemIncrRefCounter(psMetadataLookupStr(NULL, arguments, "-stamps")); 258 126 259 127 const char *statsName = psMetadataLookupStr(NULL, arguments, "-stats"); // Filename for statistics … … 281 149 } 282 150 283 return true;284 }285 286 287 288 151 psTrace("ppSub", 1, "Done reading command-line arguments\n"); 289 152
Note:
See TracChangeset
for help on using the changeset viewer.
