IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 3, 2006, 8:48:10 AM (19 years ago)
Author:
magnier
Message:

defined pmConfigConvertFilename, added to all I/O functions

File:
1 edited

Legend:

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

    r9992 r10421  
    44 *  @author EAM (IfA)
    55 *
    6  *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2006-11-15 02:34:18 $
     6 *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2006-12-03 18:48:10 $
    88 *
    99 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    454454
    455455
     456// XXX aren't these (return false) below errors: call psError?
    456457bool pmConfigValidateCameraFormat(const psMetadata *cameraFormat, const psMetadata *header)
    457458{
     
    463464    psMetadata *rule = psMetadataLookupMetadata(&mdStatus, cameraFormat, "RULE");
    464465    if (! mdStatus || ! rule) {
    465         psLogMsg(__func__, PS_LOG_WARN, "Unable to read rule for camera.\n");
     466        psError(PS_ERR_UNKNOWN, true, "Unable to read rule for camera.\n");
    466467        return false;
    467468    }
     
    472473    while ((ruleItem = psMetadataGetAndIncrement(ruleIter))) {
    473474        // Check for the existence of the rule
    474         psMetadataItem *headerItem = psMetadataLookup((psMetadata*)header, ruleItem->name);
     475        psMetadataItem *headerItem = psMetadataLookup(header, ruleItem->name);
    475476        if (! headerItem) {
    476477            // It doesn't have a required header keyword, so it's not it
    477478            psFree(ruleIter);
    478             psTrace("psModules.config", 5, "Can't find %s\n", ruleItem->name);
     479            psError(PS_ERR_UNKNOWN, true, "Can't find %s\n", ruleItem->name);
    479480            return false;
    480481        }
     
    482483        // Check to see if the rule works
    483484        if (! psMetadataItemCompare(headerItem, ruleItem)) {
    484             psTrace("psModules.config", 5, "%s doesn't match.\n", ruleItem->name);
     485            psError(PS_ERR_UNKNOWN, true, "%s doesn't match.\n", ruleItem->name);
    485486            psFree(ruleIter);
    486487            return false;
     
    938939            glob (words->data[i], 0, NULL, &globList);
    939940
     941            // if the glob does not match, save the literal word:
     942            // otherwise save all glob matches
    940943            if (globList.gl_pathc == 0) {
    941                 psError(PS_ERR_IO, true, "No match for %s", (char *)words->data[i]);
    942                 return input;
    943             }
    944 
    945             for (int j = 0; j < globList.gl_pathc; j++) {
    946                 char *filename = psStringCopy (globList.gl_pathv[j]);
    947                 psArrayAdd (input, 16, filename);
    948                 psFree (filename);
     944                psArrayAdd (input, 16, words->data[i]);
     945            } else {
     946                for (int j = 0; j < globList.gl_pathc; j++) {
     947                    char *filename = psStringCopy (globList.gl_pathv[j]);
     948                    psArrayAdd (input, 16, filename);
     949                    psFree (filename);
     950                }
    949951            }
    950952        }
     
    10081010    return true;
    10091011}
     1012
     1013// convert the supplied name, create a new output psString
     1014psString pmConfigConvertFilename (char *filename, pmConfig *config)
     1015{
     1016
     1017    psString newName = psStringCopy (filename);
     1018
     1019    // strip file:// from front of name
     1020    if (!strncasecmp (newName, "file://", strlen("file://"))) {
     1021        newName = psStringSubstitute (newName, "", "file://");
     1022    }
     1023
     1024    // replace path://PATH with matched datapath
     1025    if (!strncasecmp (newName, "path://", strlen("path://"))) {
     1026        // filename should be of the form: path://PATH/rest/of/file
     1027        // replace PATH with matching name from config->site:DATAPATH
     1028        psMetadata *datapath = psMetadataLookupPtr (NULL, config->site, "DATAPATH");
     1029        if (datapath == NULL) {
     1030            psError(PS_ERR_UNKNOWN, true, "DATAPATH is not defined in config.site");
     1031            psFree (newName);
     1032            return NULL;
     1033        }
     1034
     1035        char *point = newName + strlen("path://");
     1036        char *mark = strchr (point, '/');
     1037        if (mark == NULL) {
     1038            psError(PS_ERR_UNKNOWN, true, "syntax error in PATH-style name %s", newName);
     1039            psFree (newName);
     1040            return false;
     1041        }
     1042
     1043        psString path = psStringNCopy (point, mark - point);
     1044        char *realpath = psMetadataLookupStr (NULL, datapath, path);
     1045        if (realpath == NULL) {
     1046            psError(PS_ERR_UNKNOWN, true, "path (%s) not defined in config.site:DATAPATH for PATH-style name %s", path, newName);
     1047            psFree (newName);
     1048            psFree (path);
     1049            return false;
     1050        }
     1051        psFree (path);
     1052
     1053        char *tmpName = NULL;
     1054        psStringAppend (&tmpName, "%s/%s", realpath, mark + 1);
     1055        psFree (newName);
     1056        newName = tmpName;
     1057    }
     1058
     1059    // substitute neb://name with matched nebulous name
     1060
     1061    // if we still have a relative path, prepend WORKDIR:
     1062    if (newName[0] != '/') {
     1063        char *workdir = psMetadataLookupStr (NULL, config->site, "WORKDIR");
     1064        if (workdir) {
     1065            psStringPrepend (&newName, "%s/", workdir);
     1066        }
     1067    }
     1068
     1069    return newName;
     1070}
Note: See TracChangeset for help on using the changeset viewer.