static void ClearTree() { LE_INFO("---- Clearing Out Current Tree -----------------------------------------------------"); le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn(TestRootDir); LE_FATAL_IF(iterRef == NULL, "Test: %s - Could not create iterator.", TestRootDir); DumpTree(iterRef, 0); le_cfg_DeleteNode(iterRef, ""); le_cfg_CommitTxn(iterRef); iterRef = le_cfg_CreateReadTxn(TestRootDir); DumpTree(iterRef, 0); le_cfg_CancelTxn(iterRef); }
void DumpTree(SObject* root, int depth) { for ( int i = 0; i < depth; i++ ) FLASHOUTPUT(" "); FLASHOUTPUT("Type=%i Name=%s addr=%X\n", root->character ? root->character->type : -1, root->name ? root->name : "", root); for ( SObject* obj = root->bottomChild; obj; obj = obj->above ) DumpTree(obj, depth+1); }
/* verification */ extern void CGDone( n *nd ) { /*******************************/ // CGError( "OOPS!" ); Action( "CGDone( %t )%n%n", nd ); VerNode( nd ); DumpTree( nd ); NoDanglers(); }
NS_IMETHODIMP nsFrameUtil::DumpRegressionData(FILE* aInputFile, FILE* aOutputFile) { Node* tree1 = Node::ReadTree(aInputFile); if (nsnull != tree1) { DumpTree(tree1, aOutputFile, 0); Node::Destroy(tree1); return NS_OK; } return NS_ERROR_FAILURE; }
void ReflectionParser::DumpTree(Cursor const & cursor, size_t level, std::stringstream & outData) { outData << "\n"; for (size_t i = 0; i < level; ++i) outData << "-"; outData << cursor.GetDisplayName() << ", " << cursor.GetKind(); for (auto &child : cursor.GetChildren()) { DumpTree(child, level + 1, outData); } }
NS_IMETHODIMP nsFrameUtil::CompareRegressionData(FILE* aFile1, FILE* aFile2,PRInt32 aRegressionOutput) { Node* tree1 = Node::ReadTree(aFile1); Node* tree2 = Node::ReadTree(aFile2); nsresult rv = NS_OK; if (!CompareTrees(tree1, tree2)) { // only output this if aRegressionOutput is 0 if( 0 == aRegressionOutput ){ printf("Regression data 1:\n"); DumpTree(tree1, stdout, 0); printf("Regression data 2:\n"); DumpTree(tree2, stdout, 0); } rv = NS_ERROR_FAILURE; } Node::Destroy(tree1); Node::Destroy(tree2); return rv; }
void nsFrameUtil::DumpTree(Node* aNode, FILE* aOutputFile, PRInt32 aIndent) { while (nsnull != aNode) { DumpNode(aNode, aOutputFile, aIndent); nsFrameUtil::NodeList* lists = aNode->lists; if (nsnull != lists) { while (nsnull != lists) { nsFrame::IndentBy(aOutputFile, aIndent); fprintf(aOutputFile, " list: %s\n", lists->name ? lists->name : "primary"); DumpTree(lists->node, aOutputFile, aIndent + 1); lists = lists->next; } } aNode = aNode->next; } }
static void DumpTree(le_cfg_IteratorRef_t iterRef, size_t indent) { if (le_arg_NumArgs() == 1) { return; } static char strBuffer[STR_SIZE] = { 0 }; do { size_t i; for (i = 0; i < indent; i++) { printf(" "); } le_cfg_GetNodeName(iterRef, "", strBuffer, STR_SIZE); le_cfg_nodeType_t type = le_cfg_GetNodeType(iterRef, ""); switch (type) { case LE_CFG_TYPE_STEM: printf("%s/\n", strBuffer); le_cfg_GoToFirstChild(iterRef); DumpTree(iterRef, indent + 2); le_cfg_GoToParent(iterRef); break; case LE_CFG_TYPE_EMPTY: printf("%s~~\n", strBuffer); break; default: printf("%s<%s> == ", strBuffer, NodeTypeStr(iterRef)); le_cfg_GetString(iterRef, "", strBuffer, STR_SIZE, ""); printf("%s\n", strBuffer); break; } } while (le_cfg_GoToNextSibling(iterRef) == LE_OK); }
// ------------------------------------------------------------------------------------------------- static int HandleGetUserFriendly ( const char* nodePathPtr ///< Path to the node in the tree. ) // ------------------------------------------------------------------------------------------------- { // Start a read transaction at the specified node path. Then dump the value, (if any.) le_cfg_IteratorRef_t iterRef = le_cfg_CreateReadTxn(nodePathPtr); switch (le_cfg_GetNodeType(iterRef, "")) { case LE_CFG_TYPE_EMPTY: // Nothing to do here. break; case LE_CFG_TYPE_STEM: DumpTree(iterRef, 0); break; case LE_CFG_TYPE_BOOL: if (le_cfg_GetBool(iterRef, "", false)) { printf("true\n"); } else { printf("false\n"); } break; default: { char nodeValue[LE_CFG_STR_LEN_BYTES] = ""; le_cfg_GetString(iterRef, "", nodeValue, LE_CFG_STR_LEN_BYTES, ""); printf("%s\n", nodeValue); } break; } le_cfg_CancelTxn(iterRef); return EXIT_SUCCESS; }
static void DeleteTest() { static char pathBuffer[STR_SIZE] = { 0 }; snprintf(pathBuffer, STR_SIZE, "%s/deleteTest/", TestRootDir); le_cfg_IteratorRef_t iterRef = le_cfg_CreateWriteTxn(pathBuffer); le_cfg_SetString(iterRef, "valueA", "aNewValue"); le_cfg_SetString(iterRef, "valueB", "aNewValue"); le_cfg_SetString(iterRef, "valueC", "aNewValue"); TestValue(iterRef, "valueA", "aNewValue"); TestValue(iterRef, "valueB", "aNewValue"); TestValue(iterRef, "valueC", "aNewValue"); le_cfg_CommitTxn(iterRef); iterRef = le_cfg_CreateWriteTxn(pathBuffer); le_cfg_DeleteNode(iterRef, "valueB"); TestValue(iterRef, "valueA", "aNewValue"); TestValue(iterRef, "valueB", ""); TestValue(iterRef, "valueC", "aNewValue"); le_cfg_CommitTxn(iterRef); iterRef = le_cfg_CreateReadTxn(pathBuffer); TestValue(iterRef, "valueA", "aNewValue"); TestValue(iterRef, "valueB", ""); TestValue(iterRef, "valueC", "aNewValue"); DumpTree(iterRef, 0); le_cfg_CancelTxn(iterRef); }
void CMagpieApplication::ExecutingModule::DumpTree(INT tabId) { CHAR fileName[128]; sprintf(fileName, "c:\\temp\\magpie-modules.%i.log", tabId); HANDLE hFile = CreateFileA(fileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { return; } SetFilePointer(hFile, 0, NULL, FILE_END); CHAR msg[128]; sprintf(msg, "==================================================\r\n"); DWORD w; WriteFile(hFile, msg, strlen(msg), &w, NULL); DumpTree(-1, hFile); // don't display root element, its meaningless CloseHandle(hFile); }
void vDisplay(char *cmd) { DumpTree(); } // vDisplay
void Module::DumpTree (const string& file, Module* mod,int ichild, int level) { //root node redirects output buffer, if filename is given streambuf* sobuf = 0; std::ofstream* pfout = 0; if (mod ==NULL) { mod=this; if (!file.empty()) { sobuf = cout.rdbuf(); // Save the original stdout buffer. pfout = new ofstream(file.c_str()); if (*pfout) cout.rdbuf(pfout->rdbuf()); // Redirect cout output to the opened file. } } //Dump info on this module vector<Module*> children = mod->GetChildren(); stringstream spaces_bef; for (int j=0;j<level;++j) spaces_bef << " "; stringstream spaces_aft; for (int j=level; j<m_seq_tree->GetDepth(); ++j) spaces_aft << " "; if (ichild<0) { cout << endl << " Static Events-------> "; } else { if (ichild) cout << spaces_bef.str() << "|_ child " << ichild << " "; else cout << "dump of sequence tree\n" << spaces_aft.str() << " TYPE CLASS NAME duration ADCs TPOIs | module specific\n" << spaces_aft.str() << " ----------------------------------------------------------------- | ---------------\n" << "sequence-root"; for (int j=level; j<m_seq_tree->GetDepth(); ++j) cout << "--"; cout << "> "; } string class_type = mod->GetClassType(); string name = mod->GetName(); transform(class_type.begin(), class_type.end(), class_type.begin(), (int(*)(int)) toupper); string type; int adcs = 0; if (mod->GetType() == MOD_CONCAT) { type="CONCAT"; adcs=((Sequence*) mod)->GetNumOfADCs(); } if (mod->GetType() == MOD_ATOM) { type="ATOM"; adcs=((Sequence*) mod)->GetNumOfADCs(); } if (mod->GetType() == MOD_PULSE) { type="PULSE"; adcs=((Pulse*) mod)->GetNADC() ; } int tpois = mod->GetNumOfTPOIs(); char chform[70]; sprintf(chform,"%8s %20s %8s %9.3f %7d %8d",type.c_str(),class_type.c_str(),name.c_str(),mod->GetDuration(),adcs,tpois); cout << chform << " | " << mod->GetInfo() << "\n"; level++; for (unsigned int i=0; i<children.size() ; ++i) DumpTree(file, mod->GetChild(i),i+1,level); // the static Atom World* pW = World::instance(); if (ichild == 0 && pW->pStaticAtom != NULL ) { DumpTree(file, ((Module*) pW->pStaticAtom),-1,level); } // root node restores cout to original state. if (ichild == 0 && !file.empty() ) { cout.rdbuf(sobuf); delete pfout; } }
int main(int argc, char ** argv) { int i; FILE * in = NULL; FILE * out = NULL; byte * pb = NULL; size_t cb = 0; byte rgb[2048]; size_t cbIn; int forXML = false; FOO * root = NULL; for (i=1; i<argc; i++) { if ((argv[i][0] == '-') || (argv[i][0] == '/')) { if (strcmp(&argv[i][1], "someoption") == 0) { } else if (strcmp(&argv[i][1], "xml=yes") == 0) { forXML = true; } else if (strcmp(&argv[i][1], "xml=no") == 0) forXML = false; else if (strncmp(&argv[i][1], "wrap=", 5) == 0) { WrapLineAt = atoi(&argv[i][6]); } else if (strncmp(&argv[i][1], "type=", 5) == 0) { if (strcmp(&argv[i][1], "type=encrypt") == 0) root = &EncryptedMessage; else if (strcmp(&argv[i][1], "type=envelope") == 0) root = &EnvelopedMessage; else if (strcmp(&argv[i][1], "type=signed") == 0) root = &SignedMessage; else if (strcmp(&argv[i][1], "type=mac") == 0) root = &MacMessage; else if (strcmp(&argv[i][1], "type=mac0") == 0) root = &Mac0Message; else if (strcmp(&argv[i][1], "type=keyset") == 0) root = &KeySet; else if (strcmp(&argv[i][1], "type=key") == 0) root = &Key; else PrintUsage(); } else { PrintUsage(); exit(1); } } else { if (in == NULL) { in = fopen(argv[i], "rb"); if (in == NULL) { fprintf(stderr, "Unable to open file '%s'\n", argv[i]); exit(1); } } else if (out == NULL) { out = fopen(argv[i], "wt"); if (out == NULL) { fprintf(stderr, "Unable to open file '%s'\n", argv[i]); exit(1); } } else { PrintUsage(); exit(1); } } } // Set defaults if (in == NULL) { #ifdef _WIN32 in = stdin; _setmode(_fileno(stdin), _O_BINARY); #else in = stdin; // fdreopen(_fileno(stdin), NULL, O_RDONLY | OPEN_O_BINARY); #endif } if (out == NULL) out = stdout; // Read the input to a buffer - needed for the parser cbIn = 1; while (cbIn > 0) { cbIn = fread(rgb, 1, sizeof(rgb), in); if (cbIn == 0) { // finished break; } pb = realloc(pb, cb+cbIn); if (pb == NULL) { fprintf(stderr, "Error allocating memory\n"); exit(1); } memcpy(pb+cb, rgb, cbIn); cb += cbIn; } // Parse it cn_cbor * cbor = cn_cbor_decode(pb, cb CBOR_CONTEXT_PARAM, NULL); if (cbor == NULL) { fprintf(stderr, "Error parsing CBOR"); exit(1); } if (root == NULL) { if (cbor->type == CN_CBOR_TAG) { switch (cbor->v.sint) { case 98: root = &SignedMessageWithTag; break; case 96: root = &EnvelopedMessageWithTag; break; case 16: root = &EncryptedMessageWithTag; break; case 97: root = &MacMessageWithTag; break; case 17: root = &Mac0MessageWithTag; break; case 18: root = &Sign0MessageWithTag; break; } } } if (forXML) { fprintf(out, "<t>Size of binary file is %lu bytes</t>\n\n", (unsigned long) cb); fprintf(out, "<figure><artwork type='CBORdiag'><![CDATA[\n"); } DumpTree(cbor, out, root, 0, true, true, false); WrapPrintF(out, "\n"); if (forXML) { fprintf(out, "]]></artwork></figure>\n"); } }
void DumpTree(const cn_cbor * cbor, FILE * out, const FOO *pFOO, int depth, int fField, int fValue, int fInComment) { int i; int i2; const cn_cbor * cbor2; const FOO * pFoo2; int group; if (pFOO != NULL) { switch (pFOO->type) { case CN_CBOR_TAG: if (cbor->type != CN_CBOR_TAG) pFOO = NULL; break; default: break; } } if (fField && (pFOO != NULL) && (pFOO->fieldName != NULL)) { if (fInComment) WrapPrintF(out, "\\ %s \\ ", pFOO -> fieldName); else WrapPrintF(out, "/ %s / ", pFOO->fieldName); } switch (cbor->type) { case CN_CBOR_TAG: WrapPrintF(out, "%u(\n", cbor->v.uint); Indent(out, depth + 1); DumpTree(cbor->last_child, out, pFOO != NULL ? pFOO->children : NULL, depth+1, true, true, fInComment); WrapPrintF(out, "\n"); Indent(out, depth); WrapPrintF(out, ")"); break; case CN_CBOR_ARRAY: WrapPrintF(out, "["); cbor2 = cbor->first_child; for (i = 0; i < cbor->length; i++, cbor2 = cbor2->next) { if (i != 0) WrapPrintF(out, ", "); if (pFOO == NULL) pFoo2 = NULL; else if (pFOO->count == 1) pFoo2 = pFOO->children; else if (i >= pFOO->count) pFoo2 = NULL; else pFoo2 = &pFOO->children[i]; WrapPrintF(out, "\n"); Indent(out, depth + 1); DumpTree(cbor2, out, pFoo2, depth + 1, true, true, fInComment); } if (i > 0) { WrapPrintF(out, "\n"); Indent(out, depth); } WrapPrintF(out, "]"); break; case CN_CBOR_MAP: WrapPrintF(out, "{"); cbor2 = cbor->first_child; // Determine the correct group - always assume it is at element UINT=1 group = 0; for (i = 0; i < cbor->length; i+=2, cbor2 = cbor2->next->next) { if ((cbor2->type == CN_CBOR_UINT) && (cbor2->v.uint == 1)) { group = (int) cbor2->next->v.uint; break; } } cbor2 = cbor->first_child; // Dump each element for (i = 0; i < cbor->length; i+=2, cbor2 = cbor2->next) { pFoo2 = NULL; if (pFOO != NULL) { // Locate the right entry in foo for (i2 = 0, pFoo2 = pFOO->children; i2 < pFOO->count; pFoo2++, i2 += 1) { if (pFoo2->type != cbor2->type) continue; switch (cbor2->type) { case CN_CBOR_UINT: if ((group != 0) && (pFoo2->group != 0) && (pFoo2->group != group)) continue; if (pFoo2->value == (int) cbor2->v.uint) i2 = pFOO->count + 1; break; case CN_CBOR_INT: if ((group != 0) && (pFoo2->group != 0) && (pFoo2->group != group)) continue; if (pFoo2->value == cbor2->v.sint) i2 = pFOO->count + 1; break; default: // Should assert here? break; } if (i2 == pFOO->count + 1) break; } if (i2 == pFOO->count) pFoo2 = NULL; } if (i != 0) WrapPrintF(out, ", "); WrapPrintF(out, "\n"); Indent(out, depth + 1); DumpTree(cbor2, out, pFoo2, depth + 1, true, false, fInComment); WrapPrintF(out, ":"); cbor2 = cbor2->next; DumpTree(cbor2, out, pFoo2, depth + 1, false, true, fInComment); } if (i > 0) { WrapPrintF(out, "\n"); Indent(out, depth); } WrapPrintF(out, "}"); break; case CN_CBOR_BYTES: DumpBytes(out, cbor); if ((pFOO != NULL) && (pFOO->children != NULL)) { const cn_cbor * cbor3 = cn_cbor_decode(cbor->v.bytes, cbor->length CBOR_CONTEXT_PARAM, NULL); if (cbor3 != NULL) { WrapPrintF(out, fInComment ? " \\ " : " / "); DumpTree(cbor3, out, pFOO->children, depth+1, true, true, true); WrapPrintF(out, fInComment ? " \\ " : " / "); } } break; case CN_CBOR_INT: WrapPrintF(out, "%d", cbor->v.sint); if (fValue && pFOO != NULL) { for (i = 0, pFoo2 = pFOO->children; i < pFOO->count; i++, pFoo2++) { if ((pFoo2->type == CN_CBOR_INT) && (pFoo2->value == cbor->v.sint)) { if (pFoo2->fieldName != NULL) { if (fInComment) WrapPrintF(out, " \\ %s \\", pFoo2->fieldName); else WrapPrintF(out, " / %s /", pFoo2->fieldName); } break; } } } break; case CN_CBOR_UINT: WrapPrintF(out, "%u", cbor->v.uint); if (fValue && (pFOO != NULL)) { for (i = 0, pFoo2 = pFOO->children; i < pFOO->count; i++, pFoo2++) { if ((pFoo2->type == CN_CBOR_UINT) && (pFoo2->value == (int) cbor->v.uint)) { if (pFoo2->fieldName != NULL) { if (fInComment) WrapPrintF(out, " \\ %s \\", pFoo2->fieldName); else WrapPrintF(out, " / %s /", pFoo2->fieldName); } break; } } } break; case CN_CBOR_TEXT: WrapPrintF(out, "\""); for (i = 0; i < cbor->length; i++) { if (fInComment && (cbor->v.str[i] == '/')) { WrapPrintF(out, "%c", cbor->v.str[i]); } WrapPrintF(out, "%c", cbor->v.str[i]); } WrapPrintF(out, "\""); break; case CN_CBOR_TRUE: WrapPrintF(out, "true"); break; case CN_CBOR_FALSE: WrapPrintF(out, "false"); break; default: WrapPrintF(out, "##"); break; } }
// ------------------------------------------------------------------------------------------------- static void DumpTree ( le_cfg_IteratorRef_t iterRef, ///< Write out the tree pointed to by this iterator. size_t indent ///< The amount of indentation to use for this item. ) // ------------------------------------------------------------------------------------------------- { // Note that because this is a recursive function, the buffer here is static in order to save on // stack space. The implication here is that we then have to be careful how it is later // accessed. Also, this makes the function not thread safe. But this trade off was made as // this was not intended to be a multi-threaded program. static char strBuffer[LE_CFG_STR_LEN_BYTES] = ""; do { // Quick and dirty way to indent the tree item. size_t i; for (i = 0; i < indent; i++) { printf(" "); } // Simply grab the name and the type of the current node. le_cfg_GetNodeName(iterRef, "", strBuffer, LE_CFG_STR_LEN_BYTES); le_cfg_nodeType_t type = le_cfg_GetNodeType(iterRef, ""); switch (type) { // It's a stem object, so mark this item as being a stem and recurse into the stem's // sub-items. case LE_CFG_TYPE_STEM: printf("%s/\n", strBuffer); le_cfg_GoToFirstChild(iterRef); DumpTree(iterRef, indent + 2); le_cfg_GoToParent(iterRef); // If we got back up to where we started then don't iterate the "root" node's // siblings. if (indent == 0) { return; } break; // The node is empty, so simply mark it as such. case LE_CFG_TYPE_EMPTY: printf("%s<empty>\n", strBuffer); break; case LE_CFG_TYPE_BOOL: { char* value = NULL; if (le_cfg_GetBool(iterRef, "", false)) { value = "true"; } else { value = "false"; } printf("%s<bool> == %s\n", strBuffer, value); } break; // The node has a different type. So write out the name and the type. Then print the // value. default: printf("%s<%s> == ", strBuffer, NodeTypeStr(le_cfg_GetNodeType(iterRef, ""))); le_cfg_GetString(iterRef, "", strBuffer, LE_CFG_STR_LEN_BYTES, ""); printf("%s\n", strBuffer); break; } } while (le_cfg_GoToNextSibling(iterRef) == LE_OK); }
//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TMainForm::LoadFile( void ) { int bStatus; // Can we open the file ? if( (fd = fopen( OpenDialog1->FileName.c_str(), "rb") ) == NULL ) { MsgBoxStop( "Cannot open input file\n\n" + OpenDialog1->FileName ); return; } pnlChunks->Caption = ""; strList->Clear(); ListBoxChunks->Clear(); RichEditChunks->Clear(); RichEditReport->Clear(); ProgressBar1->Min = 0; ProgressBar1->Position = 0; SetChunkCount( 0 ); RichEditReport->Lines->Add( "" ); RichEditReport->Lines->Add( "Chunk contents of file :" ); RichEditReport->Lines->Add( OpenDialog1->FileName ); RichEditReport->Lines->Add( "" ); // Make report pane visible - prove we are working and not locked up PageControl1->ActivePage = tsReport; try { StaticTextStatus->Caption = "Working ... please wait"; StaticTextStatus->Update(); bStatus = DumpTree(); // true indicates success } __finally { ProgressBar1->Position = 0; StaticTextStatus->Caption = "Ok"; fclose( fd ); fd = NULL; } if( !bStatus ) // We have an error { pnlChunks->Caption = ""; strList->Clear(); ListBoxChunks->Clear(); RichEditChunks->Clear(); RichEditReport->Lines->Add(""); RichEditReport->Lines->Add("An error occurred while reading the file."); } else { // Read file and chunks without any problems // Set Report Panels caption pnlChunks->Caption = "Chunk 1 of " + String( ListBoxChunks->Items->Count ); // Set Listbox to first item ListBoxChunks->ItemIndex = 0; // Put gleeful message in report pane RichEditChunks->Lines->Add( "" ); RichEditChunks->Lines->Add( "No error's found when reading file ... " ); RichEditChunks->Lines->Add( "Click the list box to display the data for each chunk."); // Place cursor at top of editor RichEditChunks->SelStart = 0; RichEditChunks->SelLength = 0; // Place cursor at top of editor RichEditReport->SelStart = 0; RichEditReport->SelLength = 0; // Lock richedits - so an immediate undo does not make data vanish ! RichEditReport->Modified = false; // @ap@ Borland should fix this ! (it don't work) } }