IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7817


Ignore:
Timestamp:
Jul 5, 2006, 12:46:13 PM (20 years ago)
Author:
Paul Price
Message:

Storing argc as a pointer in pmConfig. As it's a pointer to the original version, we can change what's at the end of the pointer and change the original version. That means that we don't have two copies of argc floating around (one on the pmConfig, and one in the main program). Changed the API for pmConfigRead again, so it modifies argc (keeps everything consistent). Fixed up some assertions to use the correct return type (NULL vs false).

Location:
trunk/psModules/src/config
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfig.c

    r7791 r7817  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-07-03 21:18:30 $
     5 *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-07-05 22:46:13 $
    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));
     
    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()) {
     
    711712        // Go through the command-line arguments
    712713        int argNum; // Argument number for "-recipe"
    713         while ((argNum = psArgumentGet(config->argc, config->argv, "-recipe")) > 0) {
    714             psArgumentRemove(argNum, &config->argc, config->argv);
    715             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) {
    716717                psLogMsg(__func__, PS_LOG_WARN, "-recipe command-line switch provided without the "
    717718                         "required recipe and source --- ignored.\n");
    718                 if (argNum == config->argc) {
     719                if (argNum == *config->argc) {
    719720                    // Remove the single last argument (we required two, they gave us one)
    720                     psArgumentRemove(argNum, &config->argc, config->argv);
     721                    psArgumentRemove(argNum, config->argc, config->argv);
    721722                }
    722723                continue;
     
    724725
    725726            const char *recipeName = psStringCopy(config->argv[argNum]); // Name of the recipe
    726             psArgumentRemove(argNum, &config->argc, config->argv);
     727            psArgumentRemove(argNum, config->argc, config->argv);
    727728            const char *recipeSource = psStringCopy(config->argv[argNum]); // Source of the recipe
    728             psArgumentRemove(argNum, &config->argc, config->argv);
     729            psArgumentRemove(argNum, config->argc, config->argv);
    729730
    730731            // Command-line has the highest priority, so we don't have to check to see if it's already there
     
    834835psArray *pmConfigFileSets(pmConfig *config, char *file, char *list)
    835836{
    836     PS_ASSERT_INT_NONNEGATIVE(config->argc, NULL);
    837837    PS_ASSERT_PTR_NON_NULL(config, NULL);
     838    PS_ASSERT_PTR_NON_NULL(config->argc, NULL);
     839    PS_ASSERT_INT_NONNEGATIVE(*config->argc, NULL);
    838840    PS_ASSERT_PTR_NON_NULL(config->argv, NULL);
    839841    PS_ASSERT_PTR_NON_NULL(file, NULL);
     
    851853    // maybe a comma-separated list of words
    852854    // each word may be a glob: "file*.fits"
    853     if ((Narg = psArgumentGet (config->argc, config->argv, file))) {
     855    if ((Narg = psArgumentGet (*config->argc, config->argv, file))) {
    854856
    855857        // select the word after 'file' and split by comma
    856         psArgumentRemove (Narg, &config->argc, config->argv);
     858        psArgumentRemove (Narg, config->argc, config->argv);
    857859        psArray *words = psStringSplitArray (config->argv[Narg], ",", true);
    858         psArgumentRemove (Narg, &config->argc, config->argv);
     860        psArgumentRemove (Narg, config->argc, config->argv);
    859861
    860862        // parse the word as a glob
     
    879881
    880882    // load the list from the supplied text file
    881     if ((Narg = psArgumentGet (config->argc, config->argv, list))) {
     883    if ((Narg = psArgumentGet (*config->argc, config->argv, list))) {
    882884        int nItems;
    883885        char line[1024]; // XXX limits the list lines to 1024 chars
     
    885887        char *filename;
    886888
    887         psArgumentRemove (Narg, &config->argc, config->argv);
     889        psArgumentRemove (Narg, config->argc, config->argv);
    888890        FILE *f = fopen (config->argv[Narg], "r");
    889891        if (f == NULL) {
     
    906908            }
    907909        }
    908         psArgumentRemove (Narg, &config->argc, config->argv);
     910        psArgumentRemove (Narg, config->argc, config->argv);
    909911    }
    910912
     
    915917{
    916918    PS_ASSERT_PTR_NON_NULL(metadata, false);
    917     PS_ASSERT_PTR_NON_NULL(config, NULL);
    918     PS_ASSERT_INT_NONNEGATIVE(config->argc, NULL);
    919     PS_ASSERT_PTR_NON_NULL(config->argv, false);
     919    PS_ASSERT_PTR_NON_NULL(config, false);
    920920    PS_ASSERT_PTR_NON_NULL(name, false);
    921     PS_ASSERT_INT_POSITIVE(strlen(name), NULL);
     921    PS_ASSERT_INT_POSITIVE(strlen(name), false);
    922922    PS_ASSERT_PTR_NON_NULL(file, false);
    923     PS_ASSERT_INT_POSITIVE(strlen(file), NULL);
     923    PS_ASSERT_INT_POSITIVE(strlen(file), false);
    924924    PS_ASSERT_PTR_NON_NULL(list, false);
    925     PS_ASSERT_INT_POSITIVE(strlen(list), NULL);
     925    PS_ASSERT_INT_POSITIVE(strlen(list), false);
    926926
    927927    psErrorClear();   // pmConfigFileSets may or may not call psError, so
     
    934934    }
    935935
    936     psMetadataAddPtr (metadata, PS_LIST_TAIL, name,  PS_DATA_ARRAY, "", files);
     936    psMetadataAddPtr(metadata, PS_LIST_TAIL, name,  PS_DATA_ARRAY, "", files);
    937937    psFree (files);
    938938    return true;
  • trunk/psModules/src/config/pmConfig.h

    r7792 r7817  
    33 *  @author PAP, IfA
    44 *
    5  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2006-07-03 21:26:53 $
     5 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2006-07-05 22:46:13 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3333    psMetadata *files;                  // pmFPAfiles used for analysis
    3434    psDB *database;                     // Database handle
    35     int argc;                           // Number of command-line arguments
     35    int *argc;                          // Number of command-line arguments
    3636    char **argv;                        // Command-line arguments (raw version)
    3737    // Private members
     
    4141pmConfig;
    4242
    43 pmConfig *pmConfigAlloc(int argc,       // Number of command-line arguments
     43pmConfig *pmConfigAlloc(int *argc,      // Number of command-line arguments
    4444                        char **argv     // Command-line arguments
    4545                       );
     
    6767 */
    6868pmConfig *pmConfigRead(
    69     int argc,
     69    int *argc,
    7070    char **argv);
    7171
Note: See TracChangeset for help on using the changeset viewer.