/// directly sends the quoted text to oss /// and returns if a quote was found /// empties the given buffer in to oss if one is given /// works only if a quote char is found where the iss cursor is. bool JLDIO::skipOverQuotes(std::ostringstream& oss, std::istringstream& iss, std::list<char> *bufferToEmpty) { char charBuffer = iss.peek(); if(charBuffer == '\'' || charBuffer == '\"') { if(bufferToEmpty && !bufferToEmpty->empty()) { oss << listToString(*bufferToEmpty); bufferToEmpty->clear(); } // std::cout<<"Skipping: "; char matchedChar = charBuffer; iss.get(charBuffer); assert(matchedChar == charBuffer); do { oss << charBuffer; // std::cout<<charBuffer; } while(iss.get(charBuffer) && charBuffer != matchedChar); if(iss.good()) oss << charBuffer; // std::cout<<charBuffer<<"\n"; return true; } return false; }
char* tableToString(HashTable* t) { // get the total number of variable in the hashtable int i, numOfVariable = 0; for (i = 0; i < HTSIZE; i++) { numOfVariable += getListSize(t->table[i]); } // allocate memory for string representation of hashtable // assuming each variable will require 20 characters char* str = (char*) malloc(20 * numOfVariable * sizeof(char)); // empty the string str[0] = '\0'; // loop through the hashtable and add each list to the string for (i = 0; i < HTSIZE; i++) { char* list = listToString(t->table[i]); // concatenate the "list" string to the string if (list == NULL) { strcat(str, "EMPTY LIST"); } else { strcat(str, list); } // insert a newline to separate terms strcat(str, "\n"); } return str; }
std::string removeRedundantSubstrings(const std::string &s) { // Convert the string into a list of strings and separate out the redundant entries std::list<std::string> XStringList = stringToList(s); XStringList.sort(); XStringList.unique(); return listToString(XStringList); }
ObjectNode *op_LoadBmp (ExecuteHandler execute, Context *context, Node *node){ void *res = NULL; ObjectNode *objpath = execute(context, &node->childs[0]); char *path = listToString(objpath); BITMAP bmp; if(readBitmap(&bmp, path)) return newObjectNode(NTYPE_NONE, NULL); res = (void *) mkList(&bmp); freeBitmap(&bmp); return res; }
/* Call this each loop to update the game timer */ void gameTimeUpdate() { uint32_t currTime = wzGetTicks(); if (currTime < baseTime) { // Warzone 2100, the first relativistic computer game! // Exhibit A: Time travel // force a rebase debug(LOG_WARNING, "Time travel is occurring! Clock went back in time a bit from %d to %d!\n", baseTime, currTime); baseTime = currTime; timeOffset = graphicsTime; } // Do not update the game time if gameTimeStop has been called if (stopCount == 0) { bool mayUpdate = true; // Calculate the new game time uint32_t scaledCurrTime = (currTime - baseTime)*modifier + timeOffset; if (scaledCurrTime < graphicsTime) // Make sure the clock doesn't step back at all. { debug(LOG_WARNING, "Rescaled clock went back in time a bit from %d to %d!\n", graphicsTime, scaledCurrTime); scaledCurrTime = graphicsTime; baseTime = currTime; timeOffset = graphicsTime; } if (updateWantedTime == 0 && scaledCurrTime >= gameTime) { updateWantedTime = currTime; // This is the time that we wanted to tick. } if (scaledCurrTime >= gameTime && !checkPlayerGameTime(NET_ALL_PLAYERS)) { unsigned player; // Pause time at current game time, since we are waiting GAME_GAME_TIME from other players. scaledCurrTime = gameTime; baseTime = currTime; timeOffset = gameTime; debug(LOG_SYNC, "Waiting for other players. gameTime = %u, player times are {%s}", gameTime, listToString("%u", ", ", gameQueueTime, gameQueueTime + game.maxPlayers).c_str()); mayUpdate = false; for (player = 0; player < game.maxPlayers; ++player) { if (!checkPlayerGameTime(player)) { NETsetPlayerConnectionStatus(CONNECTIONSTATUS_WAITING_FOR_PLAYER, player); break; // GAME_GAME_TIME is processed serially, so don't know if waiting for more players. } } } // Calculate the time for this frame deltaGraphicsTime = scaledCurrTime - graphicsTime; // Adjust deltas. if (scaledCurrTime >= gameTime && mayUpdate) { if (scaledCurrTime > gameTime + GAME_TICKS_PER_SEC*MAXIMUM_SPF) { // Game isn't updating fast enough... uint32_t slideBack = deltaGraphicsTime - GAME_TICKS_PER_SEC*MAXIMUM_SPF; baseTime += slideBack / modifier; // adjust the addition to base time deltaGraphicsTime -= slideBack; } deltaGameTime = GAME_TICKS_PER_UPDATE; updateLatency(); if (crcError) { debug(LOG_ERROR, "Synch error, gameTimes were: {%s}", listToString("%10u", ", ", gameQueueCheckTime, gameQueueCheckTime + game.maxPlayers).c_str()); debug(LOG_ERROR, "Synch error, CRCs were: {%s}", listToString("0x%08X", ", ", gameQueueCheckCrc, gameQueueCheckCrc + game.maxPlayers).c_str()); crcError = false; } } else { deltaGameTime = 0; } if (deltaGameTime != 0) { deltaGraphicsTime = 0; // Don't update graphics until game state is updated. } // Store the game and graphics times gameTime += deltaGameTime; graphicsTime += deltaGraphicsTime; } else { // The game is paused, so the change in time is zero. deltaGameTime = 0; deltaGraphicsTime = 0; } // Pre-calculate fraction used in timeAdjustedIncrement graphicsTimeFraction = (float)deltaGraphicsTime / (float)GAME_TICKS_PER_SEC; ASSERT(graphicsTime <= gameTime, "Trying to see the future."); }
void Query::setSelectedFields(QStringList fields) { selectedFields = listToString(fields); selectedList = fields; }
std::string JLDIO::findAndUseMacros(std::string raw) { //find declaractions std::unordered_map<std::string, std::string> macros; /// list of keys in descending order of string size std::list<std::string> orderedKeyList; std::string line = ""; std::string out = ""; int cutAfter = 0; int thisLine = 0; int maxMacroSize = 0; for (char c : raw) { if(c != '\n') line += c; else { thisLine = line.size() + 1; if(line.substr(0, 8) == "#define ") { // position after "#define " int i = 7; while (line[i] == ' ' || line[i] == '\t') i++; line = line.substr(i); i = 0; while (line[i] != ' ' && line[i] != '\t') i++; auto key = line.substr(0, i); auto iter = orderedKeyList.begin(); // sorting performance should not matter since // there shouldnt be many macros anyway while (iter != orderedKeyList.end()) { if(iter->size() < key.size()) break; iter++; } orderedKeyList.insert(iter, key); macros.insert({key, line.substr(i+1)}); } else break; cutAfter += thisLine; line = ""; } } out = raw.substr(cutAfter); // No macros found if (!orderedKeyList.size()) return out; maxMacroSize = orderedKeyList.front().size(); // std::cout<<"maxMacroSize: "<<maxMacroSize<<"\n"; // std::cout<<"orderedKeyList: "; // for (auto s : orderedKeyList) // std::cout<<s<<" "; // std::cout<<"\n"<<std::flush; // find and replace std::ostringstream oss; std::istringstream iss(out); std::list<char> workingBuffer; char charBuffer; // Fill buffer while(workingBuffer.size() < maxMacroSize) { if(!getNextChar(charBuffer, oss, iss, &workingBuffer)) { oss << std::flush; return oss.str(); } workingBuffer.push_back(charBuffer); } do { bool matchFound = false; for(auto key : orderedKeyList) { auto kvp = macros.find(key); assert(kvp != macros.end() && "orderedKeyList should only contain valid keys"); auto value = kvp->second; if(key == listToString(workingBuffer).substr(0, key.size())) { // remove key from workingBuffer for (int i=0; i<key.size(); i++) { // std::cout<<"REMOVE: '"<<workingBuffer.front()<<"'\n"; workingBuffer.pop_front(); } // insert value in to the output // std::cout<<"INSERT: '"<<value<<"'\n"; oss << '\"' << value << '\"'; // refill workingBuffer // same as the one above while(workingBuffer.size() < maxMacroSize) { if(!getNextChar(charBuffer, oss, iss, &workingBuffer)) { break; } else { workingBuffer.push_back(charBuffer); } } matchFound = true; break; } } if(!matchFound) { oss << workingBuffer.front(); // move to next char workingBuffer.pop_front(); // refill workingBuffer // because getNextChar() can empty the buffer // same as the one above while(workingBuffer.size() < maxMacroSize) { if(!getNextChar(charBuffer, oss, iss, &workingBuffer)) { break; } else { workingBuffer.push_back(charBuffer); } } if(workingBuffer.empty()) { oss<<std::flush; return oss.str(); } } } while(true); assert(0 && "Unexpected exit"); oss<<std::flush; return oss.str(); }
std::string removePseudoRedundantSubstrings(const std::string &s) { // Convert the string into a list of strings and separate out the redundant entries std::list<std::string> XStringList = stringToList(s); XStringList.sort(); XStringList.unique(); // Build a list of the strings that will be modified std::list<std::string> modifiedStringList; std::list<std::string> listOfStringsToRemove; std::list<std::string>::iterator i; // Two loops over the list of strings represents a quadratic complexity! for (i = XStringList.begin(); i != XStringList.end(); i++) { std::string i_modifiedString; // printf ("At top of loop over XStringList \n"); // Build list of the differences between strings std::list<std::string> listOfDifferences; for (std::list<std::string>::iterator j = XStringList.begin(); j != XStringList.end(); j++) { // compare *i and *j and check for pseudo-redundence // printf ("top of loop through string: compare *i and *j and check for pseudo-redundence \n"); // build information about *i std::string::const_iterator i_diffpos = find_if ( (*i).begin(), (*i).end(), isNumber ); // build information about *j std::string::const_iterator j_diffpos = find_if ( (*j).begin(), (*j).end(), isNumber ); unsigned int i_subStringLength = i_diffpos - (*i).begin(); unsigned int j_subStringLength = j_diffpos - (*j).begin(); // printf ("i_subStringLength = %d j_subStringLength = %d \n",i_subStringLength,j_subStringLength); // Must be the same length string AND // the same length substring occuring before the first number AND // there must have been a number in the string if ( ((*i).size() == (*j).size()) && (i_subStringLength == j_subStringLength) && (i_diffpos != (*i).end()) ) { // printf ("substrings could be the same ... \n"); i_modifiedString = *i; i_modifiedString[i_subStringLength] = '$'; std::string j_modifiedString = *j; j_modifiedString[j_subStringLength] = '$'; // After modifying the strings (uniformly) see if we have a match if ( i_modifiedString == j_modifiedString ) { // (*i) and (*j) match upto the value of the number // record this as a modified string // modifiedStringList.push_back(i_modifiedString); // Remove these strings (after we finish these nested loops) listOfStringsToRemove.push_back(*i); // Build a string from the number that differentiates the two strings std::string i_numberString(1, *i_diffpos); std::string j_numberString(1, *j_diffpos); // Save the differences between the pseudo matching strings listOfDifferences.push_back(i_numberString); listOfDifferences.push_back(j_numberString); } } } // printf ("listOfDifferences.size() = %" PRIuPTR " \n",listOfDifferences.size()); // If there are any elements then we can proceed if (!listOfDifferences.empty()) { listOfDifferences.sort(); listOfDifferences.unique(); std::string maxvalue = listOfDifferences.back(); ROSE_ASSERT (!maxvalue.empty()); // char* diffpos = find_if ( modifiedString.c_str(), modifiedString.c_str()+modifiedString.length(), isMarker ); std::string::iterator diffpos = find_if (i_modifiedString.begin(), i_modifiedString.end(), isMarker ); *diffpos = maxvalue[0]; // modifiedString = copyEdit(modifiedString,string("$Y"),maxvalue); modifiedStringList.push_back(i_modifiedString); } } // Remove strings we identified for removal listOfStringsToRemove.sort(); listOfStringsToRemove.unique(); for (i = listOfStringsToRemove.begin(); i != listOfStringsToRemove.end(); i++) { XStringList.remove(*i); } // Add the strings the we saved (the resort) XStringList.insert(XStringList.end(), modifiedStringList.begin(), modifiedStringList.end()); XStringList.remove(std::string("\n")); XStringList.sort(); XStringList.unique(); return listToString(XStringList); }
QString TAEval::serveRequest(QString request, QString data) { //Then find the request here and delegate the data to the SQL to query the required info. if(request.compare("loginRequest") == 0){ qDebug() << "Login Request being processed" << endl; QString l = accessControl.logIn(data); if(l.contains("Instructor")) { return QString("Instructor"); } if(l.contains("TA")) { return QString("TA"); } if(l.contains("loggedin")) { return QString("loggedin"); } else return QString("false"); } else if (request.compare("semesterRequest") == 0) { qDebug() << "Semester Request being processed" << endl; StringList *semesters; if(getSemesters(data, semesters)) { QString result = listToString(*semesters); delete semesters; return result.isEmpty() ? "false" : result; } } else if (request.compare("coursesRequest") == 0) { qDebug() << "Courses Request being processed" << endl; QStringList info = data.split("|"); qDebug() << info.at(0) + " " + info.at(1) << endl; CourseList* c; if(getCourses(info.at(0), c, info.at(0), info.at(1))) { QString stringOfCourses = Course::listToString(*c); qDebug() << stringOfCourses << endl; delete c; return (stringOfCourses.isEmpty()) ? "false" : stringOfCourses; } } else if (request.compare("tasRequest") == 0) { qDebug() << "TAs Request being processed" << endl; QStringList info = data.split("|"); qDebug() << "Inst here is: " + info.at(0) + " and " + info.at(1) << endl; TAList* t; if(getTAs(info.at(0), info.at(1), t)) { QString stringOfTAs = TA::listToString(*t);delete t; qDebug() << stringOfTAs << endl; return (stringOfTAs.isEmpty()) ? "false" : stringOfTAs; } } else if (request.compare("taskRequest") == 0) { qDebug() << "Task Request being processed" << endl; QStringList info = data.split("|"); qDebug() << "Inst here is: " + info.at(0) + " and " + info.at(1) << " and " << info.at(2) << endl; TaskList* taskList; if(getTasks(info.at(0), info.at(1), info.at(2), taskList)) { QString stringOfTask = Task::listToString(*taskList); delete taskList; qDebug() << stringOfTask << endl; return (stringOfTask.isEmpty()) ? "false" : stringOfTask; } else return "false"; } else if (request.compare("taskCreateRequest") == 0) { qDebug() << "Create Task Request being processed" << endl; QStringList info = data.split("|"); qDebug() << "Inst here is: " + info.at(0) + " and " + info.at(1) << " and " << info.at(2) + " and " + info.at(3) << " and " << info.at(4) << + " and " + info.at(5) << endl; QStringList begDateList = info.at(4).split("-"); QStringList dueDateList = info.at(5).split("-"); QDate begDate(begDateList.at(0).toInt(), begDateList.at(1).toInt(), begDateList.at(2).toInt()); QDate dueDate(dueDateList.at(0).toInt(), dueDateList.at(1).toInt(), dueDateList.at(2).toInt()); return createTask(info.at(0), info.at(1), info.at(2), info.at(3), begDate, dueDate) ? "true" : "false"; } else if (request.compare("taskEditRequest") == 0) { qDebug() << "Edit Task Request being processed" << endl; QStringList info = data.split("|"); qDebug() << "Inst here is: " + info.at(0) + " and " + info.at(1) + " and " + info.at(2) + " and " + info.at(3) + "and " + info.at(4) << endl; QStringList begDateList = info.at(2).split("-"); QStringList dueDateList = info.at(3).split("-"); QDate begDate(begDateList.at(0).toInt(), begDateList.at(1).toInt(), begDateList.at(2).toInt()); QDate dueDate(dueDateList.at(0).toInt(), dueDateList.at(1).toInt(), dueDateList.at(2).toInt()); return editTask(info.at(0), info.at(1), begDate, dueDate, QString(info.at(4))) ? "true" : "false"; } else if (request.compare("taskDeleteRequest") == 0){ qDebug() << "DELETE Task Request being processed" << endl; QStringList info = data.split("|"); qDebug() << "Inst here is: " + info.at(0) + " and " + info.at(1) << endl; return deleteTask(info.at(0), QString(info.at(1))) ? "true" : "false"; } else if (request.compare("editEvalRequest") == 0){ qDebug() << "Edit Evail Request being processed" << endl; QStringList info = data.split("|"); return enterEvaluation(info.at(0), info.at(1).toInt(), info.at(2), info.at(3).toInt()) ? "true" : "false"; } else if (request.compare("logOutRequest") == 0){ qDebug() << "LogOut Request being processed" << endl; QStringList info = data.split("|"); qDebug() << "Inst here is: " + info.at(0) << endl; return accessControl.logOut(info.at(0)) ? "true" : "false"; } qDebug() << "Request Failed" << endl; return "false"; }