IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 29, 2004, 8:18:28 PM (22 years ago)
Author:
gusciora
Message:

This code is in a non-working state.

File:
1 edited

Legend:

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

    r481 r556  
    1616 not the same thing as a node's "level", which corresponds to the
    1717 trace level of that node.  I should probably rename some variables.
     18 
     19 This code is obduscated by the fact that component names are of the form
     20 ".a.b.c.d" where "." is always the root of the tree, and for tree that have
     21 a depth of 3 or higher (including the root ".") the "."  character is also
     22 the deliminator between different individual nodes in the full component
     23 name.  So, for ".a.b.c.d", the first "." signifies the root of the tree,
     24 while the last three dots merely act as separators between the node names
     25 "b", "c", and "d".
    1826 *****************************************************************************/
    1927#include <stdlib.h>
     
    2836#define CACHE_NAME_LEN 50
    2937#define NO_CACHE "\a"                     // no name is cached
    30 #define UNKNOWN_LEVEL -9999               // we don't know this name's level
    3138/*****************************************************************************
    3239    A component is a string of the form aaa.bbb.ccc, and may itself contain
     
    4754// tree.
    4855
    49 // NOTE: the next tree globals exist
    50 // for optimization purposes only.
     56// NOTE: the next tree globals exist for optimization purposes only.
    5157// Consider removing them.
    5258static int highest_level = 0;             // Highest level requested.  Defining
    53 // this variable allows us to reduce
    54 // component-tree searches that tell
     59// this variable allows us to reduce component-tree searches that tell
    5560// us if a message should be printed.
    5661static char cachedName[CACHE_NAME_LEN + 1] = NO_CACHE;
     
    103108{
    104109    if (croot == NULL) {
    105         croot = componentAlloc("", UNKNOWN_LEVEL);
     110        croot = componentAlloc(".", UNKNOWN_TRACE_LEVEL);
    106111    }
    107112}
     
    119124
    120125/*****************************************************************************
    121     Add a new component to the tree
     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.
    122132 
    123133    NOTE: replace the call to strsep() with a call to strtok(), which conforms
     
    126136    NOTE: Should we check in comp == NULL?
    127137 *****************************************************************************/
    128 static void componentAdd(Component  *comp,
    129                          const char *aname,
     138static void componentAdd(const char *addNodeName,
    130139                         int         level)
    131140{
    132     char name[strlen(aname) + 1];      // need a writeable copy
    133     strcpy(name, aname);
    134141    int i = 0;
    135     int j = 0;
     142    char name[strlen(addNodeName) + 1]; // buffer for writeable copy of name.
     143    char *rest = name;                 // rest of name
    136144    char *firstComponent = NULL;       // first component of name
    137     char *rest = name;                 // rest of name
    138 
     145    Component *currentNode = croot;
     146    int nodeExists = 0;
     147
     148    printf("calling componentAdd(%s, %s, %d)\n", addNodeName, level);
     149    // Is this the root node?  If so, simply set level and return.
     150    if (strcmp(".", addNodeName) == 0) {
     151        croot->level = level;
     152        return;
     153    }
     154
     155    if (addNodeName[0] != '.')
     156        printf("ERROR: failed to add %s to the root component tree.\n", addNodeName);
     157    exit(1);
     158}
     159
     160strcpy(name, addNodeName);
     161// Iterate through the components of addNodeName.
     162while (0 != strcmp(name, ""))
     163{
     164    rest = name;
    139165    firstComponent = strsep(&rest, ".");
    140     // After this call, firstComponent
    141     // points to the first component of the
    142     // name, rest points to everything else.
    143 
    144     // Does firstComponent match this level?
    145     if (strcmp(comp->name, firstComponent) == 0) {
    146         if (rest == NULL) {
    147             comp->level = level;
    148         } else {
    149             componentAdd(comp, rest, level);
    150         }
    151         return;
    152     }
    153 
    154     // Look for a match for firstComponent in this level's subcomps
     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;
    155171    for (i = 0; i < comp->n; i++) {
    156         if (strcmp(comp->subcomp[i]->name, firstComponent) == 0) {
    157             if (rest == NULL) {
    158                 comp->subcomp[i]->level = level;
    159             } else {
    160                 componentAdd(comp->subcomp[i], rest, level);
    161             }
    162 
    163             return;
    164         }
    165     }
    166 
    167     // No match; add firstComponent to this level.  Ensure that subcomp is
    168     // sorted.
    169     if (comp->n >= comp->dimen - 1) {
    170         comp->dimen += 5;
    171 
    172         comp->subcomp = psRealloc(comp->subcomp,
    173                                   comp->dimen*sizeof(Component *));
    174     }
    175 
    176     Component *firstComponent2 = componentAlloc(firstComponent, UNKNOWN_LEVEL);
    177     for (i = 0; i < comp->n; i++) {
    178         if (strcmp(firstComponent, comp->subcomp[i]->name) > 0) {
    179             for (j = comp->n; j > i; j--) {
    180                 comp->subcomp[j] = comp->subcomp[j - 1];
    181             }
    182             break;
    183         }
    184     }
    185     comp->subcomp[i] = firstComponent2;
    186     comp->n++;
    187 
    188     if (rest == NULL) {
    189         firstComponent2->level = level;
    190     } else {
    191         componentAdd(firstComponent2, rest, level);
    192     }
     172        if (strcmp(currentNode->subcomp[i]->name, firstComponent) == 0) {
     173            currentNode = currentNode->subcomp[i];
     174            nodeExists = 1;
     175        }
     176        if (nodeExists == 0) {
     177            // GUS: add this component to this level of currentNode.
     178        }
     179        name = rest;
     180    }
     181    currentNode->level = level;
    193182}
    194183
     
    239228    }
    240229
     230    printf("Calling psSetTraceLevel(%s, %d)\n", comp, level);
    241231    // invalidate cache
    242232    strncpy(cachedName, NO_CACHE, CACHE_NAME_LEN);
    243233
    244234    // Add the new component to the component tree.
    245     componentAdd(croot, comp, level);
     235    componentAdd(comp, level);
    246236
    247237    // Save this search info in our depth-one cache.
     
    249239        highest_level = level;
    250240    } else {
    251         highest_level = UNKNOWN_LEVEL;
     241        highest_level = UNKNOWN_TRACE_LEVEL;
    252242        setHighestLevel(croot);
    253243    }
     
    280270    char *rest = name;                  // rest of name
    281271    int level = -1;
     272    int i = 0;
    282273
    283274    firstComponent = strsep(&rest, ".");
    284275
    285276    // Look for a match for firstComponent in this level's subcomps
    286     for (int i = 0; i < comp->n; i++) {
     277    for (i = 0; i < comp->n; i++) {
    287278        if (strcmp(comp->subcomp[i]->name, firstComponent) == 0) {
    288279            if (rest == NULL) {
    289280                // Cool.  We have matched the full name.
    290281                level = comp->subcomp[i]->level;
    291                 return (level == UNKNOWN_LEVEL) ? comp->level : level;
     282                return (level == UNKNOWN_TRACE_LEVEL) ? comp->level : level;
    292283            } else {
    293284                // We have matched this component.  Now we must recurse a
     
    330321    if (strcmp(name, cachedName) == 0) {
    331322        return cachedLevel;
     323    } else if (strcmp(name, croot->name) == 0) {
     324        return(croot->level);
    332325    }
    333326
     
    360353    int i = 0;
    361354
     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");
    362358    if (comp->name[0] == '\0') {
    363359        printf("%*s%-*s %d\n", depth, "", 20 - depth,
    364                "(root)", (comp->level == UNKNOWN_LEVEL) ? 0 : comp->level);
     360               "(root)", (comp->level == UNKNOWN_TRACE_LEVEL) ? 0 : comp->level);
    365361    } else {
    366         if (comp->level == UNKNOWN_LEVEL) {
     362        if (comp->level == UNKNOWN_TRACE_LEVEL) {
    367363            printf("%*s%-*s %s\n", depth, "", 20 - depth,
    368364                   comp->name, ".");
     
    372368        }
    373369    }
     370    printf("        ]\n");
     371
    374372
    375373    for (i = 0; i < comp->n; i++) {
    376374        doPrintTraceLevels(comp->subcomp[i], depth+1);
    377375    }
     376    printf("CALLED (%d): doPrintTraceLevels()\n", depth);
    378377}
    379378
     
    428427
    429428    if ((level <= highest_level) &&
    430             (psGetTraceLevel(comp) >= level)) {
     429            (level <= psGetTraceLevel(comp))) {
    431430        va_start(ap, level);
    432431
Note: See TracChangeset for help on using the changeset viewer.