Exemplo n.º 1
0
void Tree::showTree(node* n){
	if(n!=NULL){
		showTree(n->left);
		showTree(n->right);
		std::cout << " " << n->key.second << " ";
	}
}
Exemplo n.º 2
0
bool testCase(int *num, int numsSize) {
    struct TreeNode *root = buildTree(num, numsSize);
    showTree(root);

    // How to use serialize and deserialize
    char *data = serialize(root);
    struct TreeNode *node = deserialize(data);

    printf("serialize to [%s]\n", data);
    bool r = eqTree(root, node);
    printf("deserialize to\n");
    if (!r) {
        showTree(node);
    } else {
        printf("same\n");
    }
    printf("%s\n", expect(r));

    freeTree(root);
    freeTree(node);
    if (data) {
        free(data);
    }
    return r;
}
Exemplo n.º 3
0
Arquivo: BST.cpp Projeto: maxchv/cpp
	void showTree(Leaf *cur)
	{
		if (cur)
		{
			showTree(cur->right);
			cout << *cur << " ";
			showTree(cur->left);
		}
	}
 void OutputItemContentWidget::refreshOutputItem()
 {
     switch(_viewMode) {
     case Text: showText(); break;
     case Tree: showTree(); break;
     case Table: showTable(); break;
     case Custom: showCustom(); break;
     default: showTree();
     }
 }
Exemplo n.º 5
0
int main(void)
{
    TreeNode *tree1, *tree2;
    tree1 = createTree( tree1 );
    tree2 = createTree( tree2 );
    _Bool equal;
    equal = CompTree( tree1, tree2 );   
    printf("equal = %d\n", equal );
    showTree( tree1 );
    showTree( tree2 );
    return 0;
}
Exemplo n.º 6
0
void HTMLParser	::	showTree( const TNodeShared aNode, int aSpacing )	{
	
	TNodeListShared children = aNode->getChildNodes();
	int length = children->getLength();
	if ( length != 0 )	{
		for ( int i = 0; i < length; i++ )	{
			TNodeShared child = make_shared( children->item( i ) );
			for ( int j = 0; j < aSpacing; j++ )	{
				cout << "  ";
			}
			cout << "Child name: " << child->getNodeName().c_str() << endl;
			if ( child->getNodeType() == ELEMENT_NODE )	{
				// Check for attributes
				TNamedNodeMapShared attributes = child->getAttributes();
				for ( unsigned int j = 0; j < attributes->getLength(); j++ )	{
					TNodeWeak attr = attributes->item( j );
					TNodeShared tempAttr = make_shared( attr );
					for ( int j = 0; j < aSpacing + 1; j++ )	{
						cout << "  ";
					}
					cout << "Attribute " << tempAttr->getNodeName();
					cout << " with value " << tempAttr->getNodeValue() << endl;
				}
			}
			showTree( child, aSpacing + 1 );
		}
	}	
}
    void OutputItemContentWidget::showCustom()
    {
        if (!_isCustomModeSupported) {
            // try to downgrade to tree mode
            showTree();
            return;
        }

        QWidget *customWidget = NULL;

        if (!_isCustomModeInitialized) {

            if (_type == "collectionStats") {
                _collectionStats = new CollectionStatsTreeWidget(_shell);
                _collectionStats->setDocuments(_documents);
                customWidget = _collectionStats;
            }

            if (customWidget)
                _stack->addWidget(_collectionStats);
            _isCustomModeInitialized = true;
        }

        if (_collectionStats)
            _stack->setCurrentWidget(_collectionStats);
    }
Exemplo n.º 8
0
void SGMLParser :: showTree(const TNodePtr aNode, int aSpacing) {
	
	TNodeListPtr children = aNode->getChildNodes();
	int length = children->getLength();
	if ( length != 0 )	{
		for ( int i = 0; i < length; i++ )	{
			TNodePtr child = children->item( i );
			for ( int j = 0; j < aSpacing; j++ )	{
				printf("  ");
			}
			printf("Child name: %s\n", child->getNodeName().c_str());
			if ( child->getNodeType() == ELEMENT_NODE )	{
				// Check for attributes
				TNamedNodeMapPtr attributes = child->getAttributes();
				for ( unsigned int j = 0; j < attributes->getLength(); j++ )	{
					TNodePtr attr = attributes->item( j );
					for ( int j = 0; j < aSpacing + 1; j++ )	{
						printf("  ");
					}
					printf("Attribute %s", attr->getNodeName().c_str());
					printf(" with value %s\n", attr->getNodeValue().c_str());
				}
			}
			showTree( child, aSpacing + 1 );
		}
	}	
}
Exemplo n.º 9
0
static void showMacro(register symbol *p)
{  if (p)
   {  showMacro(p->left);
      fprintf(stderr,"%s\n\n",p->name);
      showTree(4,NULL,p->val);
      showMacro(p->right);
   }
}
Exemplo n.º 10
0
//
//recursively walk through tree and show node names with indentation
//
void XMLNode::showTree(XMLNode* node, int indent) const{
  indent++;
  if( (node!=0) && (node->size()>0) ){
    for( XMLNode::const_iterator i=node->begin(); i!= node->end(); ++i ){
      (*i)->show( indent );
      showTree( *i , indent );
    }
  }
}
Exemplo n.º 11
0
ostream& Btree<T>::TextWrite(ostream& Os_, Boolean* Ok_) const
{
  Boolean Dum_;
  if (!Ok_)
    Ok_ = &Dum_;

  *Ok_ = showTree(*this, Os_);
  return Os_;
}
void showTree(node* root, int level)
{
	int i = 0;

	if(!root->isLeaf)
	{
		for (i = 0; i < level; i++)
		{
			printf(" ");
		}
		
		level++;

		showTree(root->left, level);
		showTree(root->right, level);
	}
	else
	{
		printf("level: "); printf("%d", level);
		printf(" node:[ "); printf("%d ", root->leafVector[0]); printf(" %d]\n", root->leafVector[1]);

	}
}
Exemplo n.º 13
0
void showTree(int n, char *m, node *p)
{   node *q;

    if (p)
    {   if (m)
	  fprintf(stderr,"%s",m);
	else
	  fprintf(stderr,"(null)");
	space(stderr,n);
	showFlavour(stderr,p);
	showLocation(stderr,p);
	fprintf(stderr,"\n");
        q = p->Lson;
        while (q)
        {   showTree(n+2,m,q);
            q = q->Rbro;
        }
    }
}
Exemplo n.º 14
0
int main(int argc, char ** argv)
{
    treeNode * root = createTree();
    if (!root)
        return -1;
    printf("\n------------------\n");
    LDRTree(root);
    printf("\n------------------\n");
    DLRTree(root);
    printf("\n------------------\n");
    LRDTree(root);

    printf("\n叶子结点个数 %d\n", leafnum(root));
    printf("\n二叉树层高 %d\n", getMaxLevel(root));

    showTree(root);

    return 0;
}
Exemplo n.º 15
0
 //! \brief Returns a string representation of the loaded configuration tree
 std::string showFullTree() { return showTree(m_root); }
int main(void)
{
	char inputMenu;
	char inputData;
	int menu = 0;
	int type;

	while (1)
	{
		printf("-----------------------\n");
		printf("1. Insert a Node\n");
		printf("2. Delete a Node\n");
		printf("3. Destroy BST\n");
		printf("4. Find a Node\n");
		printf("5. Tree Traverse\n");
		printf("6. Show the height of tree\n");
		printf("7. Show the shape of Tree\n");
		printf("8. Make the completed BST\n");
		printf("9. Cut Tree\n");
		printf("0. Exit\n");
		printf("-----------------------\n");
		printf("->");

		fgets(&inputMenu, 3, stdin);
		menu = atoi(&inputMenu);

		switch (menu) {

		case 1:
			printf("Type the value to insert\n");
			printf("->");
			fgets(&inputData, 3, stdin);

			insertNode(inputData);

			break;

		case 2:
			printf("Type the node id to delete\n");
			printf("->");
			fgets(&inputData, 3, stdin);

			deleteNode(inputData);

			break;

		case 3:
			destroyBST();

			break;

		case 4:
			printf("Type the node id to find\n");
			printf("->");
			fgets(&inputData, 3, stdin);

			findNode(inputData);

			break;

		case 5:
			printf("Type the type of Tree Traversal (0: Pre-order, 1: In-order, 2: Post-order)\n");
			printf("->");
			fgets(&inputData, 3, stdin);
			type = atoi(&inputData);
			printf("Type the node id to start Traverse\n");
			printf("->");
			fgets(&inputData, 3, stdin);

			treeTraversal(type, inputData);

			break;

		case 6:
			findHeight();

			break;

		case 7:
			showTree();

			break;

		case 8:
			makeCompleteBST();

			break;

		case 9:
			printf("Type the node id that will become the new root node\n");
			printf("->");
			fgets(&inputData, 3, stdin);

			cutTree(inputData);

			break;

		case 0:
			exit(0);

			break;

		default:
			printf("Input should be 0-9\n");
			break;
		}
	}


	return 0;
}
Exemplo n.º 17
0
void HTMLParser	::	showDocument()	{
	
	cout << "Document layout...\n";
	showTree( mDocument, 1 );

}
Exemplo n.º 18
0
Arquivo: BST.cpp Projeto: maxchv/cpp
		void showTree()
		{
			showTree(root);
			cout << endl;
		}
Exemplo n.º 19
0
    OutputItemHeaderWidget::OutputItemHeaderWidget(OutputItemContentWidget *output, QWidget *parent) : 
        QFrame(parent),
        _maximized(false)
    {
        setContentsMargins(5,0,0,0);
        
        // Maximize button
        _maxButton = new QPushButton;
        _maxButton->setIcon(GuiRegistry::instance().maximizeIcon());
        _maxButton->setToolTip("Maximize or restore back this output result. You also can double-click on result's header.");
        _maxButton->setFixedSize(18, 18);
        _maxButton->setFlat(true);
        VERIFY(connect(_maxButton, SIGNAL(clicked()), this, SLOT(maximizePart())));

        // Text mode button
        _textButton = new QPushButton(this);
        _textButton->setIcon(GuiRegistry::instance().textIcon());
        _textButton->setToolTip("View results in text mode");
        _textButton->setFixedSize(24, 24);
        _textButton->setFlat(true);
        _textButton->setCheckable(true);

        // Tree mode button
        _treeButton = new QPushButton(this);
        _treeButton->hide();
        _treeButton->setIcon(GuiRegistry::instance().treeIcon());
        _treeButton->setToolTip("View results in tree mode");
        _treeButton->setFixedSize(24, 24);
        _treeButton->setFlat(true);
        _treeButton->setCheckable(true);
        _treeButton->setChecked(true);     

        // Table mode button
        _tableButton = new QPushButton(this);
        _tableButton->hide();
        _tableButton->setIcon(GuiRegistry::instance().tableIcon());
        _tableButton->setToolTip("View results in table mode");
        _tableButton->setFixedSize(24, 24);
        _tableButton->setFlat(true);
        _tableButton->setCheckable(true);
        _tableButton->setChecked(true);       

        // Custom mode button
        _customButton = new QPushButton(this);
        _customButton->hide();
        _customButton->setIcon(GuiRegistry::instance().customIcon());
        _customButton->setToolTip("View results in custom UI");
        _customButton->setFixedSize(24, 24);
        _customButton->setFlat(true);
        _customButton->setCheckable(true);

        VERIFY(connect(_textButton, SIGNAL(clicked()), output, SLOT(showText())));
        VERIFY(connect(_treeButton, SIGNAL(clicked()), output, SLOT(showTree())));
        VERIFY(connect(_tableButton, SIGNAL(clicked()), output, SLOT(showTable())));
        VERIFY(connect(_customButton, SIGNAL(clicked()), output, SLOT(showCustom())));

        _collectionIndicator = new Indicator(GuiRegistry::instance().collectionIcon());
        _timeIndicator = new Indicator(GuiRegistry::instance().timeIcon());
        _paging = new PagingWidget();

        _collectionIndicator->hide();
        _timeIndicator->hide();
        _paging->hide();

        QHBoxLayout *layout = new QHBoxLayout();
        layout->setContentsMargins(2, 0, 5, 1);
        layout->setSpacing(0);

        layout->addWidget(_collectionIndicator);
        layout->addWidget(_timeIndicator);
        QSpacerItem *hSpacer = new QSpacerItem(2000, 24, QSizePolicy::Preferred, QSizePolicy::Minimum);
        layout->addSpacerItem(hSpacer);
        layout->addWidget(_paging);
        layout->addWidget(createVerticalLine());
        layout->addSpacing(2);

        if (output->isCustomModeSupported()) {
            layout->addWidget(_customButton, 0, Qt::AlignRight);
            _customButton->show();
        }

        if (output->isTreeModeSupported()) {
            layout->addWidget(_treeButton, 0, Qt::AlignRight);
            _treeButton->show();
        }

        if (output->isTableModeSupported()) {
            layout->addWidget(_tableButton, 0, Qt::AlignRight);
            _tableButton->show();
        }

        if (output->isTextModeSupported())
            layout->addWidget(_textButton, 0, Qt::AlignRight);

        layout->addSpacing(3);
        layout->addWidget(createVerticalLine());
        layout->addWidget(_maxButton, 0, Qt::AlignRight);
        setLayout(layout);
    }
Exemplo n.º 20
0
void TestB()
{
	char tty_name[] = "/dev_tty1";

	int fd_stdin  = open(tty_name, O_RDWR);
	assert(fd_stdin  == 0);
	int fd_stdout = open(tty_name, O_RDWR);
	assert(fd_stdout == 1);

	char rdbuf[128];
	char cmd[8];
	char filename[120];
	char buf[1024];
	int m,n;

	initFSTree();


	printf("                        ==================================\n");
	printf("                                    File Manager           \n");
	printf("                                 Kernel on Orange's \n\n");
	printf("                        ==================================\n");
	while (1) {
		printPath();
		printf("$ :");
		int r = read(fd_stdin, rdbuf, 70);
		rdbuf[r] = 0;

		if (strcmp(rdbuf, "i") == 0)
		{
			char treeInfo[2048] = {0};
			getTreeInfo(treeInfo);
			printf("%s\n", treeInfo);
		}
		else if(strcmp(rdbuf, "s") == 0)
		{
			showTree();
		}
		else if(strcmp(rdbuf, "p") == 0)
		{
			printPath();
			printf("\n");
		}
		else if (strcmp(rdbuf, "help") == 0)
		{
			printf("=============================================================================\n");
			printf("Command List     :\n");
			printf("1. create [filename]       : Create a new file \n");
			printf("2. read [filename]         : Read the file\n");
			printf("3. write [filename]        : Write at the end of the file\n");
			printf("4. delete [filename]       : Delete the file\n");
			printf("5. help                    : Display the help message\n");
			printf("==============================================================================\n");		
		}
		else if (strcmp(rdbuf, "dir") == 0)
		{
			printCurrFile();
			continue;
		}
		else
		{
			int fd;
			int i = 0;
			int j = 0;
			char temp = -1;
			while(rdbuf[i]!=' ' && rdbuf[i] != 0)
			{
				cmd[i] = rdbuf[i];
				i++;
			}
			cmd[i++] = 0;
			while(rdbuf[i] != 0)
			{
				filename[j] = rdbuf[i];
				i++;
				j++;
			}
			filename[j] = 0;

			if(strcmp(cmd, "mkdir") == 0)
			{
				createDir(filename);

				saveTreeToDsik();
				// //write TreeRecord
				// char treeInfo[2048]={0};
				// getTreeInfo(treeInfo);
				// printf("%s\n", treeInfo);

				// fd = open("TreeRecord", O_RDWR);
				// if (fd == -1)
				// {
				// 	printf("Failed to open 'TreeRecord'!\n");
				// 	continue ;
				// }
				// strcpy(buf,treeInfo);
				// printf("buf :%s\n", buf);

				// n = write(fd, buf, 1024);
				// close(fd);

			}
			else if(strcmp(cmd, "cd") == 0)
			{
				//open dir
				if(strcmp(filename, "..") == 0)
				{
					backDir();
				}
				else
				{
					openDir(filename);
				}
			}
			else if(strcmp(cmd,"rmdir") == 0)
			{
				//delete dir
				if(isThereFile(filename) == 0)
				{
					printf("fail to remove dir, not here!\n");
					continue;
				}
				deleteDirRecord(filename);

				saveTreeToDsik();
				// //write TreeRecord
				// char treeInfo[2048]={0};
				// getTreeInfo(treeInfo);
				// printf("%s\n", treeInfo);

				// fd = open("TreeRecord", O_RDWR);
				// if (fd == -1)
				// {
				// 	printf("Failed to open 'TreeRecord'!\n");
				// 	continue ;
				// }
				// strcpy(buf,treeInfo);
				// printf("buf :%s\n", buf);

				// n = write(fd, buf, 1024);
				// close(fd);
			}
			else if (strcmp(cmd, "create") == 0)
			{
				fd = open(filename, O_CREAT | O_RDWR);
				if (fd == -1)
				{
					printf("Failed to create file! Please check the fileaname!\n");
					continue ;
				}
				buf[0] = 0;
				write(fd, buf, 1);
				printf("File created: %s (fd %d)\n", filename, fd);
				close(fd);

				//add to tree currFatherDir
				fTreeArray[treeCurrSize].currDir = treeCurrSize;
				fTreeArray[treeCurrSize].fatherDir = currFatherDir;
				fTreeArray[treeCurrSize].isDir = 0;  //not a dir
				strcpy(fTreeArray[treeCurrSize].fileName, filename);
				treeCurrSize++;
				treeCount++;

				// showTree();

				// char* treeInfo;
				// treeInfo = getTreeInfo();
				// printf("%d\n", treeCurrSize);

				saveTreeToDsik();
				// //write TreeRecord
				// char treeInfo[2048]={0};
				// getTreeInfo(treeInfo);
				// printf("%s\n", treeInfo);

				// fd = open("TreeRecord", O_RDWR);
				// if (fd == -1)
				// {
				// 	printf("Failed to open 'TreeRecord'!\n");
				// 	continue ;
				// }
				// strcpy(buf,treeInfo);
				// printf("buf :%s\n", buf);

				// n = write(fd, buf, 1024);
				// close(fd);

			}
			else if (strcmp(cmd, "read") == 0)
			{
				if(isThereFile(filename) == 0)
				{
					printf("fail to read file, not here!\n");
					continue;
				}
				fd = open(filename, O_RDWR);
				if (fd == -1)
				{
					printf("Failed to open file! Please check the fileaname!\n");
					continue ;
				}
				
				n = read(fd, buf, 1024);
				
				printf("%s\n", buf);
				close(fd);

			}
			else if (strcmp(cmd, "write") == 0)
			{
				// if(isThereFile(filename) == 0)
				// {
				// 	printf("fail to write file, not here!\n");
				// 	continue;
				// }
				fd = open(filename, O_RDWR);
				if (fd == -1)
				{
					printf("Failed to open file! Please check the fileaname!\n");
					continue ;
				}

				m = read(fd_stdin, rdbuf,80);
				rdbuf[m] = 0;
				
				n = write(fd, rdbuf, m+1);
				close(fd);


			}
			else if (strcmp(cmd, "delete") == 0)
			{
				if(isThereFile(filename) == 0)
				{
					printf("fail to delete file, not here!\n");
					continue;
				}

				m=unlink(filename);
				if (m == 0)
				{
					printf("File deleted!\n");

					//delete file from tree records, not a dir
					int i = 0;
					for (; i < treeCurrSize; ++i)
					{
						if(strcmp(fTreeArray[i].fileName,filename) == 0)
						{
							fTreeArray[i].currDir = -1;
							continue;
						}
					}
					treeCount--;
					// showTree();

					saveTreeToDsik();
					// //write TreeRecord
					// char treeInfo[2048]={0};
					// getTreeInfo(treeInfo);
					// printf("%s\n", treeInfo);

					// fd = open("TreeRecord", O_RDWR);
					// if (fd == -1)
					// {
					// 	printf("Failed to open 'TreeRecord'!\n");
					// 	continue ;
					// }
					// strcpy(buf,treeInfo);
					// printf("buf :%s\n", buf);

					// n = write(fd, buf, 1024);
					// close(fd);

					continue;
				}
				else
				{
					printf("Failed to delete file! Please check the fileaname!\n");
					continue;
				}

			}
			else 
			{
				printf("Command not found, Please check!\n");
				continue;
			}

			
			
		}
		
			
	}

	assert(0); /* never arrive here */
}
Exemplo n.º 21
0
DOMTest	::	DOMTest()	:	BApplication( "application/x-vnd.Themis-DOMTest" )	{
	
	printf( "Let's kick off!\n" );

	TDocumentPtr document( new TDocument() );
	//document->setSmartPointer( document );
	
	printf( "Create an Element\n" );
	TElementPtr scooby = document->createElement( "scooby" );
		
	printf( "Attach element to document\n" );
	document->appendChild( scooby );

	printf( "Element created\n" );
	printf( "Try to append same node\n" );
	try	{
		scooby->appendChild( scooby );
	}
	catch ( TDOMException e )	{
		printf( "Exception caught : %s\n", e.getString() );
	}

	TElementPtr element = document->createElement( "cookie" );

	printf( "Try to append an element\n" );
	try	{
		scooby->appendChild( element );
	}
	catch ( TDOMException e )	{
		printf( "Exception caught : %s\n", e.getString() );
	}

	printf( "Tag name of the element: %s\n", element->getTagName().c_str() );
	
	printf( "Add an attribute to the element\n" );
	element->setAttribute( "me", "king" );
	
	printf( "Retrieve the attribute that was just created\n" );
	printf( "Attribute me has value: %s\n", element->getAttribute( "me" ).c_str() );

	TAttrPtr attr = shared_static_cast<TAttr> ( element->getAttributes()->getNamedItem( "me" ) );
	printf( "Attribute is attached to: %s\n", attr->getOwnerElement()->getNodeName().c_str() );

	printf( "Remove attribute me through NamedNodeMap\n" );
	element->getAttributes()->removeNamedItem( "me" );
	
	if ( element->getAttribute( "me" ) == "" )	{
		printf( "Removal succesfull\n" );
	}
	else	{
		printf( "Removal failed\n" );
	}

	printf( "Adding an attribute to the element for later use\n" );
	element->setAttribute( "piet", "joe" );

	printf( "Try to append parent to node\n" );
	try	{
		element->appendChild( scooby );
	}
	catch ( TDOMException e )	{
		printf( "Exception caught : %s\n", e.getString() );
	}

	printf( "Create a text node\n" );
	//DOMPointer<TText> textNode( new TText( "Text test" ) );
	TTextPtr textNode = document->createText( "This is a test" );
	printf( "Text node created\n" );
	printf( "Try to add an element to the text node\n" );
	try	{
		textNode->insertBefore( scooby, TNodePtr() );
	}
	catch ( TDOMException e )	{
		printf( "Exception caught : %s\n", e.getString() );
	}
	
	printf( "Get the name of the text node\n" );
	printf( "Name: %s\n", textNode->getNodeName().c_str() );

	printf( "Get a node\n" );
	TNodePtr newNode = scooby->getFirstChild();
	
	printf( "Test a node for sameness\n" );
	if ( element->isSameNode( newNode ) )	{
		printf( "Nodes are the same\n" );
	}
	else	{
		printf( "Nodes are different\n" );
	}

	printf( "Get type of node\n" );
	printf( "Type of node is: %s\n", element->getNodeTypeString() );

	printf( "Creating some elements...\n" );
	TElementPtr base = document->createElement( "base" );
	TElementPtr item1 = document->createElement( "item1" );
	TElementPtr item2 = document->createElement( "item2" );
	TElementPtr item3 = document->createElement( "item3" );
	TElementPtr item4 = document->createElement( "item4" );
	TElementPtr item5 = document->createElement( "item1" ); // Watch out: name is item1
	printf( "Create a tree with the elements...\n" );
	base->appendChild( item1 );
	base->appendChild( item2 );
	base->appendChild( item3 );
	item3->appendChild( item5 );
	item5->appendChild( item4 );

	printf( "Add base to document\n" );
	document->appendChild( base );

	printf( "Printing tree...\n" );
	showDocument( document );

	TNodeListPtr result = base->getElementsByTagName( "item1" );
	printf( "There are %i elements with tag name item1\n", (int) result->getLength() );
	printf( "Still here\n" );

	TNodeListPtr resultStar = base->getElementsByTagName( "*" );
	printf( "There are %i elements in base\n", (int) resultStar->getLength() );

	printf( "Removing an item with tag name item1...\n" );
	base->removeChild( item1 );
	item1.reset();

	printf( "There are %i elements with tag name item1\n", (int) result->getLength() );

	printf( "Removing a small piece of a tree...\n" );
	base->removeChild( item3 );
	
	resultStar = base->getElementsByTagName( "*" );
	printf( "There are %i elements in base\n", (int) resultStar->getLength() );

	TTextPtr text1 = document->createText( "bla " );
	TTextPtr text2 = document->createText( "blub " );
	base->appendChild( text1 );
	base->appendChild( text2 );
	
	TTextWeak textWeak = text1;
	
	printf( "Testing Text functions...\n" );
	printf( "Whole text of nodes\n%s\n", text1->getWholeText().c_str() );
	printf( "Replacing the whole text\n" );
	text1.reset();
	text2->replaceWholeText( "This works" );
	printf( "Text2 replaced\n" );
	printf( "Whole text replaced by: %s\n", text2->getWholeText().c_str() );
	if ( textWeak.expired() )	{
		printf( "Node removed as it should be\n" );
	}
	else	{
		printf( "Erm, this shouldn't happen\n" );
	}

	printf( "Printing what's left of the tree...\n" );
	showDocument( document );
	printf( "Printing a deep clone of the tree\n" );
	TNodePtr deepClone = document->cloneNode( true );
	showTree( deepClone, 1 );
	printf( "Printing a shallow clone of the tree\n" );
	TNodePtr shallowClone = document->cloneNode( false );
	showTree( shallowClone, 1 );

	printf( "Cleaning up...\n" );

	// Clean up and exit
	scooby.reset();
	element.reset();
	
	printf( "Exiting...\n" );
	be_app->PostMessage( B_QUIT_REQUESTED );
	
}
Exemplo n.º 22
0
void DOMTest	::	showDocument( const TDocumentPtr document )	{
	
	printf( "Root of the tree: " );
	showTree( document, 1 );
	
}
Exemplo n.º 23
0
void Tree::showTree(){
	showTree(root);
}
Exemplo n.º 24
0
/******************************************************************************
*                                                                             *
*       execExp/1                                                             *
*                                                                             *
*       This routine attempts to evaulate the string expression as if it was  *
*       an IF-THEN-FI execS expression. Take expression and generate an       *
*       if ( expression ) then $i=0 endif, give it to the parser , then use   *
*	execR() to evaluate it. 					      *
*       For single variable expressions 				      *
*	 if not present, expression is false				      *
*	 if real variable & inactive, expression is false		      *
*	 if string & null string value, expression is false		      *
*       For Multiple variable expressions				      *
*        if a variable is not present, Error is reported & error returned     *
*       Parser errors return -1					              *
*                                                                             *
*				Author: Greg Brissey 5/31/90		      *
******************************************************************************/
int execExp(const char *buffer)	
{  
   char *expbuf;
   int   explen;
   char *prevTempID;
   const char *oldbp;
   int   oldFromFile;
   int   oldFromString;
   node *oldcodeTree;
   int   returnCode=0;
   int   gocheckit;

   LPRINT0(1,"execExp: starting...\n");
   LPRINT1(1,"execExp: expression ='%s'\n",buffer);
   if ( (explen = strlen(buffer)) > 0)
   {
  
     expbuf = allocateWithId( (explen + 35) * sizeof(char), "execExp");
     if (expbuf == NULL)
     {
        Werrprintf("cannot allocate memory for expression string");
        ABORT;
     }
     /* for parser: 'if ( expression ) then statement endif'  */
     strcpy(expbuf,"if ( ");
     strcat(expbuf,buffer);
     strcat(expbuf," ) then $i=0 endif \n");
     LPRINT1(1,"execExp: parser expression ='%s'\n",expbuf);
   
      oldFromFile   = fromFile;		/* push existing file info */
      oldFromString = fromString;
      oldbp         = bp;
      oldcodeTree   = codeTree;

      fromFile      = 0;
      fromString    = 1;
      bp            = expbuf;
      codeTree      = NULL;

      prevTempID    = tempID; tempID = newTempName("tmpExecExpID");

      /* parse expression IF-THEN-FI */
      switch (yyparse())
      { case 0:
		LPRINT0(1,"execExp: ...parser gives code 0, go do it!\n");
#ifdef  DEBUG
		if ( 1 < Lflag)
                {
		  showTree(0,"execExp:    ",codeTree);
		  showFlavour(stderr,codeTree);
                }
#endif 
		switch(codeTree->flavour)
		{
		   case THEN:  	/* It has to be this or something is real wrong. */
			{ 
			    char    *name;
                            int      shouldFree;
                            varInfo *v;
  			    pair p;

			    /* was it a single variable expression ?*/
			    /* if not flavour,  will be an operator not ID or LB */
                            gocheckit = 0;
                            v = NULL;
                            if ((codeTree->Lson->flavour == ID) ||
				(codeTree->Lson->flavour == LB) )
			    {
                              if ( (name=execN(codeTree->Lson->Lson,&shouldFree,NULL)) )
			      {
                                if ( (v=findVar(name)) )
				{
                                  gocheckit = 2; /* variable present, check active */
				}
                                else
                                { 
                                  gocheckit = 0; /* variable not present */
                                }
			      }
                              if (shouldFree)
                              {
                                LPRINT1(3,"execExp: ...releasing name %s\n",name);
                                release(name);
                              }
			    }
                            else
                              gocheckit = 1;	/* two variable expression */


			   if (gocheckit)
			   {
                            if (execR(codeTree->Lson,&p, NULL))
			    {
			       if((gocheckit > 1) && (p.T.basicType == T_REAL)	)
			       {
				  if (!v->active)
				  {
			             returnCode = 0;
                            	     cleanPair(&p);
				     break;
				  }	
			       }
			       if((gocheckit > 1) && (p.T.basicType == T_STRING)	)
			       {
				  if (strcmp(p.R->v.s,"n") == 0)
				  {
			             returnCode = 0;
                            	     cleanPair(&p);
				     break;
				  }	
			       }
                               if (isTrue(&p))
                               {
                                 LPRINT0(1,"execExp: IF-THEN-FI exp is true\n");
                                 returnCode = 1;
                               }
                               else
                               {   
                                LPRINT0(1,"execExp: IF-THEN-FI exp is false\n");
                                returnCode = 0;
                               }
			    }
                            else
                            {   
                               LPRINT0(1,"execExp: IF-THEN-FI exp failed\n");
                               returnCode = -1;
                            }
                            cleanPair(&p);
			   }
			   else
			     returnCode = 0;	/* variable not present */
                         }
			break;
                   default:
		        WerrprintfWithPos(
		         "BUG! execExp has a bad flavour (=%d)",codeTree->flavour);
                        returnCode = -1;
			break;
         	}
		break;
	case 1:
		LPRINT0(1,"execExp: ...parser gives code 1, drop everything!\n");
		ignoreEOL  = 0;		/* had a syntax error, drop it */
		returnCode = -1;
		break;
	case 2:
		LPRINT0(1,"execExp: ...parser gives code 2, incomplete expression, abort\n");
		ignoreEOL  = 0;		/* had a syntax error, drop it       */
		returnCode = -1;
		break;
      }
      codeTree = NULL;

      releaseWithId(tempID); free(tempID); tempID = prevTempID;

      fromFile   = oldFromFile;		/*  restore old file/kbd/string state*/
      fromString = oldFromString;
      bp         = oldbp;
      codeTree   = oldcodeTree;
      releaseAllWithId("execExp");
      LPRINT0(1,"execExp: finishing...\n");
   }
   else
   {  fprintf(stderr,"execExp: string (=\"%s\") is null.\n",buffer);
      returnCode = -1;
   }
   return(returnCode);
}
Exemplo n.º 25
0
void SGMLParser :: parse(const char * aSchemaFile, const char * aDocument) {

	printf("Loading schema\n");
	clock_t start = clock();
	loadSchema(aSchemaFile);
	clock_t end = clock();
	printf("Time taken for loading the schema: %f\n", (double)(end - start)/CLOCKS_PER_SEC);

	start = clock();
	printf("Starting to scan the HTML document\n");
	mScanner->setDocument(aDocument);
	printf("Loaded the document\n");
	// Assume the doctype is HTML.
	mDocTypeName = "HTML";
	ElementParser elementParser(mScanner, mSchema, mDocTypeName);
	// See if we can scan a whole HTML document.
	try {
		mToken = mScanner->nextToken();
		parseSStar();
		printf("Got first token: %s\n", mScanner->getTokenText().c_str());
		parseProlog();
		while (mToken != EOF_SYM) {
			switch (mToken) {
				case ELEMENT_OPEN_SYM: {
					// Kickstart the element parser.
					TElementPtr element = elementParser.parseStartTag();
					TDOMString name = element->getTagName();
					ElementToken elmToken = ElementToken(START_TAG, name, element);
					TElementDeclarationPtr declaration = mSchema->getDeclaration(mDocTypeName);
					mToken = elementParser.parse(elmToken, declaration);
					break;
				}
				case DECLARATION_SYM: {
					mToken = mScanner->nextToken();
					if (mToken == COMMENT_SYM) {
						if (mCommentDeclParser == NULL)
							mCommentDeclParser = new CommentDeclParser(mScanner, TSchemaPtr());
						mToken = mCommentDeclParser->parse(mToken, ELEMENT_OPEN_SYM);
					}
					else
						throw ReadException(mScanner->getLineNr(),
											mScanner->getCharNr(),
											"Expected comment sym",
											GENERIC,
											true);
					break;
				}
				case DECLARATION_END_SYM: {
					mToken = mScanner->nextToken(ELEMENT_OPEN_SYM);
					break;
				}
				case TEXT_SYM: {
					mToken = mScanner->nextToken();
					break;
				}
				case SPACE_SYM: {
					// Not doing anything with that right now.
					mToken = mScanner->nextToken();
					break;
				}
				default: {
					printf("Found token: %s\n", mScanner->getTokenText().c_str());
					mToken = mScanner->nextToken();
				}
			}
		}
	}
	catch(ReadException r) {
		printf(
			"Found error: line: %i char %i message: %s\n",
			r.getLineNr(),
			r.getCharNr(),
			r.getErrorMessage().c_str());
	}

	end = clock();
	printf("Time taken: %f\n", (double)(end - start)/CLOCKS_PER_SEC);

	TDocumentPtr document = elementParser.getDocument();
	showTree(document, 0);

}
Exemplo n.º 26
0
Arquivo: io.c Projeto: timburrow/ovj3
node *loadMacro(char *n, int search, int *res)
{   char *prevTempID;
    node *finalTree;
    node *p;

    *res = 0;
    if (3 <= Dflag)
	fprintf(stderr,"load: macro named \"%s\"...\n",n);
    if (init_input(n,search))
    {	finalTree = NULL;
	if (3 <= Dflag)
	    fprintf(stderr,"load: ...initialization of file %s is complete\n"
		   ,fileName
		   );
	prevTempID = tempID; tempID = newTempName("tmpLoadID");
	while (1)
	{   codeTree   = NULL;
	    if (3 <= Dflag)
		fprintf(stderr,"load: ...off to the parser!\n");
	    if (yyparse())
	    {   if (3 <= Dflag)
		    fprintf(stderr,"load: ...parser bombed!\n");
		finalTree = NULL;
                *res = 1;
		releaseWithId(tempID);
		break;
	    }
	    else
	    {   renameAllocation(tempID,"newMacro");
	        if (3 <= Dflag)
		{   fprintf(stderr,"load: ...parser done\n");
		    if (codeTree)
		    {   fprintf(stderr,"load: ...got...\n");
			showTree(0,"load:    ",codeTree);
		    }
		}
		if (codeTree && codeTree->flavour != ENDFILE)
		{   if (codeTree->flavour != EOL)
			if (finalTree)
			{   if (3 <= Dflag)
				fprintf(stderr,"load: ...tie it in\n");
			    p = newNode(CM,&(codeTree->location));
			    addLeftSon(p,codeTree);
			    addLeftSon(p,finalTree);
			    finalTree = p;
			}
			else
			{   if (3 <= Dflag)
				fprintf(stderr,"load: ...first one\n");
			    finalTree = codeTree;
			}
		    else
			if (3 <= Dflag)
			    fprintf(stderr,"load: ...just noise\n");
		}
		else
		{   if (3 <= Dflag)
		    {   fprintf(stderr,"load: ...have...\n");
			showTree(0,"load:    ",finalTree);
		    }
		    break;
		}
	    }
	}
	if (3 < Dflag)
	   fprintf(stderr,"load: time to clean-up!\n");
	free(tempID); tempID = prevTempID;
	cleanUp(n);
	return(finalTree);
    }
    else
   {
           Werrprintf("Command or macro \"%s\" does not exist",n);
           *res = 1;
	   return(NULL);
   }
}
Exemplo n.º 27
0
    OutputItemHeaderWidget::OutputItemHeaderWidget(
            OutputItemContentWidget *outputItemContentWidget, bool multipleResults, 
            bool tabbedResults, bool firstItem, bool lastItem, QWidget *parent) :
        QFrame(parent),
        _maxButton(nullptr), _dockUndockButton(nullptr), _maximized(false), 
        _multipleResults(multipleResults), 
        _firstItem(firstItem), _lastItem(lastItem), _orientation(Qt::Vertical)
    {
        setContentsMargins(5, 0, 0, 0);

        auto const* outputWidget = qobject_cast<OutputWidget*>(outputItemContentWidget->parentWidget());
        _orientation = outputWidget->getOrientation();

        // Text mode button
        _textButton = new QPushButton(this);
        _textButton->setIcon(GuiRegistry::instance().textIcon());
        _textButton->setToolTip("View results in text mode");
        _textButton->setFixedSize(24, 24);
        _textButton->setFlat(true);
        _textButton->setCheckable(true);

        // Tree mode button
        _treeButton = new QPushButton(this);
        _treeButton->hide();
        _treeButton->setIcon(GuiRegistry::instance().treeIcon());
        _treeButton->setToolTip("View results in tree mode");
        _treeButton->setFixedSize(24, 24);
        _treeButton->setFlat(true);
        _treeButton->setCheckable(true);
        _treeButton->setChecked(true);     

        // Table mode button
        _tableButton = new QPushButton(this);
        _tableButton->hide();
        _tableButton->setIcon(GuiRegistry::instance().tableIcon());
        _tableButton->setToolTip("View results in table mode");
        _tableButton->setFixedSize(24, 24);
        _tableButton->setFlat(true);
        _tableButton->setCheckable(true);
        _tableButton->setChecked(true);       

        // Custom mode button
        _customButton = new QPushButton(this);
        _customButton->hide();
        _customButton->setIcon(GuiRegistry::instance().customIcon());
        _customButton->setToolTip("View results in custom UI");
        _customButton->setFixedSize(24, 24);
        _customButton->setFlat(true);
        _customButton->setCheckable(true);

        // Create maximize button only if there are multiple results
        if (_multipleResults && !tabbedResults) {
            _maxButton = new QPushButton;
            _maxButton->setIcon(GuiRegistry::instance().maximizeIcon());
            _maxButton->setToolTip("Maximize this output result (double-click on result's header)");
            _maxButton->setFixedSize(18, 18);
            _maxButton->setFlat(true);
            VERIFY(connect(_maxButton, SIGNAL(clicked()), this, SLOT(maximizeMinimizePart())));
        }

        auto dockWidget = qobject_cast<QueryWidget::CustomDockWidget*>(outputItemContentWidget->parentWidget()->parentWidget());
        auto queryWidget = dockWidget->getParentQueryWidget();
        
        _dockUndockButton = new QPushButton;
        _dockUndockButton->setFixedSize(18, 18);
        _dockUndockButton->setFlat(true);
        _dockUndockButton->setHidden(true);
        applyDockUndockSettings(!dockWidget->isFloating());
        VERIFY(connect(_dockUndockButton, SIGNAL(clicked()), queryWidget, SLOT(dockUndock())));

        VERIFY(connect(_textButton, SIGNAL(clicked()), outputItemContentWidget, SLOT(showText())));
        VERIFY(connect(_treeButton, SIGNAL(clicked()), outputItemContentWidget, SLOT(showTree())));
        VERIFY(connect(_tableButton, SIGNAL(clicked()), outputItemContentWidget, SLOT(showTable())));
        VERIFY(connect(_customButton, SIGNAL(clicked()), outputItemContentWidget, SLOT(showCustom())));

        _collectionIndicator = new Indicator(GuiRegistry::instance().collectionIcon());
        _timeIndicator = new Indicator(GuiRegistry::instance().timeIcon());
        _paging = new PagingWidget();

        _collectionIndicator->hide();
        _timeIndicator->hide();
        _paging->hide();

        QHBoxLayout *layout = new QHBoxLayout();
#ifdef __APPLE__
        layout->setContentsMargins(2, 8, 5, 1);
#else  
        layout->setContentsMargins(2, 0, 5, 1);
#endif
        layout->setSpacing(0);
        layout->addWidget(_collectionIndicator);
        layout->addWidget(_timeIndicator);
        QSpacerItem *hSpacer = new QSpacerItem(2000, 24, QSizePolicy::Preferred, QSizePolicy::Minimum);
        layout->addSpacerItem(hSpacer);
        layout->addWidget(_paging);
        layout->addWidget(createVerticalLine());
        layout->addSpacing(2);

        if (outputItemContentWidget->isCustomModeSupported()) {
            layout->addWidget(_customButton, 0, Qt::AlignRight);
            _customButton->show();
        }

        if (outputItemContentWidget->isTreeModeSupported()) {
            layout->addWidget(_treeButton, 0, Qt::AlignRight);
            _treeButton->show();
        }

        if (outputItemContentWidget->isTableModeSupported()) {
            layout->addWidget(_tableButton, 0, Qt::AlignRight);
            _tableButton->show();
        }

        if (outputItemContentWidget->isTextModeSupported())
            layout->addWidget(_textButton, 0, Qt::AlignRight);

        if (_multipleResults)
            layout->addWidget(_maxButton, 0, Qt::AlignRight);

        layout->addSpacing(3);
        _verticalLine = createVerticalLine();
        _verticalLine->setHidden(true);
        layout->addWidget(_verticalLine);
        layout->addWidget(_dockUndockButton);

        setLayout(layout);

        // Update dock/undock button visibility
        if (_multipleResults)
            updateDockButtonOnToggleOrientation();
        else {
            _verticalLine->setVisible(true);
            _dockUndockButton->setVisible(true);
        }
      
        if(tabbedResults)
            setStyleSheet("background-color: white");
    }
Exemplo n.º 28
0
/******************************************************************************
*                                                                             *
*       evalName/3                                                            *
*                                                                             *
*       var - variable, strval - buffer to return string value, 	      *
*       maxlen - length of buffer					      *
*       This routine obtains the value of string variable 		      *
*       If variable does not exit, null string returned.		      *
*       If variable is not a string, null string returned.		      *
*       If string value length is greater than maxlen then only maxlen-1 char *
*	   are returned. 						      *
*									      *
*       an IF-THEN-FI execS expression. Take expression and generate an       *
*       if ( expression ) then $i=0 endif, give it to the parser , then use   *
*	execN() to obtain value. 					      *
*                                                                             *
*				Author: Greg Brissey 6/6/90		      *
******************************************************************************/
int execName(const char *var, char *strval, int maxlen)	
{  
   char *expbuf;
   int   explen;
   char *prevTempID;
   const char *oldbp;
   int   oldFromFile;
   int   oldFromString;
   node *oldcodeTree;
   int   returnCode=0;

   LPRINT0(1,"execName: starting...\n");
   LPRINT1(1,"execName: expression ='%s'\n",var);
   if ( (explen = strlen(var)) > 0)
   {
  
     expbuf = (char *)allocateWithId( (explen + 35) * sizeof(char), "execName");
     if (expbuf == NULL)
     {
        Werrprintf("cannot allocate memory for expression string");
        ABORT;
     }
     /* for parser: 'if ( expression ) then statement endif'  */
     strcpy(expbuf,"if ( ");
     strcat(expbuf,var);
     strcat(expbuf," ) then $i=0 endif \n");
     LPRINT1(1,"execName: parser expression ='%s'\n",expbuf);
   
      oldFromFile   = fromFile;		/* push existing file info */
      oldFromString = fromString;
      oldbp         = bp;
      oldcodeTree   = codeTree;

      fromFile      = 0;
      fromString    = 1;
      bp            = expbuf;
      codeTree      = NULL;

      prevTempID    = tempID; tempID = newTempName("tmpExecExpID");

      /* parse expression IF-THEN-FI */
      switch (yyparse())
      { case 0:
		LPRINT0(1,"execName: ...parser gives code 0, go do it!\n");
#ifdef  DEBUG
		if ( 1 < Lflag)
                {
		  showTree(0,"execName:    ",codeTree);
		  showFlavour(stderr,codeTree);
                }
#endif 
		switch(codeTree->flavour)
		{
		   case THEN:  	/* It has to be this or something is real wrong. */
			{ 
			    char    *name;
                            int      shouldFree;
                            varInfo *v;
  			    pair p;

                            if ( (name=execN(codeTree->Lson->Lson,&shouldFree, NULL)) )
			    {
                              if ( (v=findVar(name)) ) /* does variable exist? */
			      {
                                if (execR(codeTree->Lson,&p, NULL)) /* obtain value info */
			        {
				   if (p.T.basicType == T_STRING)
				   {
				     if ( (int) strlen(p.R->v.s) >= maxlen)
				     {
					strncpy(strval,p.R->v.s,maxlen-1);
					strval[maxlen-1]=0; /* Null terminate string */
				     }
				     else
				     {
				       strcpy(strval,p.R->v.s);
				     }
				   }
				   else
			 	     *strval = 0;
				}
				else
			 	   *strval = 0;
                                cleanPair(&p);
			      }
                              else
                              { 
                                 *strval = 0; /* return null string */
                              }
			    }
                            if (shouldFree)
                            {
                                LPRINT1(3,"execName: ...releasing name %s\n",name);
                                release(name);
                            }
			    returnCode = strlen(strval);
                         }
			break;
                   default:
		        WerrprintfWithPos(
		         "BUG! execName has a bad flavour (=%d)",codeTree->flavour);
                        returnCode = -1;
			break;
         	}
		break;
	case 1:
		LPRINT0(1,"execName: ...parser gives code 1, drop everything!\n");
		ignoreEOL  = 0;		/* had a syntax error, drop it */
		returnCode = -1;
		break;
	case 2:
		LPRINT0(1,
	         "execName: ...parser gives code 2, incomplete expression, abort\n");
		ignoreEOL  = 0;		/* had a syntax error, drop it       */
		returnCode = -1;
		break;
      }
      codeTree = NULL;

      releaseWithId(tempID); free(tempID); tempID = prevTempID;

      fromFile   = oldFromFile;		/*  restore old file/kbd/string state*/
      fromString = oldFromString;
      bp         = oldbp;
      codeTree   = oldcodeTree;
      releaseAllWithId("execName");
      LPRINT0(1,"execName: finishing...\n");
   }
   else
   {  fprintf(stderr,"execName: string (=\"%s\") is null.\n",var);
      returnCode = -1;
   }
   return(returnCode);
}