Esempio n. 1
0
void company() { // function to print the company login menu
    int p=1;
    do {
        printf("\nWelcome to the company management console!\n\n");
        printf("1. View current stock price of a company\n");
        printf("2. View past stock history of the company\n");
        printf("3. Create a new stock for a company\n");
        printf("4. Go Back\n\n");
        printf("Enter choice:");
        scanf("%d",&c);
        switch(c) {
        case 1:
            getQuote();
            break;
        case 2:
            getGraph();
            break;
        case 3:
            createStock();
            break;
        case 4:
            p=0;
            break;
        default:
            printf("Invalid Choice. Enter again!\n");
        }
    } while(p);
}
Esempio n. 2
0
Dialogs::Dialogs(QWidget *parent) : QWidget(parent)
{
   login=new Login(this);
   emTest=new EmotionTest(this);
   data = new Database(this);
   QLabel a("Thanks for participating", this);
   QHBoxLayout lay;
   lay.addWidget(&a);
   setLayout(&lay);
   
   if(data->makeConnection()) {

     // initializing the quote to be displayed in the typing test
     connect(this, SIGNAL(getQuote(int)), data, SLOT(getQuote(int)));
     connect(data, SIGNAL(setQuote(const QString&)), this,
	     SLOT(setQuote(const QString&)));

     srand(time(NULL));
     emit getQuote(rand() % 42);
    

      // checks the username and password combination
      connect(login, SIGNAL(info(const QString&, const QString&)),
	      data, SLOT(login(const QString&, const QString&)));
      // if the username and password are valid then closes dialog
      connect(data, SIGNAL(acceptLogin(bool)), login, 
	      SLOT(acceptedInfo(bool)));

      // moves onto the EmotionTest
      connect(login, SIGNAL(accepted()), emTest, SLOT(exec()));
      // giving the emotionTest results to the database
      connect(emTest, SIGNAL(results(const QList<EmotionRank*>&)),
	      data, SLOT(Emotions(const QList<EmotionRank*>&)));
      // if test results are put into the database then closes dialog
      connect(data, SIGNAL(acceptEmotions(bool)), emTest,
	      SLOT(acceptedInfo(bool)));
   
      // moves onto the TypingTest
      connect(emTest, SIGNAL(accepted()), tyTest, SLOT(exec()));

      //getting previous TypingTest results
      connect(tyTest, SIGNAL(findPrevious()), data, SLOT(previousTyping()));
      connect(data, SIGNAL(previousTypingResults(const QList<KeyFeatures>&)),
	      tyTest, SLOT(inputKeyFeatures(const QList<KeyFeatures>&)));
      
      
      //giving the TypingTest results to the database
      connect(tyTest, SIGNAL(results(const KeyFeatures&)), data,
	      SLOT(Typing(const KeyFeatures&)));
      // if test results are put into the database then closes dialog
      connect(data, SIGNAL(acceptTyping(bool)), tyTest,
	      SLOT(acceptedInfo(bool)));
      // closes everything
      connect(tyTest, SIGNAL(accepted()), data, SLOT(makeTest()));

      login->exec();

     }
Esempio n. 3
0
void loggedin() {
    int p=1;
    do {
        printf("1. Buy Stocks\n2. Sell stocks\n3. Get Stock Quotes\n4. Get previous stocks history\n5. View available stocks\n6. My Portfolio\n7. Logout\n\n");

        printf("Enter your choice: ");
        scanf("%d",&c);

        switch(c)
        {
        case 1:
            buyStocks();
            break;

        case 2:
            sellStocks();
            break;

        case 3:
            getQuote();
            break;

        case 4:
            getGraph();
            break;

        case 5:
            availablestocks();
            break;

        case 6:
            myPortfolio();
            break;

        case 7:
            logout();
            p=0;
            break;

        default:
            printf("\nWrong choice. Enter again.\n");
        }
    } while(p);
}
Esempio n. 4
0
void xml::lex::getContent(xml::token *tok)
{
	static const char* s_emptyElement = "/>";
	static const char* s_endElement = "</";
	static const char* s_elementEnd = ">";
	static const char* s_cdataStart = "<![CDATA[";
	int nEndlessLoopDetection = 0;
	if (m_s != 0)
	{

contentTop:;
		if (nEndlessLoopDetection++ > 1000)
		{
			// When parsing a XML with an invalid element <@CustomerID>
			// 1000 is well beyond any normal behavior of stream stacks.
			throw GException("XML Parser", 27, m_line, m_byte);
		}
		switch (m_sstate)
		{
			case xml::_xml_element_start :
				if (!m_s)
					throw GException("XML Parser", 28, m_line, m_byte);

				if ((m_s->m_xml[m_s->m_offset] == '<') && 
					(isNameChar(m_s->m_xml[m_s->m_offset + 1])))
				{
					m_s->m_offset++;
					offsetLine();
					tok->m_type = _startTag;
					if (getName(tok) != false)
					{
						GStackPush(m_tagStack,tok->get());

						m_sstate = _xml_element_attribute;

						if ((m_tagStack.m_nNext == 1) &&
							(m_documentType != 0))
						{
							if (memcmp(m_documentType, tok->get(), tok->length()) != 0)
							{
								throw GException("XML Parser", 16, m_line, m_byte);
							}
						}
					}
					else
					{
						throw GException("XML Parser", 11, m_line, m_byte);
					}
				}
				else
				{
					// make sure that the next tag isn't a >
					if (m_s->m_xml[m_s->m_offset + 1] == *s_elementEnd)
						throw GException("XML Parser", 11, m_line, m_byte);
		
					m_sstate = _xml_element_content;
					goto contentTop;
				}

				break;

			case xml::_xml_element_attribute :
				if (handleWhitespace() != false)
				{
					if (getName(tok) != false)
					{
						tok->m_type = _attributeName;
						m_sstate = _xml_element_attribute_value;
					}
					else
					{
						m_sstate = _xml_element_start_end;
						goto contentTop;
					}
				}
				else
				{
					m_sstate = _xml_element_start_end;
					goto contentTop;
				}
				break;

			case xml::_xml_element_start_end :
				if (handleReserved(s_emptyElement) != false)
				{
					// return an empty end tag token
					tok->m_type  = _emptyEndTag;
					m_sstate = _xml_element_start;
				}
				else if (handleReserved(s_elementEnd) != false)
				{
					m_sstate = _xml_element_content;
					goto contentTop;
				}
				else
				{
					throw GException("XML Parser", 8, m_line, m_byte);
				}

				break;

			case xml::_xml_element_attribute_value :
				getEqual();
				getQuote();
				tok->m_type = _pcdata;
				getAttribute(tok);
				getQuote();
				m_sstate = _xml_element_attribute;

				break;

			case xml::_xml_element_content :
				if (getCharacterData(tok) != false)
					tok->m_type = _pcdata;
				else if (handleReserved(s_cdataStart) != false)
				{
					getCData(tok);
					tok->m_type = _cdata;
				}
				else
				{
					getMisc(tok);

					if (tok->m_type == _unknown)
					{
						m_sstate = _xml_element_end_tag;
						goto contentTop;
					}
				}
				break;

			case xml::_xml_element_end_tag :
				handleWhitespace();
				if (handleReserved(s_endElement) != false)
				{
					tok->m_type = _endTag;
					getName(tok);

					m_sstate = _xml_element_end_end;
				}
				else if (m_tagStack.m_nNext)
				{
					m_sstate = _xml_element_start;
					goto contentTop;
				}
				break;

			case xml::_xml_element_end_end :
				handleWhitespace();
				if (handleReserved(s_elementEnd) == false)
				{
					throw GException("XML Parser", 8, m_line, m_byte);
				}

				m_sstate = _xml_element_start;
				goto contentTop;

				break;
		}
	}

	if ((tok->m_type == _endTag) || 
		(tok->m_type == _emptyEndTag))
	{
		// throw an exception if the end tag
		// doesn't match the last start tag
		GStackPopType(m_tagStack,tag,char *)
		if ( (tok->isEmpty() == false) && (tag != 0) )
		{
			if (memcmp(tag, tok->get(), tok->length()) != 0)
			{
				GString strStartTag;
				while ((tag) && (*tag != '>') && (!isWhitespace(*tag)))
				{
					strStartTag += *tag;
					tag++;
				}
				GString strEndTag(tok->get(), tok->length());
				throw GException("XML Parser", 12, (const char *)strEndTag, (const char *)strStartTag,m_line, m_byte);
			}
		}

		if (m_tagStack.m_nNext == 0)
		{
			m_state = xml::_finished;
			m_nextState = xml::_finished;

			if ((tok->m_type == _endTag) && (handleReserved(s_elementEnd) == false))
			{
				throw GException("XML Parser", 8, m_line, m_byte);
			}
		}
	}
Esempio n. 5
0
void xml::lex::getDTD(xml::token *tok)
{
	static const char* s_system = "SYSTEM";
	static const char* s_public = "PUBLIC";
	static const char* s_markupDeclStart = "[";
	static const char* s_markupDeclEnd = "]";
	static const char* s_entityDecl = "<!ENTITY";
	static const char* s_entityEnd = ">";
	static const char* s_parsedEntityRef = "%";

dtdTop:;

	switch (m_sstate)
	{
		case _xml_dtd_name :
			if (handleWhitespace() == false)
			{
				throw GException("XML Parser", 20, m_line, m_byte);
			}
			if (getName(tok) == false)
			{
				throw GException("XML Parser", 0, m_line, m_byte);
			}

			m_documentType = new char[tok->length() + 1];
			memcpy(m_documentType, tok->get(), tok->length());
			m_documentType[tok->length()] = 0;
			tok->release();

			handleWhitespace();

			// check for external identifiers
			if (handleReserved(s_system) != false)
				m_sstate = _xml_system_literal;
			else if (handleReserved(s_public) != false)
				m_sstate = _xml_public_literal;
			else
				m_sstate = _xml_pre_markup;

			goto dtdTop;
		case _xml_system_literal :
			if (handleWhitespace() == false)
			{
				throw GException("XML Parser", 20, m_line, m_byte);
			}
			getQuote();
			tok->m_type = _systemLiteral;
			getLiteral(tok);
			getQuote();

			// load the external DTD using the
			// DTD callback function
			if (m_state == xml::_xml_dtd)
				loadExternal(m_lpfnExternalDTD, tok);

			m_sstate = _xml_pre_markup;
			break;
		case _xml_public_literal :
			if (handleWhitespace() == false)
			{
				throw GException("XML Parser", 20, m_line, m_byte);
			}
			getQuote();
			tok->m_type = _publicLiteral;
			getLiteral(tok);
			getQuote();
			m_sstate = _xml_system_literal;
			break;
		case _xml_pre_markup :
			handleWhitespace();
			if (handleReserved(s_markupDeclStart) != false)
			{
				m_sstate = _xml_markup;
				goto dtdTop;
			}
			m_sstate = _xml_post_markup;
			break;
		case _xml_markup :
			handleWhitespace();

			if (handleReserved(s_markupDeclEnd) != false)
			{
				m_sstate = _xml_post_markup;
				goto dtdTop;
			}

			getMisc(tok);

			// look for elements, attribute lists, entities, and notation
			if (tok->m_type == xml::_unknown)
			{
				if (handleReserved(s_entityDecl) != false)
				{
					m_parameterEntity = false;
					if (handleWhitespace() == false)
					{
						throw GException("XML Parser", 20, m_line, m_byte);
					}
					// declaration of a parameter entity
					if (handleReserved(s_parsedEntityRef) != false)
					{
						m_parameterEntity = true;
						if (handleWhitespace() == false)
						{
							throw GException("XML Parser", 20, m_line, m_byte);
						}
					}

					tok->m_type = _entityName;
					if (getName(tok) == false)
					{
						throw GException("XML Parser", 11, m_line, m_byte);
					}

					xml::entity *p = new xml::entity();
					p->setTag(tok);
					if (m_parameterEntity == false)
					{
						if (m_generalEntities != 0)
							m_generalEntities->AddLast(p);
					}
					else
					{
						if (m_parameterEntities != 0)
							m_parameterEntities->AddLast(p);
					}

					m_sstate = _xml_entity;
				}
				else if (handleReserved(s_parsedEntityRef) != false)
				{
					handleEntityReference();
					goto dtdTop;
				}
			}

			break;

		case _xml_entity :
			if (handleWhitespace() == false)
			{
				throw GException("XML Parser", 20, m_line, m_byte);
			}

			getQuote();
			tok->m_type = xml::_entityValue;
			if (getEntity(tok) != false)
			{
				xml::entity *p = 0;
				if (m_parameterEntity == false)
				{
					if (m_generalEntities != 0)
						p = (xml::entity *)m_generalEntities->Last();
				}
				else
				{
					if (m_parameterEntities != 0)
						p = (xml::entity *)m_parameterEntities->Last();
				}
				p->setValue(tok);
			}
			else
			{
				throw GException("XML Parser", 9, m_line, m_byte);
			}
			getQuote();

			m_sstate = _xml_entity_end;
			break;

		case _xml_entity_end :
			handleWhitespace();

			if (handleReserved(s_entityEnd) == false)
			{
				throw GException("XML Parser", 7, m_line, m_byte);
			}

			m_sstate = _xml_markup;
			goto dtdTop;

		case _xml_post_markup :
			handleWhitespace();
			if ((handleReserved(s_entityEnd) == false) &&
				(m_postmarkup != false))
			{
				throw GException("XML Parser", 1, m_line, m_byte);
			}

			m_state = _misc;
			m_nextState = _content;
			m_sstate = _xml_element_start;
	}

	if ((m_state == _xml_dtd) && (tok->m_type == xml::_unknown))
	{
		m_sstate = _xml_post_markup;
		goto dtdTop;
	}
}
Esempio n. 6
0
void xml::lex::getXMLDecl(xml::token *tok)
{
	static const char* s_version = "version";
	static const char* s_encoding = "encoding";
	static const char* s_standalone = "standalone";
	static const char* s_endXMLDecl = "?>";

xmlDecl:;

	switch (m_sstate)
	{
		case _xml_decl_version :
			if (handleWhitespace() == false)
			{
				throw GException("XML Parser", 20, m_line, m_byte);
			}
			if (handleReserved(s_version) == false)
			{
				throw GException("XML Parser", 13, m_line, m_byte);
			}
			getEqual();
			getQuote();
			tok->m_type = xml::_version;
			if (getVersion(tok) == false)
			{
				throw GException("XML Parser", 13, m_line, m_byte);
			}
			getQuote();
			m_sstate = xml::_xml_decl_encoding;
			break;
		case _xml_decl_encoding :
			handleWhitespace();
			if (handleReserved(s_encoding) != false)
			{
				getEqual();
				getQuote();
				tok->m_type = xml::_encoding;
				if (getEncoding(tok) == false)
				{
					throw GException("XML Parser", 14, m_line, m_byte);
				}
				getQuote();
			}
			else
			{
				m_sstate = xml::_xml_decl_standalone;
				goto xmlDecl;
			}
			m_sstate = xml::_xml_decl_standalone;
			break;
		case _xml_decl_standalone :
			handleWhitespace();
			if (handleReserved(s_standalone) != false)
			{
				getEqual();
				getQuote();
				tok->m_type = xml::_standalone;
				if (getStandalone(tok) == false)
				{
					throw GException("XML Parser", 15, m_line, m_byte);
				}
				getQuote();
			}
			handleWhitespace();
			if (handleReserved(s_endXMLDecl) == false)
			{
				throw GException("XML Parser", 3, m_line, m_byte);
			}
			m_state = xml::_misc;
	}
}
/***********************************************************************
 *
 * FUNCTION:    MainFormHandleEvent
 *
 * DESCRIPTION: This routine is the event handler for the 
 *              "MainForm" of this application.
 *
 * PARAMETERS:  eventP  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event has handle and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *
 *
 ***********************************************************************/
static Boolean MainFormHandleEvent(EventPtr eventP)
{
	Boolean handled = false;
	FormPtr frmP;
    char result[240];
    int rc;
    FieldPtr			fld;


	switch (eventP->eType) 
		{
		case menuEvent:
			return MainFormDoCommand(eventP->data.menu.itemID);

		case frmOpenEvent:
			frmP = FrmGetActiveForm();
			MainFormInit( frmP);
			FrmDrawForm ( frmP);
			handled = true;
			break;
			
		case frmUpdateEvent:
			// To do any custom drawing here, first call FrmDrawForm(), then do your
			// drawing, and then set handled to true.
			break;

/*
	case ctlEnterEvent:
		switch (eventP->data.ctlEnter.controlID)
		{
			case MainRunButton:
			getQuote("IBM",result);
				break;
		}
		break;
*/		

	case ctlSelectEvent:
		switch (eventP->data.ctlSelect.controlID)
		{
			case MainRunButton:
			rc = getQuote("IBM",result);
//			if (rc==SOAP_OK)
//  			{
				fld = GetObjectPtr (MainResultField);
				FldSetTextPtr( fld, result);
				FldDrawField(fld);
				FldRecalculateField(fld,true);
//			 }
//			  else
//			    FrmAlert(Soap_errorAlert);

			
			break;
		}
		break;

		default:
			break;
		
		}
	
	return handled;
}