Changeset 556
- Timestamp:
- Apr 29, 2004, 8:18:28 PM (22 years ago)
- Location:
- trunk/psLib/src
- Files:
-
- 4 edited
-
sys/psTrace.c (modified) (13 diffs)
-
sys/psTrace.h (modified) (1 diff)
-
sysUtils/psTrace.c (modified) (13 diffs)
-
sysUtils/psTrace.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/sys/psTrace.c
r481 r556 16 16 not the same thing as a node's "level", which corresponds to the 17 17 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". 18 26 *****************************************************************************/ 19 27 #include <stdlib.h> … … 28 36 #define CACHE_NAME_LEN 50 29 37 #define NO_CACHE "\a" // no name is cached 30 #define UNKNOWN_LEVEL -9999 // we don't know this name's level31 38 /***************************************************************************** 32 39 A component is a string of the form aaa.bbb.ccc, and may itself contain … … 47 54 // tree. 48 55 49 // NOTE: the next tree globals exist 50 // for optimization purposes only. 56 // NOTE: the next tree globals exist for optimization purposes only. 51 57 // Consider removing them. 52 58 static 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 55 60 // us if a message should be printed. 56 61 static char cachedName[CACHE_NAME_LEN + 1] = NO_CACHE; … … 103 108 { 104 109 if (croot == NULL) { 105 croot = componentAlloc(" ", UNKNOWN_LEVEL);110 croot = componentAlloc(".", UNKNOWN_TRACE_LEVEL); 106 111 } 107 112 } … … 119 124 120 125 /***************************************************************************** 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. 122 132 123 133 NOTE: replace the call to strsep() with a call to strtok(), which conforms … … 126 136 NOTE: Should we check in comp == NULL? 127 137 *****************************************************************************/ 128 static void componentAdd(Component *comp, 129 const char *aname, 138 static void componentAdd(const char *addNodeName, 130 139 int level) 131 140 { 132 char name[strlen(aname) + 1]; // need a writeable copy133 strcpy(name, aname);134 141 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 136 144 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 160 strcpy(name, addNodeName); 161 // Iterate through the components of addNodeName. 162 while (0 != strcmp(name, "")) 163 { 164 rest = name; 139 165 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; 155 171 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; 193 182 } 194 183 … … 239 228 } 240 229 230 printf("Calling psSetTraceLevel(%s, %d)\n", comp, level); 241 231 // invalidate cache 242 232 strncpy(cachedName, NO_CACHE, CACHE_NAME_LEN); 243 233 244 234 // Add the new component to the component tree. 245 componentAdd(c root, comp, level);235 componentAdd(comp, level); 246 236 247 237 // Save this search info in our depth-one cache. … … 249 239 highest_level = level; 250 240 } else { 251 highest_level = UNKNOWN_ LEVEL;241 highest_level = UNKNOWN_TRACE_LEVEL; 252 242 setHighestLevel(croot); 253 243 } … … 280 270 char *rest = name; // rest of name 281 271 int level = -1; 272 int i = 0; 282 273 283 274 firstComponent = strsep(&rest, "."); 284 275 285 276 // Look for a match for firstComponent in this level's subcomps 286 for (i nt i= 0; i < comp->n; i++) {277 for (i = 0; i < comp->n; i++) { 287 278 if (strcmp(comp->subcomp[i]->name, firstComponent) == 0) { 288 279 if (rest == NULL) { 289 280 // Cool. We have matched the full name. 290 281 level = comp->subcomp[i]->level; 291 return (level == UNKNOWN_ LEVEL) ? comp->level : level;282 return (level == UNKNOWN_TRACE_LEVEL) ? comp->level : level; 292 283 } else { 293 284 // We have matched this component. Now we must recurse a … … 330 321 if (strcmp(name, cachedName) == 0) { 331 322 return cachedLevel; 323 } else if (strcmp(name, croot->name) == 0) { 324 return(croot->level); 332 325 } 333 326 … … 360 353 int i = 0; 361 354 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"); 362 358 if (comp->name[0] == '\0') { 363 359 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); 365 361 } else { 366 if (comp->level == UNKNOWN_ LEVEL) {362 if (comp->level == UNKNOWN_TRACE_LEVEL) { 367 363 printf("%*s%-*s %s\n", depth, "", 20 - depth, 368 364 comp->name, "."); … … 372 368 } 373 369 } 370 printf(" ]\n"); 371 374 372 375 373 for (i = 0; i < comp->n; i++) { 376 374 doPrintTraceLevels(comp->subcomp[i], depth+1); 377 375 } 376 printf("CALLED (%d): doPrintTraceLevels()\n", depth); 378 377 } 379 378 … … 428 427 429 428 if ((level <= highest_level) && 430 ( psGetTraceLevel(comp) >= level)) {429 (level <= psGetTraceLevel(comp))) { 431 430 va_start(ap, level); 432 431 -
trunk/psLib/src/sys/psTrace.h
r459 r556 1 1 #if !defined(PS_TRACE_H) 2 2 #define PS_TRACE_H 1 3 #define UNKNOWN_TRACE_LEVEL -9999 // we don't know this name's level 3 4 4 5 /** \file psTrace.h -
trunk/psLib/src/sysUtils/psTrace.c
r481 r556 16 16 not the same thing as a node's "level", which corresponds to the 17 17 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". 18 26 *****************************************************************************/ 19 27 #include <stdlib.h> … … 28 36 #define CACHE_NAME_LEN 50 29 37 #define NO_CACHE "\a" // no name is cached 30 #define UNKNOWN_LEVEL -9999 // we don't know this name's level31 38 /***************************************************************************** 32 39 A component is a string of the form aaa.bbb.ccc, and may itself contain … … 47 54 // tree. 48 55 49 // NOTE: the next tree globals exist 50 // for optimization purposes only. 56 // NOTE: the next tree globals exist for optimization purposes only. 51 57 // Consider removing them. 52 58 static 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 55 60 // us if a message should be printed. 56 61 static char cachedName[CACHE_NAME_LEN + 1] = NO_CACHE; … … 103 108 { 104 109 if (croot == NULL) { 105 croot = componentAlloc(" ", UNKNOWN_LEVEL);110 croot = componentAlloc(".", UNKNOWN_TRACE_LEVEL); 106 111 } 107 112 } … … 119 124 120 125 /***************************************************************************** 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. 122 132 123 133 NOTE: replace the call to strsep() with a call to strtok(), which conforms … … 126 136 NOTE: Should we check in comp == NULL? 127 137 *****************************************************************************/ 128 static void componentAdd(Component *comp, 129 const char *aname, 138 static void componentAdd(const char *addNodeName, 130 139 int level) 131 140 { 132 char name[strlen(aname) + 1]; // need a writeable copy133 strcpy(name, aname);134 141 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 136 144 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 160 strcpy(name, addNodeName); 161 // Iterate through the components of addNodeName. 162 while (0 != strcmp(name, "")) 163 { 164 rest = name; 139 165 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; 155 171 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; 193 182 } 194 183 … … 239 228 } 240 229 230 printf("Calling psSetTraceLevel(%s, %d)\n", comp, level); 241 231 // invalidate cache 242 232 strncpy(cachedName, NO_CACHE, CACHE_NAME_LEN); 243 233 244 234 // Add the new component to the component tree. 245 componentAdd(c root, comp, level);235 componentAdd(comp, level); 246 236 247 237 // Save this search info in our depth-one cache. … … 249 239 highest_level = level; 250 240 } else { 251 highest_level = UNKNOWN_ LEVEL;241 highest_level = UNKNOWN_TRACE_LEVEL; 252 242 setHighestLevel(croot); 253 243 } … … 280 270 char *rest = name; // rest of name 281 271 int level = -1; 272 int i = 0; 282 273 283 274 firstComponent = strsep(&rest, "."); 284 275 285 276 // Look for a match for firstComponent in this level's subcomps 286 for (i nt i= 0; i < comp->n; i++) {277 for (i = 0; i < comp->n; i++) { 287 278 if (strcmp(comp->subcomp[i]->name, firstComponent) == 0) { 288 279 if (rest == NULL) { 289 280 // Cool. We have matched the full name. 290 281 level = comp->subcomp[i]->level; 291 return (level == UNKNOWN_ LEVEL) ? comp->level : level;282 return (level == UNKNOWN_TRACE_LEVEL) ? comp->level : level; 292 283 } else { 293 284 // We have matched this component. Now we must recurse a … … 330 321 if (strcmp(name, cachedName) == 0) { 331 322 return cachedLevel; 323 } else if (strcmp(name, croot->name) == 0) { 324 return(croot->level); 332 325 } 333 326 … … 360 353 int i = 0; 361 354 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"); 362 358 if (comp->name[0] == '\0') { 363 359 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); 365 361 } else { 366 if (comp->level == UNKNOWN_ LEVEL) {362 if (comp->level == UNKNOWN_TRACE_LEVEL) { 367 363 printf("%*s%-*s %s\n", depth, "", 20 - depth, 368 364 comp->name, "."); … … 372 368 } 373 369 } 370 printf(" ]\n"); 371 374 372 375 373 for (i = 0; i < comp->n; i++) { 376 374 doPrintTraceLevels(comp->subcomp[i], depth+1); 377 375 } 376 printf("CALLED (%d): doPrintTraceLevels()\n", depth); 378 377 } 379 378 … … 428 427 429 428 if ((level <= highest_level) && 430 ( psGetTraceLevel(comp) >= level)) {429 (level <= psGetTraceLevel(comp))) { 431 430 va_start(ap, level); 432 431 -
trunk/psLib/src/sysUtils/psTrace.h
r459 r556 1 1 #if !defined(PS_TRACE_H) 2 2 #define PS_TRACE_H 1 3 #define UNKNOWN_TRACE_LEVEL -9999 // we don't know this name's level 3 4 4 5 /** \file psTrace.h
Note:
See TracChangeset
for help on using the changeset viewer.
