IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 559


Ignore:
Timestamp:
Apr 30, 2004, 2:49:08 PM (22 years ago)
Author:
gusciora
Message:

I fixed a bunch of things.

Location:
trunk/psLib/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psTrace.c

    r556 r559  
    6767    componentAlloc(): allocate memory for a new node, and initialize members.
    6868 *****************************************************************************/
    69 static Component *componentAlloc(const char *name,
    70                                  int level)
    71 {
     69Component *componentAlloc(const char *name,
     70                          int level)
     71{
     72    //printf("Calling componentAlloc(%s, %d)\n", name, level);
    7273    Component *comp = psAlloc(sizeof(Component));
    7374    comp->name = psStringCopy(name);
     
    7576    comp->dimen = comp->n = 0;
    7677    comp->subcomp = NULL;
    77 
    7878    return comp;
    7979}
     
    124124
    125125/*****************************************************************************
    126     componentAdd(): Adds the component named "addNodeName" to the tree "comp".
    127  This procedure works by matching the current level of the component
    128  tree, pointed to by "comp", with the top level of the component
    129  name, pointed to by "addNodeName", and then recursively searching the
    130  component tree and pruning "addNodeName" until either a match is found,
    131  and then the level is set, or a new component is created.
     126    componentAdd(): Adds the component named "addNodeName" to the root tree.
    132127 
    133128    NOTE: replace the call to strsep() with a call to strtok(), which conforms
    134129    to ANSI-C.
    135  
    136     NOTE: Should we check in comp == NULL?
    137130 *****************************************************************************/
    138131static void componentAdd(const char *addNodeName,
    139132                         int         level)
    140133{
    141     int i = 0;
    142     char name[strlen(addNodeName) + 1]; // buffer for writeable copy of name.
    143     char *rest = name;                 // rest of name
    144     char *firstComponent = NULL;       // first component of name
     134    int        i = 0;
     135    char       name[strlen(addNodeName) + 1];
     136    // buffer for writeable copy.
     137    char      *pname=name;
     138    char      *firstComponent = NULL;       // first component of name
    145139    Component *currentNode = croot;
    146     int nodeExists = 0;
    147 
    148     printf("calling componentAdd(%s, %s, %d)\n", addNodeName, level);
     140    int        nodeExists = 0;
     141
     142    // printf("Calling componentAdd(%s, %d)\n", addNodeName, level);
    149143    // Is this the root node?  If so, simply set level and return.
    150144    if (strcmp(".", addNodeName) == 0) {
     
    153147    }
    154148
    155     if (addNodeName[0] != '.')
    156         printf("ERROR: failed to add %s to the root component tree.\n", addNodeName);
    157     exit(1);
    158 }
    159 
    160 strcpy(name, addNodeName);
    161 // Iterate through the components of addNodeName.
    162 while (0 != strcmp(name, ""))
    163 {
    164     rest = name;
    165     firstComponent = strsep(&rest, ".");
    166     // firstComponent points to the first component of the name, unless
    167     // it was root, in which case it points to the next component.  The
    168     // point rest points to everything else.
    169 
    170     nodeExists = 0;
    171     for (i = 0; i < comp->n; i++) {
    172         if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
    173             currentNode = currentNode->subcomp[i];
    174             nodeExists = 1;
    175         }
     149    if (addNodeName[0] != '.') {
     150        printf("ERROR: failed to add %s to the root component tree.\n",
     151               addNodeName);
     152        exit(1);
     153    }
     154
     155    strcpy(name, addNodeName);
     156    pname = &name[1];
     157    // Iterate through the components of addNodeName.  Strip off the first
     158    // component of the name, find that in the root tree, or add it if it
     159    // does not exist, then move to the next component in the name.
     160
     161    while (pname != NULL) {
     162        firstComponent = strsep(&pname, ".");
     163        nodeExists = 0;
     164        for (i = 0; i < currentNode->n; i++) {
     165            if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
     166                currentNode = currentNode->subcomp[i];
     167                nodeExists = 1;
     168                if (pname == NULL) {
     169                    currentNode->level = level;
     170                }
     171            }
     172        }
     173
    176174        if (nodeExists == 0) {
    177             // GUS: add this component to this level of currentNode.
    178         }
    179         name = rest;
    180     }
    181     currentNode->level = level;
     175            currentNode->subcomp = psRealloc(currentNode->subcomp,
     176                                             (currentNode->n + 1) * sizeof(Component *));
     177            currentNode->n = (currentNode->n)+1;
     178
     179            currentNode->subcomp[(currentNode->n)-1] =
     180                componentAlloc(firstComponent, level);
     181        }
     182    }
    182183}
    183184
     
    197198static void setHighestLevel(const Component *comp)
    198199{
     200    int i = 0;
     201
     202    if (comp == NULL) {
     203        printf("ERROR: setHighestLevel(NULL)\n");
     204        exit(1);
     205    }
     206
    199207    // If this nodes trace level is the max so far, save it in highest_level
    200208    if (comp->level > highest_level) {
     
    203211
    204212    // Do the same for all children nodes.
    205     for (int i = 0; i < comp->n; i++) {
     213    for (i = 0; i < comp->n; i++) {
    206214        setHighestLevel(comp->subcomp[i]);
    207215    }
     
    228236    }
    229237
    230     printf("Calling psSetTraceLevel(%s, %d)\n", comp, level);
     238    //printf("Calling psSetTraceLevel(%s, %d)\n", comp, level);
    231239    // invalidate cache
    232240    strncpy(cachedName, NO_CACHE, CACHE_NAME_LEN);
     
    244252
    245253    // return 0 on success.
     254    //printf("Called psSetTraceLevel(%s, %d)\n", comp, level);
    246255    return 0;
    247256}
     
    262271 The trace level of the "name" component.
    263272 *****************************************************************************/
    264 static int doGetTraceLevel(const Component *comp, // the component to search
    265                            const char *aname)     // the name to find
    266 {
    267     char name[strlen(aname) + 1];       // need a writeable copy: for strsep()
     273static int doGetTraceLevel(const char *aname)
     274{
     275    char       name[strlen(aname) + 1]; // need a writeable copy: for strsep()
     276    char      *pname=name;
     277    char      *firstComponent = NULL;   // first component of name
     278    Component *currentNode = croot;
     279    int        i = 0;
     280
     281    if (strcmp(".", aname) == 0) {
     282        return(croot->level);
     283    }
     284
     285    if (aname[0] != '.') {
     286        return(UNKNOWN_TRACE_LEVEL);
     287    }
     288
    268289    strcpy(name, aname);
    269     char *firstComponent;               // first component of name
    270     char *rest = name;                  // rest of name
    271     int level = -1;
    272     int i = 0;
    273 
    274     firstComponent = strsep(&rest, ".");
    275 
    276     // Look for a match for firstComponent in this level's subcomps
    277     for (i = 0; i < comp->n; i++) {
    278         if (strcmp(comp->subcomp[i]->name, firstComponent) == 0) {
    279             if (rest == NULL) {
    280                 // Cool.  We have matched the full name.
    281                 level = comp->subcomp[i]->level;
    282                 return (level == UNKNOWN_TRACE_LEVEL) ? comp->level : level;
    283             } else {
    284                 // We have matched this component.  Now we must recurse a
    285                 // level deeper and match the next component.
    286 
    287                 return doGetTraceLevel(comp->subcomp[i], rest);
     290    pname = &name[1];
     291    while (pname != NULL) {
     292        firstComponent = strsep(&pname, ".");
     293        for (i = 0; i < currentNode->n; i++) {
     294            if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
     295                currentNode = currentNode->subcomp[i];
     296                if (pname == NULL) {
     297                    return(currentNode->level);
     298                }
    288299            }
    289300        }
    290301    }
    291 
    292     // There was no exact match.  We return the level of the deepest
    293     // component that has matched.
    294     return comp->level;
     302    return(UNKNOWN_TRACE_LEVEL);
    295303}
    296304
     
    312320    int level = -1;
    313321
     322    //printf("Calling psGetTraceLevel(%s)\n", name);
    314323    // If the root component tree does not exist, then initialize it.
    315324    if (croot == NULL) {
     
    321330    if (strcmp(name, cachedName) == 0) {
    322331        return cachedLevel;
    323     } else if (strcmp(name, croot->name) == 0) {
    324         return(croot->level);
    325332    }
    326333
    327334    // Search the component root tree, determine the trace level.
    328     level = doGetTraceLevel(croot, name);
     335    level = doGetTraceLevel(name);
    329336
    330337    // Save this search info in our depth-one cache.
     
    332339    cachedLevel = level;
    333340
     341    //printf("Called psGetTraceLevel(%s) (level was %d)\n", name, level);
    334342    return level;
    335343}
     
    353361    int i = 0;
    354362
    355     printf("CALLING (%d): doPrintTraceLevels(%s, %d)\n", depth, comp->name, depth);
    356     printf("SHIT: comp->n is %d\n", comp->n);
    357     printf("        [\n");
    358363    if (comp->name[0] == '\0') {
    359364        printf("%*s%-*s %d\n", depth, "", 20 - depth,
     
    368373        }
    369374    }
    370     printf("        ]\n");
    371 
    372375
    373376    for (i = 0; i < comp->n; i++) {
    374377        doPrintTraceLevels(comp->subcomp[i], depth+1);
    375378    }
    376     printf("CALLED (%d): doPrintTraceLevels()\n", depth);
    377379}
    378380
  • trunk/psLib/src/sysUtils/psTrace.c

    r556 r559  
    6767    componentAlloc(): allocate memory for a new node, and initialize members.
    6868 *****************************************************************************/
    69 static Component *componentAlloc(const char *name,
    70                                  int level)
    71 {
     69Component *componentAlloc(const char *name,
     70                          int level)
     71{
     72    //printf("Calling componentAlloc(%s, %d)\n", name, level);
    7273    Component *comp = psAlloc(sizeof(Component));
    7374    comp->name = psStringCopy(name);
     
    7576    comp->dimen = comp->n = 0;
    7677    comp->subcomp = NULL;
    77 
    7878    return comp;
    7979}
     
    124124
    125125/*****************************************************************************
    126     componentAdd(): Adds the component named "addNodeName" to the tree "comp".
    127  This procedure works by matching the current level of the component
    128  tree, pointed to by "comp", with the top level of the component
    129  name, pointed to by "addNodeName", and then recursively searching the
    130  component tree and pruning "addNodeName" until either a match is found,
    131  and then the level is set, or a new component is created.
     126    componentAdd(): Adds the component named "addNodeName" to the root tree.
    132127 
    133128    NOTE: replace the call to strsep() with a call to strtok(), which conforms
    134129    to ANSI-C.
    135  
    136     NOTE: Should we check in comp == NULL?
    137130 *****************************************************************************/
    138131static void componentAdd(const char *addNodeName,
    139132                         int         level)
    140133{
    141     int i = 0;
    142     char name[strlen(addNodeName) + 1]; // buffer for writeable copy of name.
    143     char *rest = name;                 // rest of name
    144     char *firstComponent = NULL;       // first component of name
     134    int        i = 0;
     135    char       name[strlen(addNodeName) + 1];
     136    // buffer for writeable copy.
     137    char      *pname=name;
     138    char      *firstComponent = NULL;       // first component of name
    145139    Component *currentNode = croot;
    146     int nodeExists = 0;
    147 
    148     printf("calling componentAdd(%s, %s, %d)\n", addNodeName, level);
     140    int        nodeExists = 0;
     141
     142    // printf("Calling componentAdd(%s, %d)\n", addNodeName, level);
    149143    // Is this the root node?  If so, simply set level and return.
    150144    if (strcmp(".", addNodeName) == 0) {
     
    153147    }
    154148
    155     if (addNodeName[0] != '.')
    156         printf("ERROR: failed to add %s to the root component tree.\n", addNodeName);
    157     exit(1);
    158 }
    159 
    160 strcpy(name, addNodeName);
    161 // Iterate through the components of addNodeName.
    162 while (0 != strcmp(name, ""))
    163 {
    164     rest = name;
    165     firstComponent = strsep(&rest, ".");
    166     // firstComponent points to the first component of the name, unless
    167     // it was root, in which case it points to the next component.  The
    168     // point rest points to everything else.
    169 
    170     nodeExists = 0;
    171     for (i = 0; i < comp->n; i++) {
    172         if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
    173             currentNode = currentNode->subcomp[i];
    174             nodeExists = 1;
    175         }
     149    if (addNodeName[0] != '.') {
     150        printf("ERROR: failed to add %s to the root component tree.\n",
     151               addNodeName);
     152        exit(1);
     153    }
     154
     155    strcpy(name, addNodeName);
     156    pname = &name[1];
     157    // Iterate through the components of addNodeName.  Strip off the first
     158    // component of the name, find that in the root tree, or add it if it
     159    // does not exist, then move to the next component in the name.
     160
     161    while (pname != NULL) {
     162        firstComponent = strsep(&pname, ".");
     163        nodeExists = 0;
     164        for (i = 0; i < currentNode->n; i++) {
     165            if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
     166                currentNode = currentNode->subcomp[i];
     167                nodeExists = 1;
     168                if (pname == NULL) {
     169                    currentNode->level = level;
     170                }
     171            }
     172        }
     173
    176174        if (nodeExists == 0) {
    177             // GUS: add this component to this level of currentNode.
    178         }
    179         name = rest;
    180     }
    181     currentNode->level = level;
     175            currentNode->subcomp = psRealloc(currentNode->subcomp,
     176                                             (currentNode->n + 1) * sizeof(Component *));
     177            currentNode->n = (currentNode->n)+1;
     178
     179            currentNode->subcomp[(currentNode->n)-1] =
     180                componentAlloc(firstComponent, level);
     181        }
     182    }
    182183}
    183184
     
    197198static void setHighestLevel(const Component *comp)
    198199{
     200    int i = 0;
     201
     202    if (comp == NULL) {
     203        printf("ERROR: setHighestLevel(NULL)\n");
     204        exit(1);
     205    }
     206
    199207    // If this nodes trace level is the max so far, save it in highest_level
    200208    if (comp->level > highest_level) {
     
    203211
    204212    // Do the same for all children nodes.
    205     for (int i = 0; i < comp->n; i++) {
     213    for (i = 0; i < comp->n; i++) {
    206214        setHighestLevel(comp->subcomp[i]);
    207215    }
     
    228236    }
    229237
    230     printf("Calling psSetTraceLevel(%s, %d)\n", comp, level);
     238    //printf("Calling psSetTraceLevel(%s, %d)\n", comp, level);
    231239    // invalidate cache
    232240    strncpy(cachedName, NO_CACHE, CACHE_NAME_LEN);
     
    244252
    245253    // return 0 on success.
     254    //printf("Called psSetTraceLevel(%s, %d)\n", comp, level);
    246255    return 0;
    247256}
     
    262271 The trace level of the "name" component.
    263272 *****************************************************************************/
    264 static int doGetTraceLevel(const Component *comp, // the component to search
    265                            const char *aname)     // the name to find
    266 {
    267     char name[strlen(aname) + 1];       // need a writeable copy: for strsep()
     273static int doGetTraceLevel(const char *aname)
     274{
     275    char       name[strlen(aname) + 1]; // need a writeable copy: for strsep()
     276    char      *pname=name;
     277    char      *firstComponent = NULL;   // first component of name
     278    Component *currentNode = croot;
     279    int        i = 0;
     280
     281    if (strcmp(".", aname) == 0) {
     282        return(croot->level);
     283    }
     284
     285    if (aname[0] != '.') {
     286        return(UNKNOWN_TRACE_LEVEL);
     287    }
     288
    268289    strcpy(name, aname);
    269     char *firstComponent;               // first component of name
    270     char *rest = name;                  // rest of name
    271     int level = -1;
    272     int i = 0;
    273 
    274     firstComponent = strsep(&rest, ".");
    275 
    276     // Look for a match for firstComponent in this level's subcomps
    277     for (i = 0; i < comp->n; i++) {
    278         if (strcmp(comp->subcomp[i]->name, firstComponent) == 0) {
    279             if (rest == NULL) {
    280                 // Cool.  We have matched the full name.
    281                 level = comp->subcomp[i]->level;
    282                 return (level == UNKNOWN_TRACE_LEVEL) ? comp->level : level;
    283             } else {
    284                 // We have matched this component.  Now we must recurse a
    285                 // level deeper and match the next component.
    286 
    287                 return doGetTraceLevel(comp->subcomp[i], rest);
     290    pname = &name[1];
     291    while (pname != NULL) {
     292        firstComponent = strsep(&pname, ".");
     293        for (i = 0; i < currentNode->n; i++) {
     294            if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
     295                currentNode = currentNode->subcomp[i];
     296                if (pname == NULL) {
     297                    return(currentNode->level);
     298                }
    288299            }
    289300        }
    290301    }
    291 
    292     // There was no exact match.  We return the level of the deepest
    293     // component that has matched.
    294     return comp->level;
     302    return(UNKNOWN_TRACE_LEVEL);
    295303}
    296304
     
    312320    int level = -1;
    313321
     322    //printf("Calling psGetTraceLevel(%s)\n", name);
    314323    // If the root component tree does not exist, then initialize it.
    315324    if (croot == NULL) {
     
    321330    if (strcmp(name, cachedName) == 0) {
    322331        return cachedLevel;
    323     } else if (strcmp(name, croot->name) == 0) {
    324         return(croot->level);
    325332    }
    326333
    327334    // Search the component root tree, determine the trace level.
    328     level = doGetTraceLevel(croot, name);
     335    level = doGetTraceLevel(name);
    329336
    330337    // Save this search info in our depth-one cache.
     
    332339    cachedLevel = level;
    333340
     341    //printf("Called psGetTraceLevel(%s) (level was %d)\n", name, level);
    334342    return level;
    335343}
     
    353361    int i = 0;
    354362
    355     printf("CALLING (%d): doPrintTraceLevels(%s, %d)\n", depth, comp->name, depth);
    356     printf("SHIT: comp->n is %d\n", comp->n);
    357     printf("        [\n");
    358363    if (comp->name[0] == '\0') {
    359364        printf("%*s%-*s %d\n", depth, "", 20 - depth,
     
    368373        }
    369374    }
    370     printf("        ]\n");
    371 
    372375
    373376    for (i = 0; i < comp->n; i++) {
    374377        doPrintTraceLevels(comp->subcomp[i], depth+1);
    375378    }
    376     printf("CALLED (%d): doPrintTraceLevels()\n", depth);
    377379}
    378380
Note: See TracChangeset for help on using the changeset viewer.