IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 12, 2006, 11:09:44 AM (20 years ago)
Author:
jhoblitt
Message:

sync rel12 branch with head to get the reverted pmConfigAlloc() & pmConfigRead() APIs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel12/psModules/src/config/pmConfig.c

    r7754 r7876  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-06-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 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3636}
    3737
    38 pmConfig *pmConfigAlloc(int argc, char **argv)
     38pmConfig *pmConfigAlloc(int *argc, char **argv)
    3939{
    4040    pmConfig *config = psAlloc(sizeof(pmConfig));
     
    4747    config->recipesRead = P_PM_RECIPE_SOURCE_NONE;
    4848    config->recipesSource = psMetadataAlloc();
    49     config->arguments = NULL;
     49    config->arguments = psMetadataAlloc();
    5050    config->database = NULL;
    5151    config->argc = argc;
     
    171171 *****************************************************************************/
    172172pmConfig *pmConfigRead(
    173     int argc,
     173    int *argc,
    174174    char **argv)
    175175{
    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);
    178179
    179180    pmConfig *config = pmConfigAlloc(argc, argv); // The configuration, containing site, camera and recipes
     
    188189    // First, try command line
    189190    //
    190     psS32 argNum = psArgumentGet(config->argc, config->argv, "-site");
     191    psS32 argNum = psArgumentGet(*config->argc, config->argv, "-site");
    191192    if (argNum != 0) {
    192193        //
     
    195196        // remove it as well.
    196197        //
    197         psArgumentRemove(argNum, &config->argc, config->argv);
    198         if (argNum >= config->argc) {
     198        psArgumentRemove(argNum, config->argc, config->argv);
     199        if (argNum >= *config->argc) {
    199200            psLogMsg(__func__, PS_LOG_WARN,
    200201                     "-site command-line switch provided without the required filename --- ignored.\n");
    201202        } else {
    202203            siteName = psStringCopy(config->argv[argNum]);
    203             psArgumentRemove(argNum, &config->argc, config->argv);
     204            psArgumentRemove(argNum, config->argc, config->argv);
    204205        }
    205206    }
     
    255256    // file is read and parsed into psMetadata struct "camera".
    256257    //
    257     argNum = psArgumentGet(config->argc, config->argv, "-camera");
     258    argNum = psArgumentGet(*config->argc, config->argv, "-camera");
    258259    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) {
    261262            psLogMsg(__func__, PS_LOG_WARN,
    262263                     "-camera command-line switch provided without the required camera or filename --- "
     
    282283
    283284            readConfig(&config->camera, cameraFile, "camera");
    284             psArgumentRemove(argNum, &config->argc, config->argv);
     285            psArgumentRemove(argNum, config->argc, config->argv);
    285286        }
    286287    }
     
    330331
    331332
    332     argNum = psArgumentGet(config->argc, config->argv, "-log");
     333    argNum = psArgumentGet(*config->argc, config->argv, "-log");
    333334    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) {
    336337            psLogMsg(__func__, PS_LOG_WARN,
    337338                     "-log command-line switch provided without the required log destination --- ignored.\n");
     
    341342                         config->argv[argNum]);
    342343            }
    343             psArgumentRemove(argNum, &config->argc, config->argv);
     344            psArgumentRemove(argNum, config->argc, config->argv);
    344345        }
    345346    } else {
     
    388389    //
    389390    psS32 saveLogLevel = psLogGetLevel();
    390     psArgumentVerbosity(&config->argc, config->argv);
     391    psArgumentVerbosity(config->argc, config->argv);
    391392    // XXX: substitute the string for the default log level for "2".
    392393    if (2 == psLogGetLevel()) {
     
    666667    config->recipesRead |= sourceType;
    667668
     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);
    668689    return true;
    669690}
     
    691712        // Go through the command-line arguments
    692713        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) {
    696717                psLogMsg(__func__, PS_LOG_WARN, "-recipe command-line switch provided without the "
    697718                         "required recipe and source --- ignored.\n");
    698                 if (argNum == config->argc) {
     719                if (argNum == *config->argc) {
    699720                    // 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);
    701722                }
    702723                continue;
     
    704725
    705726            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);
    707728            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);
    709730
    710731            // 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);
    713732
    714733            // Is the source a symbolic reference?
     
    720739                              comment, extant);
    721740                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
    722745            } else {
    723746                // Otherwise, treat the source as a filename
     
    730753                    psFree(comment);
    731754                    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);
    732757                }
    733758            }
     
    810835psArray *pmConfigFileSets(pmConfig *config, char *file, char *list)
    811836{
    812     PS_ASSERT_INT_NONNEGATIVE(config->argc, NULL);
    813837    PS_ASSERT_PTR_NON_NULL(config, NULL);
     838    PS_ASSERT_PTR_NON_NULL(config->argc, NULL);
     839    PS_ASSERT_INT_NONNEGATIVE(*config->argc, NULL);
    814840    PS_ASSERT_PTR_NON_NULL(config->argv, NULL);
    815841    PS_ASSERT_PTR_NON_NULL(file, NULL);
     
    827853    // maybe a comma-separated list of words
    828854    // 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))) {
    830856
    831857        // select the word after 'file' and split by comma
    832         psArgumentRemove (Narg, &config->argc, config->argv);
     858        psArgumentRemove (Narg, config->argc, config->argv);
    833859        psArray *words = psStringSplitArray (config->argv[Narg], ",", true);
    834         psArgumentRemove (Narg, &config->argc, config->argv);
     860        psArgumentRemove (Narg, config->argc, config->argv);
    835861
    836862        // parse the word as a glob
     
    855881
    856882    // 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))) {
    858884        int nItems;
    859885        char line[1024]; // XXX limits the list lines to 1024 chars
     
    861887        char *filename;
    862888
    863         psArgumentRemove (Narg, &config->argc, config->argv);
     889        psArgumentRemove (Narg, config->argc, config->argv);
    864890        FILE *f = fopen (config->argv[Narg], "r");
    865891        if (f == NULL) {
     
    882908            }
    883909        }
    884         psArgumentRemove (Narg, &config->argc, config->argv);
     910        psArgumentRemove (Narg, config->argc, config->argv);
    885911    }
    886912
     
    891917{
    892918    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);
    896920    PS_ASSERT_PTR_NON_NULL(name, false);
    897     PS_ASSERT_INT_POSITIVE(strlen(name), NULL);
     921    PS_ASSERT_INT_POSITIVE(strlen(name), false);
    898922    PS_ASSERT_PTR_NON_NULL(file, false);
    899     PS_ASSERT_INT_POSITIVE(strlen(file), NULL);
     923    PS_ASSERT_INT_POSITIVE(strlen(file), false);
    900924    PS_ASSERT_PTR_NON_NULL(list, false);
    901     PS_ASSERT_INT_POSITIVE(strlen(list), NULL);
     925    PS_ASSERT_INT_POSITIVE(strlen(list), false);
    902926
    903927    psErrorClear();   // pmConfigFileSets may or may not call psError, so
     
    910934    }
    911935
    912     psMetadataAddPtr (metadata, PS_LIST_TAIL, name,  PS_DATA_ARRAY, "", files);
     936    psMetadataAddPtr(metadata, PS_LIST_TAIL, name,  PS_DATA_ARRAY, "", files);
    913937    psFree (files);
    914938    return true;
Note: See TracChangeset for help on using the changeset viewer.