Exemplo n.º 1
0
/* The actual read function. */
void readin()
{
	char* fname = ( char* )malloc( sizeof( char ) * 26 ) ;	// The extra length for the null terminator.
    readName( fname, 0, 26 ) ;
    char* lname = ( char* )malloc( sizeof( char ) * 31 ) ;
	readName( lname, 1, 31 ) ;
	char* cardnum = ( char* )malloc( sizeof( char ) * 17 ) ;
	readNums( cardnum, 0, 17 ) ;
	char* month = ( char* )malloc( sizeof( char ) * 3 ) ;
	readNums( month, 1, 3 ) ;
	while( !checkMonth( month ) )
	{
		printf( "The entered month is not valid. Please try again.\n" ) ;
		readNums( month, 1, 3 ) ;
	}
	char* year = ( char* )malloc( sizeof( char ) * 5 ) ;
	readNums( year, 2, 5 ) ;
	while( !checkYear( year ) )
	{
		printf( "The entered year is not valid. Please try again.\n" ) ;
		readNums( year, 2, 5 ) ;
	}
	char* cvv = ( char* )malloc( sizeof( char ) * 4 ) ;
	readNums( cvv, 3, 4 ) ;
	if( strlen( cvv ) != 3 )	// String already checked for numbers. Check if all three are there.
	{
		printf( "Not enough digits for 3 digit CVV security code. Please try again. \n" ) ;
		readNums( cvv, 3, 4 ) ;
	}
	char* zip = ( char* )malloc( sizeof( char ) * 6 ) ;
	readNums( zip, 4, 6 ) ;
	if( strlen( zip ) != 5 )
	{
		printf( "Not enough numbers for 5 digit zipcode. Please try again.\n" ) ;
		readNums( zip, 4, 6 ) ;
	}
	char* amount = ( char* )malloc( sizeof( char ) * 10 ) ;
	readAmount( amount, 10 ) ;
	char* email = ( char* )malloc( sizeof( char ) * 25 ) ;
	readEmail( email, 31 ) ;
	display( fname, lname, cardnum, month, year, cvv, zip, amount, email ) ;
	// Free up all the memory pointers used here.
	free( fname ) ;	free( lname ) ;	free( cardnum ) ; free( month ) ; free( year ) ;
	free( cvv ) ; free( zip ) ; free( amount ) ; free( email ) ;
}
Exemplo n.º 2
0
void KreImporter::readIngredients( const QDomNodeList& l, Recipe *recipe, const QString &header, Ingredient *ing )
{
	for ( int i = 0; i < l.count(); i++ ) {
		QDomElement el = l.item( i ).toElement();
		if ( el.tagName() == "ingredient" ) {
			QDomNodeList ingredient = el.childNodes();
			Ingredient new_ing;
			for ( int j = 0; j < ingredient.count(); j++ ) {
				QDomElement ing = ingredient.item( j ).toElement();
				if ( ing.tagName() == "name" ) {
					new_ing.name = QString( ing.text() ).trimmed();
					kDebug() << "Found ingredient: " << new_ing.name ;
				}
				else if ( ing.tagName() == "amount" ) {
					readAmount(ing,new_ing.amount,new_ing.amount_offset);
				}
				else if ( ing.tagName() == "unit" ) {
					new_ing.units = Unit( ing.text().trimmed(), new_ing.amount+new_ing.amount_offset );
				}
				else if ( ing.tagName() == "prep" ) {
					new_ing.prepMethodList = ElementList::split(",",QString( ing.text() ).trimmed());
				}
				else if ( ing.tagName() == "substitutes" ) {
					readIngredients(ing.childNodes(), recipe, header, &new_ing);
				}
			}
			new_ing.group = header;

			if ( !ing )
				recipe->ingList.append( new_ing );
			else
				ing->substitutes.append( new_ing );
		}
		else if ( el.tagName() == "ingredient-group" ) {
			readIngredients( el.childNodes(), recipe, el.attribute( "name" ) );
		}
	}
}
Exemplo n.º 3
0
void KreImporter::readDescription( const QDomNodeList& l, Recipe *recipe )
{
	for ( int i = 0; i < l.count(); i++ ) {
		QDomElement el = l.item( i ).toElement();
		if ( el.tagName() == "title" ) {
			recipe->title = el.text();
			kDebug() << "Found title: " << recipe->title ;
		}
		else if ( el.tagName() == "author" ) {
			kDebug() << "Found author: " << el.text() ;
			recipe->authorList.append( Element( el.text() ) );
		}
		else if ( el.tagName() == "serving" ) { //### Keep for < 0.9 compatibility
			recipe->yield.setAmount(el.text().toInt());
		}
		else if ( el.tagName() == "yield" ) {
			QDomNodeList yield_children = el.childNodes();
			for ( int j = 0; j < yield_children.count(); j++ ) {
				QDomElement y = yield_children.item( j ).toElement();
				if ( y.tagName() == "amount" ) {
					double amount = 0.0, amountOffset = 0.0;
					readAmount(y, amount, amountOffset);
					recipe->yield.setAmount(amount);
					recipe->yield.setAmountOffset(amountOffset);
				}
				else if ( y.tagName() == "type" )
					recipe->yield.setType(y.text());
			}
		}
		else if ( el.tagName() == "preparation-time" ) {
			kDebug() << "Found preparation time: " << el.text();
			recipe->prepTime = QTime::fromString( el.text(), "hh:mm" );
		}
		else if ( el.tagName() == "category" ) {
			QDomNodeList categories = el.childNodes();
			for ( int j = 0; j < categories.count(); j++ ) {
				QDomElement c = categories.item( j ).toElement();
				if ( c.tagName() == "cat" ) {
					kDebug() << "Found category: " << QString( c.text() ).trimmed() ;
					recipe->categoryList.append( Element( QString( c.text() ).trimmed() ) );
				}
			}
		}
		else if ( el.tagName() == "pictures" ) {
			if ( el.hasChildNodes() ) {
				QDomNodeList pictures = el.childNodes();
				for ( int j = 0; j < pictures.count(); j++ ) {
					QDomElement pic = pictures.item( j ).toElement();
					QByteArray decodedPic;
					if ( pic.tagName() == "pic" )
						kDebug() << "Found photo" ;
					QPixmap pix;
					KCodecs::base64Decode( QByteArray( pic.text().toLatin1() ), decodedPic );
					int len = decodedPic.size();
					QByteArray picData;
					picData.resize( len );
					memcpy( picData.data(), decodedPic.data(), len );
					bool ok = pix.loadFromData( picData, "JPEG" );
					if ( ok ) {
						recipe->photo = pix;
					}
				}
			}
		}
	}
}