void MMBJsonParser::parseJson(String message) { //elimino \n \t e spazi //inserisco tutti i caratteri nel buffer interno for (int i = 0; i < message.length(); i++) { addCharacter(message.charAt(i)); } //inserisco il terminatore addCharacter('\0'); //eseguo il parsing parseJson(); }
//---PARSE FUNCTION void MMBJsonParser::parseJson(char *message) { //devono essere già stati eliminati \n \t e spazi //inserisco tutti i caratteri nel buffer interno for (int i = 0; i < strlen(message); i++) { addCharacter(message[i]); } //inserisco il terminatore addCharacter('\0'); //eseguo il parsing parseJson(); }
void ClassRegex::merge(const ClassRegex* other) { for (auto i = other->characters.crbegin(); i != other->characters.crend(); ++i) { addCharacter(*i); } }
NFA CreateSingleNFA (wchar_t c) { NFA nfa; Edge e; nfa = malloc (sizeof (struct Automaton)); assert(nfa); /* 初始化nfa的Edge数组 */ nfa->edgeArray = allocEdgeArray(1); /* 初始化nfa的Status状态数组 */ nfa->statusArray = allocStatusArray(2); e = Array_get(nfa->edgeArray, 0); clearBits(e); addCharacter (e, c); link_Two_Status_In_Automaton(nfa,0,1,0); adjustStatusID(nfa); ensureFinalStatus (nfa->end); return nfa ; }
void Player::reset() { PlayerBase::reset(); // LocalNotification::getInstance()->setEnabled(true); auto& playData = getPlayData(); ValueMap map; ValueVector vec; const std::vector<const char*> mapKeys = {CHARACTERS, WEAPONS}; for(auto k: mapKeys){ playData[k] = map; } const std::vector<const char*> vecKeys = {}; for(auto k: vecKeys){ playData[k] = vec; } const std::vector<const char*> intKeys = {RANK, TOTAL_BATTLE}; for(auto k: intKeys){ playData[k] = 0; } for (auto& item : INITIAL_ITEMS) { auto itemId = item.first; auto count = item.second; addItem(itemId, count); } for (auto& map : INITIAL_CHARACTERS) { auto characterId = map.first; auto weaponId = map.second; addCharacter(characterId, weaponId); addWeapon(weaponId); } createGift("Opening1", ItemId::CHARGE, 5, "[はろくえ]ダウンロードありがとうプレゼント!!"); createGift("Opening2", ItemId::SOUL, 1000, "[はろくえ]ダウンロードありがとうプレゼント!!"); setVolume(100); setVolumeSE(100); setAudioId(-1); save(); }
void LoginManager::processPasswordConfirmation(const QString& aLine, Client &aClient) { auto account = getAccountOrDie(aClient); if(!account) return; QByteArray passwordBytes; passwordBytes.append(aLine); QString hash = QString(QCryptographicHash::hash(passwordBytes, QCryptographicHash::Md5).toHex()); if(account->getPasswordHash() != hash) { aClient.printRawLine("Passwords do not match. Try again."); aClient.printRawLine("Enter a password for this account: "); state_ = ELoginStateNewPassword; return; } //passwords match, ok //creating a new character now account->confirmCreation(); auto newCharacter = world::World::instance()->objectFactory()->createPtr<Person>(Person::TYPE); newCharacter->putInDefaultRoom(); account->addCharacter(newCharacter->uid()); aClient.setState(EClientStateNormal); aClient.linkToPerson(newCharacter); auto room = newCharacter->getRoom(); if(room)//first look around room->printDescription(*(newCharacter.get()), aClient); }
void Game::run() { window->GetMainLayer().addObject(mapSprite, 0); addCharacter(getMainCharacter().getId(), getMainCharacter()); if(isFrameratePrinted) { window->GetInterfaceLayer().addObject(framerate, 1); } if(isLatencyPrinted) { window->GetInterfaceLayer().addObject(latency, 1); } window->Launch(); if (connection->auth()) { std::cout << "Authenticated !" << std::endl; while (window->IsOpened()) { //main game loop sf::Sleep(0.01); updateCharacters(); updateMainView(); updateInterfaceView(); } } window->Wait(); }
void Compressor::Compress(Writer& w,vector< pair<string,string> > fileName) { HuffmanTree T; int numberOfFiles=fileName.size(); for (int i=0;i<numberOfFiles;i++) { Reader r(fileName[i].first); int c; int lengthName=fileName[i].second.length(); //encode filename for (int j=0;j<lengthName;j++) { c=fileName[i].second[j]; addCharacter(T,c,w); // cout << endl; // T.writeTree(); // cout << endl; } addCharacter(T,EndOfFile,w); // cout << endl; // T.writeTree(); // cout << endl; while (r.readNextByte(&c)) //encode file { addCharacter(T,c,w); // cout << endl; // T.writeTree(); // cout << endl; } addCharacter(T,EndOfFile,w); // cout << endl; // T.writeTree(); // cout << endl; } addCharacter(T,EndOfTransmission,w); // cout << endl; // T.writeTree(); // cout << endl; w.flush(); }
/* adds megaman to megaman tracker if theres space, deletes him if not * then adds him as character*/ void MyLevel::addMegaman(Megaman* newMegaman) { if(megamans.size()<(uint)metadata->getNumberOfClients()){ ClientData* clientData=metadata->getClient(megamans.size()+1); if(clientData){ megamans[clientData->getDescriptor()]=newMegaman; addCharacter(newMegaman); newMegaman->assignOwner(clientData); } }else{ delete newMegaman; } }
bool HeroInformationMenuLayer::init(){ if (!Layer::init()) { return false; } // addMenu(); addCharacter(); addIllustratedHandbook(); addSkill(); addMenu(); return true; }
int CharacterEdits::exec( TextRangeRegExp* regexp ) { _regexp = regexp; negate->setChecked( regexp->negate() ); digit->setChecked( regexp->digit() ); _nonDigit->setChecked( regexp->nonDigit() ); space->setChecked( regexp->space() ); _nonSpace->setChecked( regexp->nonSpace() ); wordChar->setChecked( regexp->wordChar() ); _nonWordChar->setChecked( regexp->nonWordChar() ); bool enabled = (RegExpConverter::current()->features() & RegExpConverter::CharacterRangeNonItems); _nonWordChar->setEnabled( enabled ); _nonDigit->setEnabled( enabled ); _nonSpace->setEnabled( enabled ); // Characters KMultiFormListBoxEntryList list1 = _single->elements(); for ( TQPtrListIterator<KMultiFormListBoxEntry> it(list1); *it; ++it ) { SingleEntry* entry = dynamic_cast<SingleEntry*>( *it ); if (entry) entry->setText( TQString::fromLocal8Bit("") ); } TQStringList list2 = regexp->chars(); for ( TQStringList::Iterator it2( list2.begin() ); ! (*it2).isNull(); ++it2 ) { addCharacter( *it2 ); } // Ranges KMultiFormListBoxEntryList list3 = _range->elements(); for ( TQPtrListIterator<KMultiFormListBoxEntry> it3(list3); *it3; ++it3 ) { RangeEntry* entry = dynamic_cast<RangeEntry*>( *it3 ); if (entry) { entry->setFrom( TQString::fromLocal8Bit("") ); entry->setTo( TQString::fromLocal8Bit("") ); } } TQPtrList<StringPair> ranges = regexp->range(); for ( TQPtrListIterator<StringPair> it4(ranges); *it4; ++it4 ) { TQString from = (*it4)->first(); TQString to = (*it4)->second(); addRange(from,to); } int res = KDialogBase::exec(); _regexp = 0; return res; }
void QCustomTableWidget::onVHeaderClicked(int index, const QPoint &position) { QAction *action = vMenu->exec(position); if (action == actionVAdd) { addCharacter(index); } else if (action == actionVRemove) { removeCharacter(index); } else if (action == actionVEdit) { editCharacter(index); } }
void QCustomTableWidget::onVHeaderClicked(int index, const QPoint &position) { bool null = (index != -1); actionRemoveRow->setVisible(null); actionEditRow->setVisible(null); QAction *action = vMenu->exec(position); if (action == actionAddRow) { addCharacter(index); } else if (action == actionRemoveRow) { removeCharacter(index); } else if (action == actionEditRow) { editCharacter(index); } }
void Game::updateCharacters() { connection->connectionMutex.Lock(); std::map<long, Character> positions = connection->getPlayers(); connection->connectionMutex.Unlock(); std::map<long, Character>::iterator pit; for (pit = positions.begin(); pit != positions.end(); pit++) { if (hasCharacter(pit->first)) { window->drawableObjectsMutex.Lock(); *characters[pit->first] = pit->second; window->drawableObjectsMutex.Unlock(); } else { Character *c = new Character(pit->second); addCharacter(pit->first, *c); } } if (characters.size() > positions.size()) { std::map<long, Character*>::iterator ppit; for (ppit = characters.begin(); ppit != characters.end(); ppit++) { if (positions.find(ppit->first) == positions.end()) { deleteCharacter(ppit->first); } } } }
void QCustomTableWidget::mousePressEvent(QMouseEvent *e) { int rowPosition, columnPosition; QTableWidgetItem *qtwitem = itemAt(e->pos()); switch (e->button()) { case Qt::LeftButton: { if (qtwitem && !qtwitem->isSelected()) { QTableWidget::mousePressEvent(e); } else { setCurrentItem(0); } break; } case Qt::RightButton: { if (qtwitem) { setCurrentItem(qtwitem); rowPosition = visualRow(currentRow()); columnPosition = visualColumn(currentColumn()); } else { rowPosition = rowCount()-1; columnPosition = columnCount()-1; } QTableWidget::mousePressEvent(e); bool null = (qtwitem != 0); actionRemoveColumn->setVisible(null); actionEditColumn->setVisible(null); actionRemoveRow->setVisible(null); actionEditRow->setVisible(null); QAction* action = menu->exec(e->globalPos()); if (action == actionAddColumn) { addProperty(columnPosition); } else if (action == actionRemoveColumn) { if (qtwitem) { removeProperty(columnPosition); } } else if (action == actionEditColumn) { if (qtwitem) { editProperty(columnPosition); } } else if (action == actionAddRow) { addCharacter(rowPosition); } else if (action == actionRemoveRow) { if (qtwitem) { removeCharacter(rowPosition); } } else if (action == actionEditRow) { if (qtwitem) { editCharacter(rowPosition); } } break; } default: break; } }
void QCustomTableWidget::keyReleaseEvent(QKeyEvent *e) { QTableWidgetItem *item = currentItem(); int row = visualRow(currentRow()); int column = visualColumn(currentColumn()); Qt::KeyboardModifiers modifs = e->modifiers(); switch (e->key()) { case Qt::Key_F2: if (!bEditing) { if (modifs == Qt::ControlModifier) { editProperty(column); } else if (modifs == (Qt::ControlModifier | Qt::ShiftModifier)) { editCharacter(row); } else if (item) { bEditing = true; editItem(item); } } break; case Qt::Key_Delete: if (!bEditing) { if (modifs == Qt::ControlModifier) { removeProperty(column); } else if (modifs == (Qt::ControlModifier | Qt::ShiftModifier)) { removeCharacter(row); } else if (item) { item->setText("0"); } } break; case Qt::Key_Insert: if (!bEditing) { if (modifs == Qt::ControlModifier) { addProperty(column); } else if (modifs == (Qt::ControlModifier | Qt::ShiftModifier)) { addCharacter(row); } else { QTableWidget::keyReleaseEvent(e); } } break; case Qt::Key_Return: case Qt::Key_Enter: case Qt::Key_Escape: bEditing = false; break; default: QTableWidget::keyReleaseEvent(e); break; } }
DateTimeEditor::DateTimeEditor(QWidget* parent) : QWidget(parent) { setFocusPolicy(Qt::StrongFocus); addGroup(YEAR, 1, 9999, 'Y'); addGroup(MONTH, 1, 12, 'M'); addGroup(DAY, 1, 31, 'D'); addGroup(HOUR, 0, 23, 'H'); addGroup(MINUTE, 0, 59, 'M'); addGroup(SECOND, 0, 59, 'S'); addCharacter(HOUR, "012"); addCharacter(HOUR, "0123456789"); addFixedCharacter(':'); addCharacter(MINUTE, "012345"); addCharacter(MINUTE, "0123456789"); addFixedCharacter(':'); addCharacter(SECOND, "012345"); addCharacter(SECOND, "0123456789"); addFixedCharacter(' '); addCharacter(YEAR, "0123456789"); addCharacter(YEAR, "0123456789"); addCharacter(YEAR, "0123456789"); addCharacter(YEAR, "0123456789"); addFixedCharacter('-'); addCharacter(MONTH, "01"); addCharacter(MONTH, "0123456789"); addFixedCharacter('-'); addCharacter(DAY, "0123"); addCharacter(DAY, "0123456789"); m_selectedPosition = -1; m_selectedGroup = NONE; validate(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), database(0), eventsFilterModel(new QSortFilterProxyModel(this)), conversationsTreeModel(new TableToTreeProxyModel(this)), hideEventsTableColumnsModel(new HideColumnsProxyModel(this)) { ui->setupUi(this); eventsFilterModel->setObjectName("eventsFilterModel"); hideEventsTableColumnsModel->setObjectName("hideEventsTableColumnsModel"); QList<int> hideColumns; hideColumns << 0 << 1 << 4 << 5; hideEventsTableColumnsModel->setHideColumns(hideColumns); conversationsTreeModel = new TableToTreeProxyModel(this); conversationsTreeModel->setObjectName("conversationsTreeModel"); QString fileName = settings.value("database").toString(); if (fileName.isEmpty() || !QFile(fileName).exists()) { newFile(); } else { openFile(fileName); } ui->statusBar->hide(); ui->splitter->setStretchFactor(1, 1); QVariant treeSize = settings.value("treeSize"); QVariant tableSize = settings.value("tableSize"); if (treeSize.isValid() && tableSize.isValid()) { QList<int> splitterSizes; splitterSizes << treeSize.toInt() << tableSize.toInt(); ui->splitter->setSizes(splitterSizes); } // TODO: Disable actions that need new e.g. characters until ready connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(newFile())); connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFile())); connect(ui->actionAdd_Event, SIGNAL(triggered()), this, SLOT(addEvent())); connect(ui->actionDelete_Event, SIGNAL(triggered()), this, SLOT(deleteEvent())); connect(ui->actionAdd_Conversation, SIGNAL(triggered()), this, SLOT(addConversation())); connect(ui->actionDelete_Conversation, SIGNAL(triggered()), this, SLOT(deleteConversation())); connect(ui->actionAdd_Character, SIGNAL(triggered()), this, SLOT(addCharacter())); connect(ui->actionDelete_Character, SIGNAL(triggered()), this, SLOT(deleteCharacter())); connect(ui->actionPreferences, SIGNAL(triggered()), this, SLOT(openPreferences())); ui->conversationsView->installEventFilter(this); ui->eventsView->installEventFilter(this); connect(ui->conversationsView, SIGNAL(clicked(QModelIndex)), this, SLOT(filterOnConversation(QModelIndex))); ui->eventsView->setModel(eventsFilterModel); ui->eventsView->hideColumn(0); ui->eventsView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); ui->eventsView->setEditTriggers(QAbstractItemView::NoEditTriggers); connect(ui->eventsView, SIGNAL(activated(QModelIndex)), this, SLOT(editEvent(QModelIndex))); conversationsTreeModel->index(0,0).parent().isValid(); ui->conversationsView->setModel(conversationsTreeModel); ui->conversationsView->sortByColumn(0, Qt::AscendingOrder); ui->conversationsView->setEditTriggers(QAbstractItemView::NoEditTriggers); connect(ui->conversationsView, SIGNAL(activated(QModelIndex)), this, SLOT(editTreeItem(QModelIndex))); }
int main (int argc, char** argv) { FILE* meme_file = 0; FILE* action_file = 0; FILE* font_file = 0; FILE* font_simp_file = 0; FILE* simp_file = 0; FILE* outfile = 0; char* line = 0; char* name = 0; char* value = 0; char* file = 0; char* tmp_word = 0; char* tmp_value = 0; char* meme_filename = 0; char* action_filename = 0; size_t line_size = 0; int i = 0; int j = 0; int x = 0; int y = 0; int w = 0; int h = 0; int line_counter = 0; int search_flag = 0; char cur_char = 0; meme* meme_data = 0; font* font_data = 0; simp* meme_simp = 0; simp* font_simp = 0; simp* string_simp = 0; simp* temp_simp = 0; simp* temp_swap_ptr = 0; /* Check to make sure there are the proper number of argumnets. */ if (argc != 3 ) { printf("Invalid number of arguments!\n"); return 1; } meme_filename = argv[1]; action_filename = argv[2]; /* Open the files for reading. If one fails to open, then exit and return 1. */ meme_file = fopen(meme_filename, "r"); if (meme_file == 0) { printf("File %s failed to open!\n", meme_filename); return 1; } action_file = fopen(action_filename, "r"); if (action_file == 0) { printf("File %s failed to open!\n", action_filename); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } /* Create space for the meme and font data structure */ meme_data = (meme*) malloc(sizeof(meme)); font_data = (font*) malloc(sizeof(font)); /* Create space for the strings */ /* line = (char*) malloc(256); */ name = (char*) malloc(128); value = (char*) malloc(128); file = (char*) malloc(128); line_counter = 0; /* Read through the act file */ while (getline(&line, &line_size, action_file) != -1) { line_counter++; if (isspace(line[0])) continue; /* Split the line into a name and a value. */ strcpy(name, strtok(line, ":\n")); strcpy(value, strtok(0, ":\n")); /* For each line, take action based on what it starts with */ if (strncmp(line, "OUTFILE", 7) == 0) { /* Open the outfile for writing binary. */ outfile = fopen(value, "wb"); /* If the outfile doesn't open then close everything and exit */ if (outfile == 0) { printf("The outfile from line %d of %s failed to open!\n", line_counter, action_filename); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } } else if (strncmp(line, "MEME", 4) == 0) { /* Initialize the meme structure with the given name. */ initMeme(meme_data, value); } else if (strncmp(line, "FONT", 4) == 0) { /* Initialize the font structure with the given name. */ initFont(font_data, value); } else { /* If the meme structure already exists, add attributes. */ addAttribute(meme_data, name, value, 0, 0); } } line_counter = 0; /* Read through the mem file */ while (getline(&line, &line_size, meme_file) != -1) { line_counter++; if (line[0] == '\n') continue; /* Split the line into a name and a value. */ strcpy(name, strtok(line, ":\n")); strcpy(value, strtok(0, ":\n")); /* For each line, take action based on what it starts with */ if (strncmp(line, "MEMES", 5) == 0) { search_flag = 0; tmp_word = strtok(value, " \t\n\v\f\r"); /* Check that at least of of the values matches meme_data->name. If none do, then exit the program. */ while(tmp_word != 0 ) { if (strcmp(tmp_word, meme_data->name) == 0) { search_flag = 1; break; } tmp_word = strtok(0, " \t\n\v\f\r"); } /* If the meme we are looking for is not included in this file, then exit. */ if (!search_flag) { printf("The Meme %s is not included in the file %s on line %d!", meme_data->name, meme_filename, line_counter); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } } else if (strncmp(line, "FONTS", 5) == 0) { /* Read the name of each one. If the name matches font_data->name, then keep that open as font_file and close all other fsf files. */ tmp_word = strtok(value, " \t\n\v\f\r"); search_flag = 0; /* Check that at least of of the values matches font_data->name. If none do, then exit the program. */ while(tmp_word != 0) { /* Open each font file for reading */ font_file = fopen(tmp_word, "r"); /* If the font_file doesn't open, then close everything and exit. */ if (font_file == 0) { printf("The file %s on line %d of %s failed to open!\n", tmp_word, line_counter, meme_filename); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } /* Read the fsf file, and look for the name tag. */ while (getline(&line, &line_size, font_file) != -1) { if (isspace(line[0])) continue; if (strncmp(line, "NAME", 4) == 0) { tmp_value = line; tmp_value = fustrtok(tmp_value, file, 128, ":\n"); tmp_value = fustrtok(tmp_value, file, 128, ":\n"); if (strcmp(file, font_data->name) == 0) { search_flag = 1; break; } } } if (search_flag) { break; } if (font_file) { fclose(font_file); } tmp_word = strtok(0, " \t\n\v\f\r"); } /* If the meme we are looking for is not included in this file, then exit. */ if (!search_flag) { printf("The Font %s on line %d is not included in the mem file!\n", font_data->name, line_counter); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } } else if (strncmp(line, meme_data->name, strlen(meme_data->name)) == 0) { /* Check to see of the next word is "FILE". If it is then open that simp file, otherwise add the values to the associated attribute. */ tmp_word = name; sscanf(name, "%*s %s", tmp_word); if (strcmp(name, "FILE") == 0) { /* Open each font file for reading */ simp_file = fopen(value, "rb"); /* If the simp_file doesn't open, then close everything and exit. */ if (simp_file == 0) { printf("The simp file, %s, on line %d of %s failed to open!\n", value, line_counter, meme_filename); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } meme_simp = (simp*) malloc(sizeof(simp)); if (!readSimp(meme_simp, simp_file)) { printf("The meme simp file was unable to be read!\n"); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } } else { if (sscanf(value, "%d %d", &x, &y) != 2) { printf("Invalid argument(s) on line %d of %s: %s:value!\n", line_counter, meme_filename, line, value); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } setAttrCoord(meme_data, tmp_word, x, y); } } } line_counter = 0; /* Read through the fsf file */ while (getline(&line, &line_size, font_file) != -1) { line_counter++; if (isspace(line[0])) continue; /* For each line, take action based on what it starts with */ if (strncmp(line, "NAME", 4) == 0) { /* This statement may be able to be removed because the NAME was already checked in the mem file read. */ } else if (strncmp(line, "IMAGE", 5) == 0) { /* Split the line into a name and a value. */ tmp_word = line; tmp_word = fustrtok(tmp_word, file, 128, ":\n"); tmp_word = fustrtok(tmp_word, file, 128, ":\n"); /* Open the simp image for editing */ font_simp_file = fopen(file, "rb"); /* If the simp_file doesn't open, then close everything and exit. */ if (font_simp_file == 0) { printf("The simp file, %s, on line %d of the specified fsf file failed to open!\n", value, line_counter); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } font_simp = (simp*) malloc(sizeof(simp)); if (!readSimp(font_simp, font_simp_file)) { printf("The file %s from line %d of the fsf file was unable to be read!\nThe filetype may be incorrect or the file may be corrupted.\n", value, line_counter); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } } else if (strncmp(line, "CHARACTER", 9) == 0) { if (!font_simp_file) { printf("The fsf IMAGE line must come before any CHARACTERn line!\n"); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } /* Check the character after CHARACTER. Crop the image at the given values and store it at the proper index. */ if (sscanf(value, "%d %d %d %d", &x, &y, &w, &h) != 4) { printf("Invalid argument(s) on line %d of the fsf file!\n", line_counter); freeAll("ccccmnssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 1; } addCharacter(font_simp, font_data, name[9], x, y, w, h); } } /* create a string_simp to overlay, and a temp_simp to hold the temporary crop. */ string_simp = (simp*) malloc(sizeof(simp)); temp_simp = (simp*) malloc(sizeof(simp)); /* For each attribute in the meme */ for (i = 0; i < meme_data->num_attr; i++) { /* TODO: take care of the scenario where there are zero letters in the message. */ w = font_data->characters[meme_data->attr[i].msg[0]]->width; h = font_data->characters[meme_data->attr[i].msg[0]]->height; /* initialize the string_simp with the width of the first two letters. */ initSimp(string_simp, w, h); crop(font_data->characters[meme_data->attr[i].msg[0]], string_simp, 0, 0, w, h); line_size = strlen(meme_data->attr[i].msg); /* For each letter in that attribute's message. */ for (j = 1; j < line_size; j++) { cur_char = meme_data->attr[i].msg[j]; w = font_data->characters[cur_char]->width; w += string_simp->width; h = font_data->characters[cur_char]->height; initSimp(temp_simp, w, h); /* Crop simp_string into temp_simp with simp_string->width + current character's width and the standard height. */ crop(string_simp, temp_simp, 0, 0, w, h); /* Swap string_simp and temp_simp pointers. */ temp_swap_ptr = string_simp; string_simp = temp_simp; temp_simp = temp_swap_ptr; /* overlay the new letter */ x = w - font_data->characters[cur_char]->width; overlay(font_data->characters[cur_char], string_simp, x, 0); freeSimp(temp_simp); } /* Calculate the upper left corner based on the centers given. */ y = meme_data->attr[i].y - string_simp->height; x = meme_data->attr[i].x - (string_simp->width / 2); /* Overlay the completed string_simp onto the meme_simp. */ overlay(string_simp, meme_simp, x, y); /* Free the string_simp to use on the next attribute. */ freeSimp(string_simp); } /* Write the meme_simp to the outfile */ writeSimp(meme_simp, outfile); /* cleanup */ freeAll("ccccmnssssffffff", line, name, value, file, meme_data, font_data, font_simp, meme_simp, string_simp, temp_simp, meme_file, action_file, font_file, font_simp_file, simp_file, outfile); return 0; }