Changeset 15330
- Timestamp:
- Oct 17, 2007, 2:14:50 PM (19 years ago)
- Location:
- trunk/ippTools/src
- Files:
-
- 2 edited
-
Makefile.am (modified) (2 diffs)
-
magictool.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/Makefile.am
r14699 r15330 14 14 warptool \ 15 15 pzgetimfiles \ 16 pztool 16 pztool \ 17 ttree 17 18 18 19 pkginclude_HEADERS = \ … … 65 66 # for pxtools.h 66 67 AM_CPPFLAGS = -I$(top_srcdir)/src$ 68 69 ttree_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS) 70 ttree_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la 67 71 68 72 pztool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS) -
trunk/ippTools/src/magictool.c
r15188 r15330 296 296 297 297 298 bool findBaseNodes(void *arg, pxNode *node) 299 { 300 bool status = false; 301 psS64 done = psMetadataLookupS64(&status, node->data, "done"); 302 if (!status) { 303 psAbort("failed to lookup value for done column"); 304 } 305 306 if ((!pxNodeHasChildren(node)) && (!done)) { 307 // if this node has no child and it's not 'done', then push it's data 308 // onto the void *array 309 psArrayAdd((psArray *)arg, 0, node->data); 310 return false; 311 } 312 313 return true; 314 } 315 316 317 bool findReadyNodes(void *arg, pxNode *node) 318 { 319 320 if (pxNodeHasChildren(node)) { 321 psListIterator *iter = psListIteratorAlloc(node->children, 0, false); 322 psMetadata *work = psMetadataCopy(NULL, node->data); 323 psMetadataRemoveKey(work, "dep"); 324 psMetadataRemoveKey(work, "done"); 325 psMetadataRemoveKey(work, "uri"); 326 pxNode *child = NULL; 327 while ((child = psListGetAndIncrement(iter))) { 328 psMetadata *data = child->data; 329 330 bool status = false; 331 psS32 done = psMetadataLookupS32(&status, data, "done"); 332 if (!status) { 333 psAbort("failed to lookup value for done column"); 334 } 335 336 if (!done) { 337 // if a child isn't "done", give up on this node and continue 338 // to crawl the tree 339 psFree(iter); 340 psFree(work); 341 return true; 342 } 343 344 char *uri = psMetadataLookupStr(&status, data, "uri"); 345 if (!status) { 346 psAbort("failed to lookup value for uri column"); 347 } 348 349 psMetadataAddStr(work, PS_LIST_TAIL, "uri", PS_META_DUPLICATE_OK, NULL, uri); 350 351 } 352 psFree(iter); 353 // if all this nodes children are done, then push it's data onto the 354 // void *array 355 psArrayAdd((psArray *)arg, 0, work); 356 psFree(work); 357 return false; 358 } 359 360 return true; 361 } 362 363 298 364 static bool toprocessMode(pxConfig *config) 299 365 { … … 307 373 } 308 374 309 psString query = pxDataGet("magictool_toprocess.sql"); 375 // look for "inputs" that need to processed 376 psString query = pxDataGet("magictool_toprocess_inputs.sql"); 310 377 if (!query) { 311 378 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 346 413 if (!psArrayLength(output)) { 347 414 psTrace("magictool", PS_LOG_INFO, "no rows found"); 348 psFree(output); 415 // psFree(output); 416 // return true; 417 } 418 419 // look for tree nodes that need to be processed 420 query = pxDataGet("magictool_toprocess_tree.sql"); 421 if (!query) { 422 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 423 return false; 424 } 425 426 427 if (magic_id) { 428 psMetadata *where = psMetadataAlloc(); 429 psMetadataAddS64(where, PS_LIST_TAIL, "magic_id", 0, "==", (psS64)atoll(magic_id)); 430 psString whereClause = psDBGenerateWhereSQL(where, NULL); 431 psFree(where); 432 psStringAppend(&query, " %s", whereClause); 433 psFree(whereClause); 434 } 435 436 if (!p_psDBRunQuery(config->dbh, query)) { 437 psError(PS_ERR_UNKNOWN, false, "database error"); 438 psFree(query); 439 return false; 440 } 441 psFree(query); 442 443 psArray *magicTree = p_psDBFetchResult(config->dbh); 444 if (!output) { 445 psErrorCode err = psErrorCodeLast(); 446 switch (err) { 447 case PS_ERR_DB_CLIENT: 448 psError(PXTOOLS_ERR_SYS, false, "database error"); 449 case PS_ERR_DB_SERVER: 450 psError(PXTOOLS_ERR_PROG, false, "database error"); 451 default: 452 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 453 } 454 455 return false; 456 } 457 if (!psArrayLength(magicTree)) { 458 psTrace("magictool", PS_LOG_INFO, "no rows found"); 459 psFree(magicTree); 349 460 return true; 350 461 } 351 352 psMetadata *deps = psMetadataAlloc(); 353 // convert the array of metadata into a single flat metadata 354 for (long i = 0; i < psArrayLength(output); i++) { 355 psMetadataCopy(deps, output->data[i]); 356 } 462 463 psHash *forest = psHashAlloc(psArrayLength(magicTree)); 464 465 // convert the array of metadata into a pxTree structure 466 for (long i = 0; i < psArrayLength(magicTree); i++) { 467 psString node = psMetadataLookupStr(&status, magicTree->data[i], "node"); 468 if (!status) { 469 psAbort("failed to lookup value for node column"); 470 } 471 472 psString dep = psMetadataLookupStr(&status, magicTree->data[i], "dep"); 473 if (!status) { 474 psAbort("failed to lookup value for dep column"); 475 } 476 477 pxTreeBuilder(forest, node, dep, magicTree->data[i]); 478 479 } 480 psFree(magicTree); 481 482 // find the root of the tree 483 pxNode *root = psHashLookup(forest, "root"); 484 psFree(forest); 485 486 pxTreePrint(stdout, root); 487 // crawl through the tree and look for un-"done" bottom nodes 488 // pxTreeCrawl(root, findBaseNodes, work); 489 490 // crawl through the tree and looking for nodes with children that are all 491 // "done" 492 pxTreeCrawl(root, findReadyNodes, output); 493 psFree(root); 494 495 bool simple = false; 496 { 497 bool status = false; 498 simple = psMetadataLookupBool(&status, config->args, "-simple"); 499 if (!status) { 500 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 501 return false; 502 } 503 } 504 505 if (psArrayLength(output)) { 506 if (!convertIdToStr(output)) { 507 psError(PS_ERR_UNKNOWN, false, "failed to convert id fields into a strings"); 508 psFree(output); 509 return false; 510 } 511 512 // negative simple so the default is true 513 if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) { 514 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 515 psFree(output); 516 return false; 517 } 518 } 519 357 520 psFree(output); 358 359 pxNode *root = pxTreeFromMetadata(deps);360 psFree(deps);361 362 // silence unused warnings...363 if (root) {}364 521 365 522 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
