Changeset 7876
- Timestamp:
- Jul 12, 2006, 11:09:44 AM (20 years ago)
- Location:
- branches/rel12/psModules/src/config
- Files:
-
- 2 edited
-
pmConfig.c (modified) (23 diffs)
-
pmConfig.h (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/rel12/psModules/src/config/pmConfig.c
r7754 r7876 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $6 * @date $Date: 2006-0 6-29 20:39:56$5 * @version $Revision: 1.29.2.1 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-07-12 21:09:44 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 36 36 } 37 37 38 pmConfig *pmConfigAlloc(int argc, char **argv)38 pmConfig *pmConfigAlloc(int *argc, char **argv) 39 39 { 40 40 pmConfig *config = psAlloc(sizeof(pmConfig)); … … 47 47 config->recipesRead = P_PM_RECIPE_SOURCE_NONE; 48 48 config->recipesSource = psMetadataAlloc(); 49 config->arguments = NULL;49 config->arguments = psMetadataAlloc(); 50 50 config->database = NULL; 51 51 config->argc = argc; … … 171 171 *****************************************************************************/ 172 172 pmConfig *pmConfigRead( 173 int argc,173 int *argc, 174 174 char **argv) 175 175 { 176 PS_ASSERT_INT_POSITIVE(argc, false); 177 PS_ASSERT_PTR_NON_NULL(argv, false); 176 PS_ASSERT_PTR_NON_NULL(argc, NULL); 177 PS_ASSERT_INT_POSITIVE(*argc, NULL); 178 PS_ASSERT_PTR_NON_NULL(argv, NULL); 178 179 179 180 pmConfig *config = pmConfigAlloc(argc, argv); // The configuration, containing site, camera and recipes … … 188 189 // First, try command line 189 190 // 190 psS32 argNum = psArgumentGet( config->argc, config->argv, "-site");191 psS32 argNum = psArgumentGet(*config->argc, config->argv, "-site"); 191 192 if (argNum != 0) { 192 193 // … … 195 196 // remove it as well. 196 197 // 197 psArgumentRemove(argNum, &config->argc, config->argv);198 if (argNum >= config->argc) {198 psArgumentRemove(argNum, config->argc, config->argv); 199 if (argNum >= *config->argc) { 199 200 psLogMsg(__func__, PS_LOG_WARN, 200 201 "-site command-line switch provided without the required filename --- ignored.\n"); 201 202 } else { 202 203 siteName = psStringCopy(config->argv[argNum]); 203 psArgumentRemove(argNum, &config->argc, config->argv);204 psArgumentRemove(argNum, config->argc, config->argv); 204 205 } 205 206 } … … 255 256 // file is read and parsed into psMetadata struct "camera". 256 257 // 257 argNum = psArgumentGet( config->argc, config->argv, "-camera");258 argNum = psArgumentGet(*config->argc, config->argv, "-camera"); 258 259 if (argNum > 0) { 259 psArgumentRemove(argNum, &config->argc, config->argv);260 if (argNum >= config->argc) {260 psArgumentRemove(argNum, config->argc, config->argv); 261 if (argNum >= *config->argc) { 261 262 psLogMsg(__func__, PS_LOG_WARN, 262 263 "-camera command-line switch provided without the required camera or filename --- " … … 282 283 283 284 readConfig(&config->camera, cameraFile, "camera"); 284 psArgumentRemove(argNum, &config->argc, config->argv);285 psArgumentRemove(argNum, config->argc, config->argv); 285 286 } 286 287 } … … 330 331 331 332 332 argNum = psArgumentGet( config->argc, config->argv, "-log");333 argNum = psArgumentGet(*config->argc, config->argv, "-log"); 333 334 if (argNum > 0) { 334 psArgumentRemove(argNum, &config->argc, config->argv);335 if (argNum >= config->argc) {335 psArgumentRemove(argNum, config->argc, config->argv); 336 if (argNum >= *config->argc) { 336 337 psLogMsg(__func__, PS_LOG_WARN, 337 338 "-log command-line switch provided without the required log destination --- ignored.\n"); … … 341 342 config->argv[argNum]); 342 343 } 343 psArgumentRemove(argNum, &config->argc, config->argv);344 psArgumentRemove(argNum, config->argc, config->argv); 344 345 } 345 346 } else { … … 388 389 // 389 390 psS32 saveLogLevel = psLogGetLevel(); 390 psArgumentVerbosity( &config->argc, config->argv);391 psArgumentVerbosity(config->argc, config->argv); 391 392 // XXX: substitute the string for the default log level for "2". 392 393 if (2 == psLogGetLevel()) { … … 666 667 config->recipesRead |= sourceType; 667 668 669 // Having read that, we now need to check to see if any symbolic links need to be resolved 670 recipesIter = psMetadataIteratorAlloc(config->recipesSource, PS_LIST_HEAD, NULL); 671 psMetadataItem *sourceItem = NULL; // Item containing source, from iteration 672 while ((sourceItem = psMetadataGetAndIncrement(recipesIter))) { 673 assert(sourceItem->type == PS_TYPE_S32); // It should be this type: we put it in ourselves 674 if (sourceItem->data.S32 == P_PM_RECIPE_SOURCE_SYMBOLIC) { 675 const char *linkName = sourceItem->comment; // The name of the link 676 psMetadata *linkSource = psMetadataLookupMD(&mdok, config->recipes, linkName); // The source 677 if (!mdok || !linkSource) { 678 psLogMsg(__func__, PS_LOG_WARN, "Unable to resolve symbolic link for recipe %s to %s " 679 "--- ignored.\n", sourceItem->name, linkName); 680 continue; 681 } 682 psMetadataItem *target = psMetadataLookup(config->recipes, sourceItem->name); // The target item 683 assert(target); // It had better be here: it's in the "sourcesRead" metadata 684 psFree(target->data.V); // Free old copy 685 target->data.V = psMetadataCopy(NULL, linkSource); 686 } 687 } 688 psFree(recipesIter); 668 689 return true; 669 690 } … … 691 712 // Go through the command-line arguments 692 713 int argNum; // Argument number for "-recipe" 693 while ((argNum = psArgumentGet( config->argc, config->argv, "-recipe")) > 0) {694 psArgumentRemove(argNum, &config->argc, config->argv);695 if (argNum + 1 >= config->argc) {714 while ((argNum = psArgumentGet(*config->argc, config->argv, "-recipe")) > 0) { 715 psArgumentRemove(argNum, config->argc, config->argv); 716 if (argNum + 1 >= *config->argc) { 696 717 psLogMsg(__func__, PS_LOG_WARN, "-recipe command-line switch provided without the " 697 718 "required recipe and source --- ignored.\n"); 698 if (argNum == config->argc) {719 if (argNum == *config->argc) { 699 720 // Remove the single last argument (we required two, they gave us one) 700 psArgumentRemove(argNum, &config->argc, config->argv);721 psArgumentRemove(argNum, config->argc, config->argv); 701 722 } 702 723 continue; … … 704 725 705 726 const char *recipeName = psStringCopy(config->argv[argNum]); // Name of the recipe 706 psArgumentRemove(argNum, &config->argc, config->argv);727 psArgumentRemove(argNum, config->argc, config->argv); 707 728 const char *recipeSource = psStringCopy(config->argv[argNum]); // Source of the recipe 708 psArgumentRemove(argNum, &config->argc, config->argv);729 psArgumentRemove(argNum, config->argc, config->argv); 709 730 710 731 // Command-line has the highest priority, so we don't have to check to see if it's already there 711 psMetadataAddS32(config->recipesSource, PS_LIST_TAIL, recipeName, PS_META_REPLACE,712 "Recipe added from command line", P_PM_RECIPE_SOURCE_CL);713 732 714 733 // Is the source a symbolic reference? … … 720 739 comment, extant); 721 740 psFree(comment); 741 // Put the source in the comment, so we can retrieve it again if we need it 742 psMetadataAddS32(config->recipesSource, PS_LIST_TAIL, recipeName, PS_META_REPLACE, 743 recipeSource, P_PM_RECIPE_SOURCE_SYMBOLIC); 744 722 745 } else { 723 746 // Otherwise, treat the source as a filename … … 730 753 psFree(comment); 731 754 psFree(recipe); // Drop reference 755 psMetadataAddS32(config->recipesSource, PS_LIST_TAIL, recipeName, PS_META_REPLACE, 756 "Recipe added from command line", P_PM_RECIPE_SOURCE_CL); 732 757 } 733 758 } … … 810 835 psArray *pmConfigFileSets(pmConfig *config, char *file, char *list) 811 836 { 812 PS_ASSERT_INT_NONNEGATIVE(config->argc, NULL);813 837 PS_ASSERT_PTR_NON_NULL(config, NULL); 838 PS_ASSERT_PTR_NON_NULL(config->argc, NULL); 839 PS_ASSERT_INT_NONNEGATIVE(*config->argc, NULL); 814 840 PS_ASSERT_PTR_NON_NULL(config->argv, NULL); 815 841 PS_ASSERT_PTR_NON_NULL(file, NULL); … … 827 853 // maybe a comma-separated list of words 828 854 // each word may be a glob: "file*.fits" 829 if ((Narg = psArgumentGet ( config->argc, config->argv, file))) {855 if ((Narg = psArgumentGet (*config->argc, config->argv, file))) { 830 856 831 857 // select the word after 'file' and split by comma 832 psArgumentRemove (Narg, &config->argc, config->argv);858 psArgumentRemove (Narg, config->argc, config->argv); 833 859 psArray *words = psStringSplitArray (config->argv[Narg], ",", true); 834 psArgumentRemove (Narg, &config->argc, config->argv);860 psArgumentRemove (Narg, config->argc, config->argv); 835 861 836 862 // parse the word as a glob … … 855 881 856 882 // load the list from the supplied text file 857 if ((Narg = psArgumentGet ( config->argc, config->argv, list))) {883 if ((Narg = psArgumentGet (*config->argc, config->argv, list))) { 858 884 int nItems; 859 885 char line[1024]; // XXX limits the list lines to 1024 chars … … 861 887 char *filename; 862 888 863 psArgumentRemove (Narg, &config->argc, config->argv);889 psArgumentRemove (Narg, config->argc, config->argv); 864 890 FILE *f = fopen (config->argv[Narg], "r"); 865 891 if (f == NULL) { … … 882 908 } 883 909 } 884 psArgumentRemove (Narg, &config->argc, config->argv);910 psArgumentRemove (Narg, config->argc, config->argv); 885 911 } 886 912 … … 891 917 { 892 918 PS_ASSERT_PTR_NON_NULL(metadata, false); 893 PS_ASSERT_PTR_NON_NULL(config, NULL); 894 PS_ASSERT_INT_NONNEGATIVE(config->argc, NULL); 895 PS_ASSERT_PTR_NON_NULL(config->argv, false); 919 PS_ASSERT_PTR_NON_NULL(config, false); 896 920 PS_ASSERT_PTR_NON_NULL(name, false); 897 PS_ASSERT_INT_POSITIVE(strlen(name), NULL);921 PS_ASSERT_INT_POSITIVE(strlen(name), false); 898 922 PS_ASSERT_PTR_NON_NULL(file, false); 899 PS_ASSERT_INT_POSITIVE(strlen(file), NULL);923 PS_ASSERT_INT_POSITIVE(strlen(file), false); 900 924 PS_ASSERT_PTR_NON_NULL(list, false); 901 PS_ASSERT_INT_POSITIVE(strlen(list), NULL);925 PS_ASSERT_INT_POSITIVE(strlen(list), false); 902 926 903 927 psErrorClear(); // pmConfigFileSets may or may not call psError, so … … 910 934 } 911 935 912 psMetadataAddPtr (metadata, PS_LIST_TAIL, name, PS_DATA_ARRAY, "", files);936 psMetadataAddPtr(metadata, PS_LIST_TAIL, name, PS_DATA_ARRAY, "", files); 913 937 psFree (files); 914 938 return true; -
branches/rel12/psModules/src/config/pmConfig.h
r7709 r7876 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $6 * @date $Date: 2006-0 6-28 00:49:13$5 * @version $Revision: 1.11.2.1 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-07-12 21:09:44 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 16 16 // What recipe sources have been read so far? 17 17 typedef enum { 18 P_PM_RECIPE_SOURCE_NONE = 0x00, // None yet 19 P_PM_RECIPE_SOURCE_SITE = 0x01, // Site configuration 20 P_PM_RECIPE_SOURCE_CAMERA = 0x02, // Camera configuration 21 P_PM_RECIPE_SOURCE_CL = 0x04, // Command-line 22 P_PM_RECIPE_SOURCE_ALL = 0x07 // All sources 18 P_PM_RECIPE_SOURCE_NONE = 0x00, // None yet 19 P_PM_RECIPE_SOURCE_SITE = 0x01, // Site configuration 20 P_PM_RECIPE_SOURCE_CAMERA = 0x02, // Camera configuration 21 P_PM_RECIPE_SOURCE_CL = 0x04, // Command-line 22 P_PM_RECIPE_SOURCE_SYMBOLIC = 0x14, // Symbolic link, specified on command-line 23 P_PM_RECIPE_SOURCE_ALL = 0xff // All sources 23 24 } p_pmRecipeSource; 24 25 … … 32 33 psMetadata *files; // pmFPAfiles used for analysis 33 34 psDB *database; // Database handle 34 int argc;// Number of command-line arguments35 int *argc; // Number of command-line arguments 35 36 char **argv; // Command-line arguments (raw version) 36 37 // Private members … … 40 41 pmConfig; 41 42 42 pmConfig *pmConfigAlloc(int argc,// Number of command-line arguments43 pmConfig *pmConfigAlloc(int *argc, // Number of command-line arguments 43 44 char **argv // Command-line arguments 44 45 ); … … 66 67 */ 67 68 pmConfig *pmConfigRead( 68 int argc,69 int *argc, 69 70 char **argv); 70 71
Note:
See TracChangeset
for help on using the changeset viewer.
